What is SQL?
SQL is the declarative language used to define, query, change, and control data in relational databases.
Lesson content
What is SQL? SQL is the declarative language used to define, query, change, and control data in relational databases. Example SELECT name, price FROM products WHERE price < 100; Key point Use the smallest correct statement, test it with representative data, and verify constraints and performance before production use. Real-life example A development team applies What is SQL? to a small commerce database, verifies the result, and then decides whether the same approach is safe for production data. Advanced example BEGIN; -- Preview the exact target set first. SELECT id FROM orders WHERE status = 'pending'; -- Apply the What is SQL? operation, verify affected rows, then commit. COMMIT; Expected result The schema or operation satisfies the stated rule, rejects invalid data, and can be verified with a repeatable query. Production check Test with empty, duplicate, null, and boundary values. Use a transaction for related writes. Inspect the execution plan before adding an index. Use parameterized queries for application input. Continue with the PicoStore database This lesson reuses picostore . Relevant tables: customers, products, orders, order_items . Keep the starter rows from the Introduction lesson so results remain comparable. Another practical example SELECT o.order_id, c.name AS customer, o.status, o.total FROM orders o JOIN customers c ON c.customer_id = o.customer_id WHERE o.total >= 1000 ORDER BY o.ordered_at DESC; Check the result Run the verification query, compare the returned rows with the starter data, and explain why every included or excluded row is correct. SQL reference catalog: What is SQL? This catalog covers the practical public SQL surface. Check the exact server-version documentation before using a vendor-specific item. SQL command families DQL — SELECT queries data DDL — CREATE, ALTER, DROP, TRUNCATE, RENAME define structures DML — INSERT, UPDATE, DELETE, MERGE change rows DCL — GRANT and REVOKE control access TCL — BEGIN, COMMIT, ROLLBACK, SAVEPOINT control transactions Core query clauses in logical order WITH — defines common table expressions SELECT — chooses expressions and columns FROM — chooses source tables JOIN ... ON — combines related sources WHERE — filters rows before grouping GROUP BY — forms groups HAVING — filters groups WINDOW — names reusable window definitions ORDER BY — sorts the result LIMIT / OFFSET or FETCH — restricts returned rows Easy example Start with a small customer table and retrieve active customers in a predictable order. SELECT customer_id, name, email FROM customers WHERE status = 'active' ORDER BY name; How to verify the easy example Run it with representative input. Confirm the expected output. Try one missing, invalid, or boundary value. Advanced example Use a CTE and a window function to rank customer revenue while keeping the query readable and testable. WITH customer_revenue AS ( SELECT customer_id, SUM(total_amount) AS revenue FROM orders WHERE order_status = 'completed' GROUP BY customer_id ) SELECT customer_id, revenue, DENSE_RANK() OVER (ORDER BY revenue DESC) AS revenue_rank FROM customer_revenue ORDER BY revenue_rank, customer_id; Advanced review Explain the tradeoffs and assumptions. Test failure, scale, security, and recovery behavior. Capture evidence from tests, execution plans, logs, or review output. Additional practical guidance What is SQL?: MySQL and PostgreSQL Use standard SQL first, then document any MySQL or PostgreSQL-specific syntax. Verify the statement with small sample data, an edge case, and the expected result before using it in production. Required verification Run the simple case. Test a NULL, duplicate, empty, or boundary case where relevant. Confirm the affected rows or query result. Use EXPLAIN for performance-sensitive queries.