SQL Keywords Reference
This reference provides a comprehensive list of common SQL keywords and their functionalities. Note that the specific syntax and availability of certain keywords might vary slightly depending on the database system (e.g., MySQL, PostgreSQL, SQL Server, Oracle) you are using. Always refer to your database's documentation for the most accurate and up-to-date information.
Data Definition Language (DDL) Keywords
Keyword | Description |
---|---|
ADD |
Adds a column to an existing table. |
ADD CONSTRAINT |
Adds a constraint to a table. |
ALTER |
Modifies the structure of a table (adding, deleting, or changing columns). |
ALTER COLUMN |
Changes the data type of a column. |
ALTER TABLE |
Modifies the structure of a table. |
CHECK |
Defines a constraint to limit values in a column. |
COLUMN |
Used within ALTER TABLE to specify a column. |
CONSTRAINT |
Used to define or drop constraints. |
CREATE |
Creates database objects (databases, tables, indexes, views, etc.). |
CREATE DATABASE |
Creates a new database. |
CREATE INDEX |
Creates an index on a table (allows duplicates). |
CREATE OR REPLACE VIEW |
Creates or updates a view. |
CREATE PROCEDURE |
Creates a stored procedure. |
CREATE TABLE |
Creates a new table. |
CREATE UNIQUE INDEX |
Creates a unique index on a table (no duplicates). |
CREATE VIEW |
Creates a view. |
DATABASE |
Used in CREATE or DROP statements for databases. |
DEFAULT |
Specifies a default value for a column. |
DROP |
Deletes database objects (databases, tables, indexes, views, etc.). |
DROP COLUMN |
Deletes a column from a table. |
DROP CONSTRAINT |
Deletes a constraint from a table. |
DROP DATABASE |
Deletes a database. |
DROP DEFAULT |
Removes a default value constraint from a column. |
DROP INDEX |
Deletes an index from a table. |
DROP TABLE |
Deletes a table. |
DROP VIEW |
Deletes a view. |
FOREIGN KEY |
Defines a foreign key constraint. |
INDEX |
Used in CREATE or DROP statements for indexes. |
PRIMARY KEY |
Defines a primary key constraint. |
PROCEDURE |
Used in CREATE or DROP statements for stored procedures. |
TABLE |
Used in CREATE , ALTER , or DROP statements for tables. |
UNIQUE |
Defines a uniqueness constraint. |
VIEW |
Used in CREATE or DROP statements for views. |
Data Manipulation Language (DML) Keywords
Keyword | Description |
---|---|
DELETE |
Deletes rows from a table. |
INSERT INTO |
Inserts new rows into a table. |
INSERT INTO SELECT |
Inserts data from one table into another. |
SELECT |
Retrieves data from a database. |
SELECT DISTINCT |
Retrieves unique rows only. |
SELECT INTO |
Creates a new table and populates it with data from a query. |
SELECT TOP |
Retrieves a limited number of rows. |
SET |
Specifies values to update in an UPDATE statement. |
TRUNCATE TABLE |
Deletes all data from a table but preserves its structure. |
UPDATE |
Modifies existing rows in a table. |
VALUES |
Specifies values for inserting new rows. |
Data Control Language (DCL) Keywords
Keyword | Description |
---|---|
GRANT |
Grants database permissions. |
REVOKE |
Revokes database permissions. |
Other Important Keywords
Keyword | Description |
---|---|
ALL |
Used with subqueries; checks if all values meet a condition. |
AND |
A logical operator; combines conditions; both must be true. |
ANY |
Used with subqueries; checks if any value meets a condition. |
AS |
Creates an alias for a column or table. |
ASC |
Sorts in ascending order. |
BETWEEN |
Selects values within a range. |
CASE |
Performs conditional logic. |
DESC |
Sorts in descending order. |
DISTINCT |
Returns only unique rows. |
DROP |
Used to delete database objects. |
EXISTS |
Checks for the existence of rows. |
FROM |
Specifies the table to select data from. |
FULL OUTER JOIN |
Combines rows from two tables, including all rows from both. |
GROUP BY |
Groups rows with the same values into summary rows. |
HAVING |
Filters grouped rows based on aggregate functions. |
IN |
Specifies multiple values in a WHERE clause. |
INNER JOIN |
Returns only rows with matches in both joined tables. |
IS NULL |
Checks for null values. |
IS NOT NULL |
Checks for non-null values. |
JOIN |
A general term for combining data from multiple tables. |
LEFT JOIN |
Returns all rows from the left table and matched rows from the right. |
LIKE |
Used for pattern matching in strings. |
LIMIT |
Limits the number of rows returned. |
NOT |
Negates a condition. |
NOT NULL |
Enforces that a column cannot contain NULL values. |
OR |
A logical operator; combines conditions; at least one must be true. |
ORDER BY |
Sorts the result set. |
OUTER JOIN |
A general term for joins that include all rows from at least one table. |
RIGHT JOIN |
Returns all rows from the right table and matched rows from the left. |
ROWNUM |
Used in Oracle to limit the number of rows returned. |
UNION |
Combines result sets, removing duplicates. |
UNION ALL |
Combines result sets, including duplicates. |
WHERE |
Filters a result set based on specified conditions. |