Home Think Topics Structured Query Language What is structured query language (SQL)?
Explore IBM Db2 database Subscribe to AI updates
Illustration showing banks of tall servers lit in blue

Published: May 31, 2024
Contributors: Tim Mucci

What is structured query language?

Structured query language (SQL) is a standardized, domain-specific programming language that excels at handling data relationships. It is used extensively for storing, manipulating and retrieving data in systems such as MySQL, SQL Server and Oracle.

When data needs to be retrieved from a database, SQL is used to make the request. SQL is used by database administrators, developers and data analysts for tasks such as data definition, access control, data sharing, writing data integration scripts and running analytical queries.

Key functions of SQL:

  • Data definition: Define the structure and organization of the stored data and the relationships among stored data items.
  • Data retrieval: Retrieve specific data items or a range of items easily.
  • Data manipulation: Add new data, remove or modify existing data.
  • Access control: Restrict a user's ability to retrieve, add and modify data, protecting stored data against unauthorized access.
  • Data sharing: Used to coordinate data sharing by concurrent users, helping to ensure that changes made by one user do not inadvertently delete or overwrite changes made by other users. 

SQL is a versatile tool in the modern tech stack, used for managing data storage and processing solutions for both front-end and back-end applications. It is employed in various domains, such as handling e-commerce inventories and processing online transactions to organizing vast amounts of healthcare data for analysis. 

Renowned for its data manipulation capabilities, rapid query processing and strong security features, SQL offers commonality and compatibility across different systems, scalability to handle growing data needs and benefits from being open source with robust community support.

It differs from other computer languages because SQL describes what the user wants the computer to do rather than how it should do it. Specifically, SQL is a declarative or descriptive language rather than a procedural one. For example, when users write a SQL query to fetch data, they don't need to outline the steps the database should take to gather that data; they describe what the result should look like.

In data science and machine learning, SQL is used to create databases that store large data sets needed for analysis. Tools such as Microsoft SQL Server and MongoDB are two choices for handling different types of databases, from relational to NoSQL.

KuppingerCole on Database and Big Data Security

KuppingerCole's Leadership Compass report offers an insightful guide to database and big data security solutions, helping clients find the best products through a comprehensive analysis.

History of SQL

Introduced in the 1970s and developed by IBM scientists Donald Chamberlin and Raymond Boyce, SQL originated from the concept of relational models and was initially called structured English query language (SEQUEL) before being shortened to SQL. It became commercially available in 1979 and has since become the global standard for relational database management systems (RDBMS).

SQL was standardized by the American National Standards Institute (ANSI) in 1986 and the International Organization for Standardization (ISO) in 1987. Despite being a standard, SQL has various dialects, such as T-SQL for MS SQL Server and PL/SQL for Oracle, which cater to specific system needs while maintaining compliance with the core ANSI standard commands like SELECT, UPDATE, DELETE, INSERT and WHERE.

Why is SQL important?

SQL is essential in the data industry and is used by analysts, scientists and database developers. Its universality makes it a valuable skill in understanding other programming languages like Python and Java. Since its development in the 1970s, SQL has become the backbone of modern database systems.

SQL is used for storing, retrieving, managing and manipulating data within database management systems (DBMS). It supports transaction processing and analytics applications and integrates seamlessly with various programming languages, such as Java, allowing developers to build high-performance data processing applications for different business intelligence needs.

Basic operations include these SQL commands:

  • SELECT * FROM customers ; to retrieve all records from the 'customers' table.
  • INSERT INTO customers (name, email) VALUES ('John Doe', 'john@example.com') ; to add a new customer or UPDATE customers
  • SET email = 'newemail@example.com' WHERE name = 'John Doe' ; to update an email address.

SQL operations are conducted through commands written as statements. These statements are aggregated into programs that facilitate the addition, modification or retrieval of data from a database, which consists of rows and columns in tables. Each row holds a record and each column represents a related category of data. In addition to tables, other database objects include views (logical data representations), indexes (to speed up lookups) and reports (data subsets based on criteria).

SQL databases are designed to help ensure reliable transaction processing by adhering to ACID properties: Atomicity (all-or-nothing), Consistency (protects database integrity), Isolation (transactions do not interfere with each other) and Durability (helps ensure that changes from successful transactions persist even if the system fails).

Relational databases organize data by using these rows and columns to structure information, such as customer information and purchase details. These tables are linked through relationships, often by using a specific identifier or primary key to facilitate efficient data retrieval and management.

While standard SQL is widely used, specific dialects like T-SQL by Microsoft SQL Server and PL/SQL by Oracle offer extensions to enhance procedural programming capabilities. SQL is known for its create, read, update and delete functions and its nonprocedural nature makes it accessible even to those with limited programming experience, often making it an easy language for beginners. It adheres to ANSI standards and is available in free SQL software like MySQL, PostgreSQL and Microsoft SQL.

How does SQL work?

SQL allows for the organization of data in a tabular format with rows and columns, facilitating the establishment of relationships between different tables. For instance, a customer service database might use separate tables for customer information, purchases, product codes and contacts, linked by keys like a unique customer ID.

This linkage often involves relationships, such as one-to-many or many-to-many, established using primary and foreign keys to help ensure data integrity.

Key features of SQL
Data manipulation

SQL handles operations such as data creation, reading, updating and deletion. For example, using the Join operation, SQL can link customer information with purchases based on customer ID to provide a comprehensive view.

Rapid query processing

SQL quickly processes and retrieves data, by using indexes and query optimization techniques to enhance performance.

Security features

SQL includes user authentication to protect data integrity and privacy, such as access controls and encryption.

Commonality and compatibility

SQL's adherence to standards like ANSI and ISO helps ensure widespread compatibility with various systems and platforms, including cloud environments and big data tools.


SQL can effectively manage both small and large databases, adapting to growing data needs without significant performance loss.

Open source and community support

Many SQL variants are open source and supported by a large, active community that contributes to continuous improvement and problem-solving.

Despite these strengths, other enterprise applications are vulnerable to security issues, such as weak authentication, insecure design and misconfiguration. SQL injection remains a threat, where attackers manipulate SQL queries to access or corrupt database information. Understanding these vulnerabilities and implementing robust security measures is critical for safeguarding data.

Key components of a SQL system

An SQL table, the fundamental unit of a relational database, is organized into rows and columns to efficiently store and manage data. SQL enables the creation of relationships between tables, such as linking a PRODUCT table to a COLOR table through keys and optimizing data storage and retrieval.

SQL processes involve several components:

  • Parser: Verifies the correctness of SQL statements and converts them into a format that the database can understand. This involves syntax analysis and semantic checking to ensure that the user is authorized to operate.
  • Relational engine: Also known as the query optimizer, it plans the most efficient data retrieval, writing or updating strategies by evaluating different query execution plans. This step is crucial for optimizing performance and resource use.
  • Storage engine: Runs the SQL statement and manages physical data storage. It handles the physical representation of data, including file formats and data buffering, helping to ensure efficient data access and updates on disk.
Common SQL commands

SQL supports various statements for data operations. Here are the most common, with examples:

SELECT: Retrieves data from one or more tables.

SELECT name, email FROM customers WHERE city = 'New York' ;

This statement retrieves the name and email of all customers who live in New York from the customers table.

INSERT: Adds new rows to a table.

INSERT INTO customers (name, email, city) VALUES ('Jane Doe', 'jane.doe@example.com', 'Los Angeles') ;

This statement adds a new row to the customers table with the name 'Jane Doe', email 'jane.doe@example.com' and city 'Los Angeles'.

UPDATE: Modifies existing data in a table.

UPDATE customers SET email = 'new.email@example.com' WHERE name = 'John Doe' ;

This statement updates the email of the customer named 'John Doe' in the customers table to 'new.email@example.com'.

DELETE: Removes rows from a table based on a condition.

DELETE FROM customers WHERE city = 'Boston' ;

This statement deletes all rows from the customers table where the city is 'Boston'.

CREATE TABLE: Defines a new table and its structure.

CREATE TABLE products (
product_id INT PRIMARY KEY,
name VARCHAR(100),
price DECIMAL(10, 2)
) ;

This statement creates a new table called products with three columns: product_id as an integer primary key, name as a variable character string up to 100 characters and price as a decimal with ten digits and two decimal places.

ALTER TABLE: Modifies the structure of an existing table.

ALTER TABLE customers ADD COLUMN birthday DATE ;

This statement adds a new column birthday of type DATE to the existing customers table.

DROP TABLE: Deletes a table and all its data.

DROP TABLE old_customers ;

This statement deletes the old_customers table along with all its data.

JOIN: Combines rows from two or more tables based on a related column.

customers c
orders o ON c.customer_id = o.customer_id
products p ON o.product_id = p.product_id
c.city = 'New York' ;

This statement retrieves the names of customers and the names of the products they ordered. It joins the customers, orders and products tables based on the customer_id and product_id, selecting only those customers who live in New York.

SQL also includes specific languages for different tasks:
  • Data definition language (DDL): Manages database objects like tables, views and indexes.
  • Data manipulation language (DML): Manages data within databases through operations like INSERT, UPDATE and DELETE.
  • Data control language (DCL): Controls data access through commands like GRANT and REVOKE, helping to ensure appropriate levels of access.
  • Data query language (DQL): Executes data queries to retrieve information.
  • Transaction control language (TCL): Manages transaction changes to help ensure data integrity and supports rollback and commit operations.

More components of an SQL system include constraints, stored procedures, transactions, data types, indexes, views, security and permissions. Indexes speed up data retrieval by reducing the number of disk accesses needed for a query.

Views act as virtual tables based on SQL queries to simplify complex queries and improve security by restricting access to underlying data. Security and permissions manage user access, while backup and recovery mechanisms protect data against loss or corruption.

SQL compared to other database systems

MySQL is an open source RDBMS provided by Oracle, without charge for developers to use on various platforms, including cloud servers. It is popular in web applications due to its functions and adaptability. MySQL is a specific implementation that uses SQL queries and is regularly updated and improved by Oracle.

NoSQL databases emerged in the late 2000s to handle data with less structure, offering faster queries and more flexible data models compared to SQL databases. While SQL databases excel in managing relational data and helping to ensure structured, efficient data storage, NoSQL databases are known for their scalability and diverse data structures like graphs, documents or wide column stores.

Key differences include:

  • Scalability: NoSQL is horizontally scalable and manages higher traffic by adding more servers. In contrast, SQL is traditionally vertically scalable, requiring more powerful hardware to handle increased load.
  • Structure: SQL databases use a table-based structure ideal for multirow transactions and complex queries across related data, thanks to robust indexing and joining capabilities. NoSQL offers various structures, such as key-value, document, graph or wide column stores, catering to different needs and allowing for more flexibility with semistructured or unstructured data.
  • Performance characteristics: SQL databases are optimized for complex queries with strict data consistency, following the ACID principles. NoSQL databases, that use basically available, soft state, eventual consistency (BASE) principles, provide faster performance for specific types of data but with different consistency guarantees.
  • Use cases: SQL is often chosen for applications requiring complex transactions, consistent data and strict schema adherence, like financial systems or CRM databases. NoSQL is preferred for rapidly changing, large-scale or semistructured data, such as in social networks, real-time analytics or content management systems.
  • Knowledge and community: SQL has a more extensive range of resources and community support due to its longer history and commonality. The learning curve for SQL can be steeper due to the need to understand relational models and query optimization, but many tools and interfaces are available to simplify these tasks. NoSQL often requires less upfront design and can be easier to scale but might need more custom development for complex querying and data consistency.
  • Maintenance and management: SQL databases require careful schema design and can be demanding in terms of maintenance for schema changes. NoSQL databases offer easier scalability and adaptability for schema changes without extensive downtime or restructuring.
Related solutions
IBM Db2®

IBM Db2 offers robust performance, scalability and advanced analytics capabilities to help ensure efficient data management and insightful business intelligence.

Explore IBM Db2

IBM Db2® Big SQL

A hybrid SQL-on-Hadoop engine delivering advanced, security-rich data queries across enterprise big data sources, object storage and data warehouses.

Explore IBM Db2 Big SQL

IBM Cloud® Databases for PostgreSQL

Discover how IBM’s managed PostgreSQL service offers robust scalability, advanced security and high availability, along with seamless integration into IBM Cloud, to optimize your database management and analytics capabilities.

Explore IBM Cloud Databases for PostgreSQL
Related resources Gaining better access to graph and blockchain data within SQL databases

Discover how integrating graph and blockchain data within SQL databases can enhance data accessibility, streamline query processes and unlock deeper insights for AI-driven business solutions.

What is a relational database?

Gain a comprehensive understanding of relational databases, their structure, advantages and how they facilitate data management and querying for business insights.

SQL versus NoSQL databases: What’s the difference?

Understand the key differences between SQL and NoSQL databases and learn how to choose the right type of database for your specific data management needs and use cases.

Take the next step

Gain a single, cloud-native engine for database administrators, enterprise architects and developers to keep apps running, store and query anything, and simplify development. No matter the volume or complexity of transactions, protect your applications and make them highly performant and resilient anywhere.

Explore IBM Db2 database Try Db2 SaaS on IBM Cloud