Data Definition Language (DDL) ------------------------------ | Command | Description | | --- | --- | | `CREATE DATABASE ` | Create a new database | | `DROP DATABASE ` | Delete a database | | `CREATE TABLE ( , )` | Create a new table | | `DROP TABLE
` | Delete a table | | `ALTER TABLE
ADD COLUMN ` | Add a new column to a table | | `ALTER TABLE
DROP COLUMN ` | Remove a column from a table | | `ALTER TABLE
RENAME COLUMN TO ` | Rename a column in a table | | `ALTER TABLE
RENAME TO ` | Rename a table | | `TRUNCATE TABLE
` | Remove all rows from a table | | `CREATE INDEX INDEXNAME ON
()` | Create an index on a table | | `DROP INDEX INDEXNAME` | Remove an index from a table | Data Manipulation Language (DML) -------------------------------- | Command | Description | | --- | --- | | `INSERT INTO
(, ) VALUES (, )` | Insert a new row into a table | | `SELECT * FROM
` | Retrieve all rows from a table | | `UPDATE
SET = WHERE = ` | Update rows in a table | | `DELETE FROM
WHERE = ` | Delete rows from a table | Data Query Language (DQL) ------------------------- | Command | Description | | --- | --- | | `SELECT , FROM
` | Retrieve specific columns from a table | | `SELECT * FROM
WHERE = VALUE` | Retrieve rows that match a condition | | `SELECT * FROM
ORDER BY ` | Retrieve rows sorted by a column | | `SELECT * FROM
LIMIT N` | Retrieve the first N rows from a table | | `SELECT * FROM
OFFSET N` | Retrieve rows starting from the Nth row | | `SELECT * FROM
JOIN ON . = .` | Retrieve rows from two tables that match a condition | | `SELECT * FROM
UNION SELECT * FROM ` | Retrieve rows from two tables without duplicates | | `SELECT * FROM
GROUP BY ` | Group rows that have the same value in a column | | `SELECT * FROM
HAVING COUNT() > N` | Filter grouped rows that have more than N rows | | `SELECT * FROM
WHERE IN (, )` | Retrieve rows where a column value matches any value in a list | | `SELECT * FROM
WHERE BETWEEN AND ` | Retrieve rows where a column value is within a range | | `SELECT * FROM
WHERE LIKE '%'` | Retrieve rows where a column value matches a pattern | | `SELECT * FROM
WHERE IS NULL` | Retrieve rows where a column value is NULL | | `SELECT * FROM
WHERE IS NOT NULL` | Retrieve rows where a column value is not NULL | Data Control Language (DCL) --------------------------- | Command | Description | | --- | --- | | `GRANT PERMISSIONS ON
TO ` | Grant permissions to a user | | `REVOKE PERMISSIONS ON
FROM ` | Revoke permissions from a user | Transaction Control Language (TCL) ---------------------------------- | Command | Description | | --- | --- | | `BEGIN TRANSACTION` | Start a new transaction | | `COMMIT` | Save changes to the database | | `ROLLBACK` | Discard changes to the database | | `SAVEPOINT ` | Create a savepoint in a transaction | | `ROLLBACK TO SAVEPOINT ` | Rollback to a savepoint in a transaction | | `RELEASE SAVEPOINT ` | Remove a savepoint in a transaction | System Commands --------------- | Command | Description | | --- | --- | | `SHOW DATABASES` | List all databases | | `SHOW TABLES` | List all tables in the current database | | `SHOW COLUMNS FROM
` | List all columns in a table | | `SHOW INDEXES FROM
` | List all indexes in a table | | `SHOW CREATE TABLE
` | Show the SQL statement that creates a table | | `DESCRIBE
` | Show the structure of a table | | `EXPLAIN SELECT * FROM
` | Show the execution plan of a query | | `SET autocommit = 0` | Disable autocommit mode | | `SET autocommit = 1` | Enable autocommit mode | | `SET FOREIGN_KEY_CHECKS = 0` | Disable foreign key checks | User Commands ------------- | Command | Description | | --- | --- | | `CREATE ''@'' IDENTIFIED BY ''` | Create a new user | | `DROP ''@''` | Delete a user | | `ALTER ''@'' IDENTIFIED BY ''` | Change password for a user | | `GRANT ALL PRIVILEGES ON TO ''@''` | Grant all privileges to a user | | `REVOKE ALL PRIVILEGES ON FROM ''@''` | Revoke all privileges from a user | | `FLUSH PRIVILEGES` | Reload privileges from the grant tables |