SQL (Structured Query Language) is the standard language for operating relational databases. SQL commands are broadly classified into three categories.
1. Data Manipulation Language (DML)
Commands for manipulating data within a database.
SELECT: Retrieves records (rows) from a database. Results can also be joined.INSERT: Inserts new records into a database table.UPDATE: Updates existing records in a database.DELETE: Deletes records from a database.
2. Data Definition Language (DDL)
Commands for defining, modifying, and deleting database structures and objects (tables, views, indexes, etc.).
CREATE: Creates new database objects (e.g.,CREATE TABLE,CREATE VIEW,CREATE INDEX).ALTER: Modifies the structure of existing database objects (e.g.,ALTER TABLEto add, remove, or modify columns).DROP: Deletes existing database objects (e.g.,DROP TABLE,DROP VIEW).RENAME: Renames database objects.TRUNCATE: Deletes all records from a table while keeping the table structure. UnlikeDELETE, it usually cannot be rolled back and is faster.
3. Data Control Language (DCL)
Commands for managing access privileges to the database and controlling transactions.
COMMIT: Confirms changes made in the current transaction and permanently saves them to the database.ROLLBACK: Undoes changes made in the current transaction, reverting to the state at the start of the transaction.SAVEPOINT: Sets a temporary save point within a transaction. You canROLLBACKto this save point.GRANT: Grants access privileges to database objects for users or roles.REVOKE: Revokes access privileges to database objects from users or roles.
By combining these commands, you can perform various operations including database design, data management, and security configuration.