SQL Command Types

SQL stands for Structured Query Language. It is used in programming and designed for managing data held in a Relational Database Management System (RDBMS).

SQL is used to communicate with and manipulate databases. It allows users to perform various tasks such as retrieving data from a database, updating data, inserting data into a database, and deleting data from a database.

SQL is a standard language, but different database management systems may implement it slightly differently.

Examples include

  • MS SQL Server by Microsoft
  • PL/SQL by Oracle

SQL commands can be categorized into several types based on their functionality and purpose.

  1. Data Definition Language (DDL)
  2. Data Manipulation Language (DML)
  3. Data Control Language (DCL)
  4. Transaction Control Language (TCL)
  5. Data Query Language (DQL)
    SQL Command type

Data definition language (DDL)

It is used to define and manage the structure of database objects.

  • CREATE TABLE: Used to create a new table in the database.
  • ALTER TABLE: Used to modify the structure of an existing table.
  • DROP TABLE: Used to delete a table from the database.
  • TRUNCATE TABLE: Used to remove all rows without logging individual row deletions.
  • RENAME: Used to modify the structure or names of database objects.
  • CREATE INDEX: Used to create an index on one or more columns of a table.
  • ALTER INDEX: Used to modify an existing index, such as renaming it or changing its definition.
  • DROP INDEX: Used to delete an existing index from the database.

Data manipulation language (DML)

It is used to manipulate data stored in the database. DML commands allow users to query, insert, update, and delete data from database tables.

  • SELECT: Used to retrieve data from one or more tables in the database.
  • INSERT INTO: Used to add new records (rows) to a table.
  • UPDATE: Used to modify existing records (rows) in a table.
  • DELETE FROM: Used to delete existing records (rows) from a table.
  • MERGE: Used to perform an "upsert" operation, which means it can perform both INSERT and UPDATE operations within a single statement based on a specified condition.

Data control language (DCL)

The commands that regulate access to data within a database. It manages user privileges and permissions, ensuring data security and integrity.

  • GRANT: This command assigns specific privileges to database users or roles.
  • REVOKE: This command revokes previously granted privileges from users or roles, restricting their access to specific database objects.

Transaction control language (TCL)

The commands are used to manage transactions within a database. Transactions are sequences of one or more SQL statements that are treated as a single unit of work.

  • COMMIT: This command is used to permanently save the changes made during the current transaction to the database.
  • ROLLBACK: This command is used to undo the changes made during the current transaction and restore the database to its state before the transaction begins.
  • SAVEPOINT: This command is used to set a savepoint within a transaction, allowing you to roll back to that point if necessary.

Data query language (DQL)

It is used to retrieve information from databases. It allows users to extract specific data that meets certain criteria or requirements.

  • SELECT: The SELECT statement retrieves data from one or more tables in the database.

SQL commands encompass various functionalities, from defining database structures to manipulating data and controlling access. By understanding the various types of SQL commands—DDL, DML, DCL, TCL, and DQL—database users can effectively interact with their data, ensuring its integrity, security, and accessibility.

If you need to delve deeper into any of these command types, please don't hesitate to comment below..!

Similar Articles