SQL commands can be broadly categorised into several types based on their functionality and purpose in interacting with databases. Here are the main types of SQL commands:
1. Data Manipulation Language (DML) Commands:
DML commands are used to manipulate data stored in the database. They include:
EXPLAIN: Used to obtain information about how a SQL statement is executed. INSERT: Adds new rows of data into a table.
UPDATE: Modifies existing data in a table.
DELETE: Removes one or more rows from a table. LOCK: Used to lock database objects such as tables, rows.
2. Data Definition Language (DDL) Commands:
DDL commands are used to define, alter, and drop database objects such as tables and indexes. They include:
CREATE: Creates new database objects like tables, views, indexes, and sequences.
ALTER: Modifies the structure of existing database objects.
DROP: Deletes database objects from the database.
TRUNCATE: Used to quickly delete all rows from a table by keeping table schema.
3. Data Control Language (DCL) Commands:
DCL commands are used to control access to the database and its objects. They include:
GRANT: Gives specific privileges to database users.
REVOKE: Removes previously granted privileges from database users.
4. Transaction Control Commands (TCL):
Transaction control commands manage the changes made to the database within a transaction. They include:
COMMIT: Saves the changes made in the current transaction.
ROLLBACK: Reverts the changes made in the current transaction.
SAVEPOINT: Creates a point in the transaction to which you can later roll back.
5. Data Query Language (DQL) Commands:
DQL commands are used to retrieve data from the database. The primary DQL command is:
SELECT: Retrieves data from one or more tables based on specified criteria.
Conclusion:
Understanding the different types of SQL commands and their functionalities is crucial for effectively interacting with databases. Whether you're retrieving data, modifying database structures, or managing user privileges, having a strong grasp of SQL commands empowers you to work efficiently and effectively with relational databases.
2 Comments