SQL Introduction
Overview
Structured Query Language (SQL) is the standard language for communicating with Relational Databases (like MySQL, PostgreSQL, and Oracle). Unlike general-purpose programming languages (Python, Java) which are 'Imperative' (you write exactly how to do a task step-by-step), SQL is 'Declarative' (you describe what data you want, and the database engine figures out the fastest way to retrieve it). Mastering SQL is non-negotiable for backend engineers, data scientists, and anyone building robust applications.
Syntax
-- 1. DQL (Data Query Language): Retrieving data
SELECT first_name, email FROM users;
-- 2. DDL (Data Definition Language): Creating structure
CREATE TABLE users (id INT, name VARCHAR(50));
-- 3. DML (Data Manipulation Language): Modifying data
INSERT INTO users (id, name) VALUES (1, 'Alice');
UPDATE users SET name = 'Alicia' WHERE id = 1;
-- 4. DCL (Data Control Language): Security & Permissions
GRANT SELECT ON users TO analyst_role;Common Pitfalls
- Confusing SQL with a Database Engine. SQL is just the written language. PostgreSQL, MySQL, and SQLite are the actual software engines that read the SQL and execute it. While SQL is a standard (ANSI SQL), every engine has its own slight variations ('dialects').
- Treating SQL like a loop in Python. Beginners often try to query data row-by-row and process it in a loop. SQL is entirely built on 'Set Theory'. You should always think about manipulating entire blocks of data (Sets) simultaneously in a single query.
Interview Questions
DDL (Data Definition Language) commands like CREATE, ALTER, and DROP modify the actual structural schema of the database tables. DML (Data Manipulation Language) commands like INSERT, UPDATE, and DELETE modify the actual row data living inside those tables.
Real-World Example
How a Node.js backend executes a declarative SQL query to log in a user.
// The backend just sends the SQL string to the database engine.
// The engine parses it, optimizes it, fetches the data from disk, and returns the rows.
const username = 'johndoe';
const query = "SELECT id, password_hash FROM users WHERE username = $1";
const result = await db.execute(query, [username]);Check Your Knowledge
Test your understanding of SQL Introduction with these quick questions.