In SQL operations are typically classified into a few distinct groups based on their purpose and functionality. Each serving different roles in database management and manipulation.
Data Manipulation Language (DML) is a subset of SQL used for adding (inserting), deleting, and modifying (updating) data in a database. DML is all about managing data within the tables. Here are the key DML commands:
UPDATE
command can change data in one or more rows, and it is often used with a WHERE
clause to specify which rows should be updated.UPDATE
, it is typically used with a WHERE
clause to specify which rows should be removed.Data Control Language (DCL) is used to define access permissions and security levels for database users and objects. It involves commands that control access to data within the database and command execution. The primary commands under DCL include:
GRANT
, this command removes specified permissions from a user. It is used to enforce security for sensitive data and to ensure that only authorized users have certain abilities.Data Definition Language (DDL) involves commands that define the structure of the database itself. This includes creating, altering, and deleting database objects such as tables, indexes, and views. The primary DDL commands include:
CREATE TABLE
is used to create a new table, CREATE INDEX
to create an index, and CREATE DATABASE
to create a new database.ALTER TABLE
commonly adds, deletes, or modifies columns in a table, or changes its characteristics.DROP TABLE
deletes a table, DROP INDEX
removes an index, and DROP DATABASE
deletes an entire database.DELETE
command as it bypasses several integrity enforcement mechanisms.Transaction Control Language (TCL) commands are used to manage transactions within the database. Transactions are important for maintaining data integrity, especially in environments where multiple users or applications might be modifying the data concurrently. The main TCL commands include:
SELECT
statement, is used for querying data, which is technically a form of data manipulation. DQL is crucial for retrieving information from a database without altering the data.SET
to change session settings or ALTER SESSION
. These are often used to configure aspects of the database environment that affect the execution of SQL statements but do not necessarily fit neatly into DDL, DML, or DCL.