SQL Commands
What are SQL Commands?â
SQL commands are the fundamental building blocks for interacting with a DBMS. They perform various operations such as creating tables, inserting data, querying information, and managing access and security.
SQL commands are categorized into different types, each serving a specific purpose in database management:
Types of SQL Commandsâ
DDL (Data Definition Language)â
Data Definition Language (DDL) commands are used to define and manage database structures such as tables, indexes, and schemas.
- CREATE: Creates a new table or database.
- ALTER: Modifies an existing database object.
- DROP: Deletes an entire table, database, or other objects.
- TRUNCATE: Removes all records from a table, deleting the space allocated for the records.
DML (Data Manipulation Language)â
Data Manipulation Language (DML) commands are used for managing data within schema objects.
- INSERT: Adds new data to a table.
- UPDATE: Modifies existing data within a table.
- DELETE: Removes data from a table.
- CALL: Executes a stored procedure.
- EXPLAIN CALL: Provides information about how a stored procedure is executed.
- LOCK: Locks a table or a row for a transaction.
DCL (Data Control Language)â
Data Control Language (DCL) commands are used to control access to data within the database.
- GRANT: Gives users access privileges to the database.
- REVOKE: Removes access privileges given with the GRANT command.
TCL (Transaction Control Language)â
Transaction Control Language (TCL) commands are used to manage transactions in the database.
- COMMIT: Saves all changes made in the current transaction.
- ROLLBACK: Restores the database to the last committed state.
- SAVEPOINT: Sets a savepoint within a transaction.
- SET TRANSACTION: Places a name on a transaction.
DQL (Data Query Language)â
Data Query Language (DQL) commands are used to query the database for information.
- SELECT: Retrieves data from the database.