What is SQL?
SQL (Structured Query Language) is the standard language for managing and querying relational databases. It was originally developed at IBM in the 1970s by Donald Chamberlin and Raymond Boyce.
š” SQL is declarative ā you describe WHAT data you want, not HOW to retrieve it. The database engine figures out the optimal execution plan.
Why SQL Matters
| Benefit | Description |
|---|---|
| Universal | Used by every major database: MySQL, PostgreSQL, SQL Server, Oracle, SQLite |
| Powerful | Can handle billions of rows efficiently |
| Declarative | Focus on results, not implementation details |
| Standardized | ANSI/ISO standard since 1986 |
| Career Essential | Required skill for data analysts, engineers, scientists |
How Databases Work
A relational database organizes data into tables (also called relations). Each table has:
- Columns (attributes) ā what fields exist
- Rows (records) ā individual data entries
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā customers ā
āāāāāā¬āāāāāāāāāāā¬āāāāāāāāāā¬āāāāāāāāāāāāāāāā¤
ā id ā name ā city ā email ā
āāāāāā¼āāāāāāāāāāā¼āāāāāāāāāā¼āāāāāāāāāāāāāāāā¤
ā 1 ā Alice ā NYC ā a@mail.com ā
ā 2 ā Bob ā LA ā b@mail.com ā
ā 3 ā Charlie ā Chicago ā c@mail.com ā
āāāāāā“āāāāāāāāāāā“āāāāāāāāāā“āāāāāāāāāāāāāāāā
Types of SQL Commands
| Category | Full Name | Purpose | Example Commands |
|---|---|---|---|
| DDL | Data Definition Language | Define database structure | CREATE, ALTER, DROP, TRUNCATE |
| DML | Data Manipulation Language | Query and modify data | SELECT, INSERT, UPDATE, DELETE |
| DCL | Data Control Language | Control access permissions | GRANT, REVOKE |
| TCL | Transaction Control Language | Manage transactions | COMMIT, ROLLBACK, SAVEPOINT |
Your First Query
-- Select all columns from the customers table
SELECT * FROM customers;
-- Select specific columns
SELECT name, email FROM customers;
-- Filter results
SELECT name, city
FROM customers
WHERE city = 'NYC';
Result:
| name | city |
|---|---|
| Alice | NYC |
SQL vs NoSQL
| Feature | SQL (Relational) | NoSQL (Non-relational) |
|---|---|---|
| Structure | Fixed schema | Flexible schema |
| Data Model | Tables with rows/columns | Documents, key-value, graphs |
| Relationships | Strong (JOINs) | Weak or none |
| ACID Compliance | Yes | Often eventual consistency |
| Best For | Structured data, complex queries | Unstructured data, scaling |
ā ļø SQL databases are not "old technology." They remain the backbone of most enterprise systems and are continuously evolving with new features.
Real-World Applications
- E-commerce: Product catalogs, orders, customer management
- Finance: Transaction processing, fraud detection, reporting
- Healthcare: Patient records, medical billing, research data
- Social Media: User profiles, posts, connections
- Analytics: Business intelligence, dashboards, forecasting
āļø Exercise: Write a SQL query to select all columns from a table called 'products'.
See Solution
SELECT * FROM products;
ā Key Takeaways
- SQL is the universal language for relational databases
- SQL is declarative ā you describe what you want, not how to get it
- DDL defines structure, DML manipulates data, DCL controls access, TCL manages transactions
- SQL databases use tables with columns (attributes) and rows (records)
- SQL remains the most widely-used data language in the world