What is SQL?
SQL (Structured Query Language) is a standardized programming language designed for managing and manipulating relational databases. It is used to query, insert, update, and delete data, as well as to create and modify database structures.
Quick Facts
| Full Name | Structured Query Language |
|---|---|
| Created | 1974 by IBM (Donald Chamberlin and Raymond Boyce) |
| Specification | Official Specification |
How SQL Works
SQL was developed at IBM in the early 1970s and became an ANSI standard in 1986. It provides a declarative approach to database operations, where users specify what data they want rather than how to retrieve it. SQL consists of several sub-languages: DDL (Data Definition Language) for schema, DML (Data Manipulation Language) for data, DCL (Data Control Language) for permissions, and TCL (Transaction Control Language) for transactions. While the core syntax is standardized, different database systems (MySQL, PostgreSQL, SQL Server, Oracle) have their own extensions and variations.
Key Characteristics
- Declarative language - specify what, not how
- ANSI/ISO standardized with vendor extensions
- Supports CRUD operations (Create, Read, Update, Delete)
- Includes DDL, DML, DCL, and TCL sub-languages
- Relational model based on set theory
- Supports transactions with ACID properties
Common Use Cases
- Database querying and reporting
- Data manipulation and transformation
- Database schema design and management
- Backend application data access
- Data analysis and business intelligence
Example
-- DDL: Create table
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
email VARCHAR(255) UNIQUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- DML: Insert data
INSERT INTO users (name, email) VALUES ('John', 'john@example.com');
-- DML: Query data
SELECT name, email FROM users WHERE id = 1;
-- DML: Update data
UPDATE users SET name = 'John Doe' WHERE id = 1;
-- DML: Delete data
DELETE FROM users WHERE id = 1;
-- Join example
SELECT u.name, o.total
FROM users u
JOIN orders o ON u.id = o.user_id
WHERE o.created_at > '2024-01-01';