SQL Commands and Queries: Quick Reference
DDL (Data Definition Language)
Command: CREATE TABLE
Syntax: CREATE TABLE table_name (column1 datatype, column2 datatype, ...);
Example: CREATE TABLE student (id INT, name VARCHAR(50), age INT);
Command: ALTER TABLE
Syntax: ALTER TABLE table_name ADD column_name datatype;
Example: ALTER TABLE student ADD address VARCHAR(100);
Command: DROP TABLE
Syntax: DROP TABLE table_name;
Example: DROP TABLE student;
Command: TRUNCATE TABLE
Syntax: TRUNCATE TABLE table_name;
Example: TRUNCATE TABLE student;
DML (Data Manipulation Language)
Command: INSERT INTO
Syntax: INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);
Example: INSERT INTO student (id, name, age) VALUES (1, 'John', 20);
Command: UPDATE
Syntax: UPDATE table_name SET column1 = value1 WHERE condition;
Example: UPDATE student SET age = 21 WHERE id = 1;
Command: DELETE
Syntax: DELETE FROM table_name WHERE condition;
Example: DELETE FROM student WHERE id = 1;
DQL (Data Query Language)
Command: SELECT
Syntax: SELECT column1, column2, ... FROM table_name WHERE condition;
Example: SELECT name, age FROM student WHERE age > 18;
TCL (Transaction Control Language)
Command: COMMIT
Syntax: COMMIT;
Example: COMMIT;
Command: ROLLBACK
Syntax: ROLLBACK;
Example: ROLLBACK;
DCL (Data Control Language)
Command: GRANT
Syntax: GRANT privilege ON object TO user;
Example: GRANT SELECT ON student TO 'user1';
Command: REVOKE
Syntax: REVOKE privilege ON object FROM user;
Example: REVOKE SELECT ON student FROM 'user1';