SQL Keywords Reference
Every SQL keyword used in this course, in alphabetical order, with what it does and where it's taught. It covers every keyword in the common online SQL references, plus the modern ones they leave out, such as FILTER, LATERAL, MERGE and RETURNING. Use the browser's find (Ctrl+F or Cmd+F) to jump to a keyword.
| Keyword | What it does | Lesson |
|---|---|---|
ADD | Add a column or constraint to a table | ALTER TABLE and DROP TABLE |
ADD CONSTRAINT | Add a named constraint to an existing table | Constraints |
ALL | True if the comparison holds for every value of a subquery | ANY and ALL |
ALTER | Change an existing object | ALTER TABLE and DROP TABLE |
ALTER COLUMN | Change a column's type, default or nullability | ALTER TABLE and DROP TABLE |
ALTER TABLE | Add, drop or change columns and constraints | ALTER TABLE and DROP TABLE |
AND | Both conditions must be true | AND, OR and NOT |
ANY | True if the comparison holds for at least one value of a subquery | ANY and ALL |
AS | Give a column or table an alias | Aliases |
ASC | Sort ascending (the default) | ORDER BY |
BACKUP DATABASE | SQL Server: back up a database (PostgreSQL uses pg_dump) | Backup and Restore |
BEGIN | Start a transaction | Transactions |
BETWEEN | A value within a range, both ends included | IN and BETWEEN |
CASE | Choose a value by conditions | CASE Expressions |
CHECK | A rule each row must satisfy | Constraints |
COLUMN | Used with ADD, ALTER, DROP and RENAME | ALTER TABLE and DROP TABLE |
COMMIT | Make a transaction's changes permanent | Transactions |
CONSTRAINT | Name a rule on a table | Constraints |
CREATE | Create a database object | CREATE TABLE |
CREATE DATABASE | Create a new database | Creating a Database |
CREATE INDEX | Create an index | Indexes |
CREATE OR REPLACE VIEW | Create a view, or replace it if it exists | Views |
CREATE PROCEDURE | Create a stored procedure | Stored Procedures |
CREATE TABLE | Create a table | CREATE TABLE |
CREATE UNIQUE INDEX | Create an index that forbids duplicate values | Indexes |
CREATE VIEW | Create a saved query | Views |
CROSS JOIN | Pair every row with every row | CROSS JOIN |
DATABASE | Used with CREATE and DROP | Creating a Database |
DEFAULT | A column's value when none is given | Constraints |
DELETE | Remove rows | DELETE |
DESC | Sort descending | ORDER BY |
DISTINCT | Remove duplicate rows | SELECT DISTINCT |
DROP | Remove an object | ALTER TABLE and DROP TABLE |
DROP COLUMN | Remove a column | ALTER TABLE and DROP TABLE |
DROP CONSTRAINT | Remove a constraint | Constraints |
DROP DATABASE | Delete a database and everything in it | Creating a Database |
DROP DEFAULT | Remove a column default | Constraints |
DROP INDEX | Remove an index | Indexes |
DROP TABLE | Delete a table and its data | ALTER TABLE and DROP TABLE |
DROP VIEW | Remove a view | Views |
EXCEPT | Rows in the first query but not the second (Oracle: MINUS) | INTERSECT and EXCEPT |
EXEC / CALL | Run a stored procedure (SQL Server EXEC; PostgreSQL and MySQL CALL) | Stored Procedures |
EXISTS | True if a subquery returns any row | EXISTS |
EXPLAIN | Show a query's plan | Reading EXPLAIN |
FETCH FIRST | Standard way to limit rows | Limiting Rows: LIMIT, TOP and FETCH |
FILTER | Limit an aggregate to matching rows | Pivoting Data |
FOREIGN KEY | A column that must match a key in another table | FOREIGN KEY |
FROM | The tables to read | SELECT |
FULL OUTER JOIN | Keep rows from both tables, matched or not | FULL OUTER JOIN |
GRANT | Give privileges | Users, Roles and Privileges |
GROUP BY | Group rows for aggregates | GROUP BY |
HAVING | Filter groups | HAVING |
IN | A value in a list or subquery | IN and BETWEEN |
INDEX | A structure that speeds up lookups | Indexes |
INNER JOIN | Keep only matching rows | INNER JOIN |
INSERT INTO | Add rows | INSERT INTO |
INSERT INTO SELECT | Copy rows from a query into a table | INSERT INTO SELECT and Loading Files |
INTERSECT | Rows in both queries | INTERSECT and EXCEPT |
IS NOT NULL | Test for a present value | NULL Values |
IS NULL | Test for a missing value | NULL Values |
JOIN | Combine rows from tables | How Joins Work |
LATERAL | A subquery that can use columns from earlier tables | LATERAL Joins |
LEFT JOIN | Keep every row from the left table | LEFT JOIN |
LIKE | Pattern match with % and _ | LIKE and Wildcards |
LIMIT | Limit rows (PostgreSQL, MySQL, SQLite) | Limiting Rows: LIMIT, TOP and FETCH |
MERGE | Insert, update or delete rows by matching a source | Upsert and MERGE |
NOT | Negate a condition | AND, OR and NOT |
NOT NULL | A value is required | Constraints |
NULL | A missing or unknown value | NULL Values |
OFFSET | Skip rows | Pagination |
ON | A join condition | How Joins Work |
ON CONFLICT | PostgreSQL and SQLite upsert | Upsert and MERGE |
OR | At least one condition true | AND, OR and NOT |
ORDER BY | Sort the result | ORDER BY |
OUTER JOIN | LEFT, RIGHT or FULL join | FULL OUTER JOIN |
OVER | Define a window for a window function | Window Functions |
PARTITION BY | Split a window into groups | Window Functions |
PRIMARY KEY | The column(s) that identify each row | UNIQUE and PRIMARY KEY |
PROCEDURE | A stored routine run with CALL or EXEC | Stored Procedures |
RECURSIVE | A CTE that refers to itself | Recursive CTEs |
REFERENCES | Declare a foreign key | FOREIGN KEY |
RETURNING | Return columns of changed rows (PostgreSQL, SQLite) | INSERT INTO |
REVOKE | Take privileges away | Users, Roles and Privileges |
RIGHT JOIN | Keep every row from the right table | RIGHT JOIN |
ROLLBACK | Undo a transaction | Transactions |
ROLLUP | Subtotals and a grand total | ROLLUP, CUBE and GROUPING SETS |
ROWNUM | Oracle's older way to limit rows | Limiting Rows: LIMIT, TOP and FETCH |
SAVEPOINT | A point inside a transaction to roll back to | Transactions |
SELECT | Read data | SELECT |
SELECT DISTINCT | Read data without duplicate rows | SELECT DISTINCT |
SELECT INTO | Create a table from a query (SQL Server, PostgreSQL) | Copying a Table |
SELECT TOP | Limit rows (SQL Server, MS Access) | Limiting Rows: LIMIT, TOP and FETCH |
SET | Assign values in UPDATE; change a setting | UPDATE |
TABLE | Used with CREATE, ALTER, DROP and TRUNCATE | CREATE TABLE |
TOP | Limit rows (SQL Server, MS Access) | Limiting Rows: LIMIT, TOP and FETCH |
TRUNCATE TABLE | Remove all rows quickly | DELETE |
UNION | Rows from both queries, duplicates removed | UNION and UNION ALL |
UNION ALL | Rows from both queries, duplicates kept | UNION and UNION ALL |
UNIQUE | No two rows may share the value | UNIQUE and PRIMARY KEY |
UPDATE | Change rows | UPDATE |
VALUES | The values to insert | INSERT INTO |
VIEW | A saved query | Views |
WHERE | Filter rows | WHERE |
WITH | A common table expression | Common Table Expressions |
For the same tasks written for each database, see the SQL Syntax by Database.
Was this tutorial helpful?