Article
Databases Best Practices Free Guides

Free Handbook - What you need to know about relational database management systems

Written by Gonçalo Calvinho
Feb 04, 2022 · 15 min. read

What is SQL?

 

Standard computer  language for Relational Database Systems. It’s used  to store, manipulate and retrieve data in a relational database.

 

It allows users to access and manipulate data, create or destroy database objects and set user permissions.

 

SQL Commands

 

The standard SQL commands used to interact with the database are classified into 3 distinct categories (DDL, DML and DCL)

 
  • DDL – Data Definition Language
 
CREATECreates a new database object (table, view, etc)
ALTERModifies an existing database object
DROPDeletes objects in the database
 
  • DML – Data Manipulation Language
 
SELECTRetrieves records from one or more tables
INSERTCreates a record
UPDATEModifies records
DELETEDeletes records
 
  • DCL – Data Control Language
 
GRANTAssings privileges to users
REVOKERemoves granted privileges
 

Constraints

 

Constraints are the rules enforced on data columns on a table. These are used to limit the type of data that can be inserted into a column, ensuring the accuracy and reliability of the data in the database.

 

Some of the most commonly used constraints in SQL are:

 
  • NOT NULL – Ensures that a column cannot have a NULL value
  • UNIQUE – Ensures that all the values in a column are different
  • PRIMARY KEY – Refers to a primary key in another table. Links both table’s data and prevents errors.
  • FOREIGN KEY – Uniquely identifies a row in another table
  • CHECK – Ensures that all values in a column satisfy certain criteria
  • INDEX – Used to create and retrieve data from the database very quickly
 

RDBMS

 

RDBMS stands for Relational Database Management System, and is the basis for SQL. It’s a database management system that is based on the relational model (all the data is related to each other ).

 

The data in a RDBMS is stored in database objects called tables. A table is basically a collection of related data, consisting of columns and rows.

 

A column is a field in a table designed to maintain specific information about every record in the table.

 

A row  is an individual record of data in a table. It is a collection of attributes.

 

Designing a database: Best Practices

 
  1. Consider every viewpoint
    1. Don’t start building a database without input from the project owner and stakeholders.
    2. Get consensus on precise expectations/functionality
  2. Choose a database type
    1. Usually as easy as deciding between SQL and NoSQL
    2. Depending on the project there are types of databases more appropriate, e.g., Oracle for large organizations with structured data, SQL Server for error handling or XML/JSON integrations and NoSQL for machine learning and IoT applications
  3. Normalize data
    1. Data normalization is critical to achieve minimum redundancy and data consistency
    2. When a database abides by the first three normal forms we can say it’s normalized
  4. Transparency
    1. Design with the end users in mind
    2. Use consistent naming conventions, as to make things easy for those who may need to modify the database in the future
  5. Define constraints
    1. This is important to maintain data integrity and enforce business rules
    2. This way the database will prevent bad data from getting in
  6. Document everything
    1. Documentation is essential, although sometimes annoying, promotes a clean development and makes maintenance easy
    2. Document the design, implementation and every database object for future users
  7. Keep privacy primary
    1. In the era of GDPR privacy concerns are increasingly important
    2. Encrypt passwords and be careful when assigning administrator permissions
    3. Vulnerabilities impact data integrity, which impacts everything else
  8. Optimize for speed
    1. Create indexes for queries that are used regularly
    2. Use an analysis tool to check if an index or clustered index is necessary
  9. Avoid dynamic SQL
    1. Always avoid dynamic queries, as this type of development can lead to SQL injection attacks.
 

If you enjoyed this text, continue to explore our blog and check out other technical articles and guides.

Get in touch

Let's talk about your next move.

Whether you're choosing a platform, rethinking your architecture, or exploring AI — we're happy to share what we've learned from 10 years of building digital commerce.