SQL Command Types Explained: DDL, DML, DCL, and TCL

SQL Command Types Explained: DDL, DML, DCL, and TCL

The summary of the four key groups of SQL statements, including Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL) and Transaction Control Language (TCL). All these categories have different roles to play in database administration including defining the database, regulating access and transaction management. Knowing these categories of commands is essential in the database administration and development.

1. DDL – Data Definition Language

Purpose:
DDL statements are issued to specify and change the format of database items. These objects are tables, schema, views, indexes, and other database-associated elements. These structures are formed, modified and eliminated by DDL commands.




Common Commands:

  • CREATE - Drafts a brand new database object which includes a table, view, index or schema.
  • ALTER - It allows changes to made to an existing database object to its structure and properties.
  • DROP – Drops a database object, and removes it out of the database.
  • TRUNCATE - deletes all the records in a table in a single go. This operation is irreversible and it is swifter than a DELETE statement with no WHERE clause.

2. DML – Data Manipulation Language

Purpose:

The data in database tables is managed using DML commands. These commands will enable insinuation, revision, cancellation, and search data (analysis and reporting).


    • Common Commands:

       
      • INSERT - Adds new row sets of data in a table.
      • UPDATE - Altering of existing data in a table.
      • DELETE The delete command erases rows in a table.
      • SELECT - This is used to retrieve data in one or more tables of any given criteria. SELECT is a data manipulation language most often classified with DML in spite of being technically a DQL- Data Query Language- command.
       

      3. DCL – Data Control Language


      Purpose:

      DCL commands are invoked to regulate accessibility to data in the database. These commands will handle user privileges and security to make sure that particular data can only be accessed and updates by the permitted individuals.


Common Commands:

  • GRANT -Permits special authorization to users or roles to take specific actions upon database objects.
  • REVOKE -Western Union Revoke is used to revoke prior given permissions to users or roles and limit access to database objects.

4. TCL – Transaction Control Language

Purpose:
Transactions in the database are controlled by using TCL commands. Transactions refer to a set of operations which are considered from an integrated point of view. TCL Commands will enable you to regulate the performance and result of these transactions and make sure there is data consistency and integrity.


Common Commands:

  • COMMIT - Saves permanently all the changes performed in the present transaction in the database.
  • ROLLBACK - Discards all the modifications which happened over during the ongoing transaction and returns the database to its earlier state prior to the initiation of the transaction.
  • SAVEPOINT - This creates a point in a transaction to which you can deferentially roll back and you can discard only partial part of the transaction.
  • SET TRANSACTION- Sets properties of the current transaction, including level of isolation, or access mode.

visual summary and examples of each SQL command type:

Visual Summary Table

CategoryFull FormPurposeExample CommandsAuto-CommitRollback Possible
DDLData Definition LanguageDefines schema (structure)CREATEALTERDROPTRUNCATE✅ Yes❌ No
DMLData Manipulation LanguageWorks with table dataSELECTINSERTUPDATEDELETE❌ No✅ Yes
DCLData Control LanguageControls access & permissionsGRANTREVOKE✅ Yes❌ No
TCLTransaction Control LanguageManages transactionsCOMMITROLLBACKSAVEPOINT❌ No✅ Yes


Examples

DDL Example:


  1. CREATE TABLE Students (     StudentID INT,     Name VARCHAR(100),     Age INT );   

This command creates a new table named "Students" with three columns: "StudentID" (integer), "Name" (string), and "Age" (integer).

DML Example:

  1. INSERT INTO Students (StudentID, Name, Age) VALUES (1, 'Alice', 20);  UPDATE Students SET Age = 21 WHERE StudentID = 1;  
  2. DELETE FROM Students WHERE StudentID = 1;   

These commands demonstrate data manipulation: inserting a new student record, updating the age of a student, and deleting a student record.

DCL Example:

  1. GRANT SELECTINSERT ON Students TO user1;  
  2. REVOKE INSERT ON Students FROM user1;   

These commands control access to the "Students" table: granting a user named "user1" the ability to select and insert data, and then revoking the insert permission.

TCL Example:

  1. BEGIN TRANSACTION;    
  2. INSERT INTO Students (StudentID, Name, Age) VALUES (2, 'Bob', 22);    
  3. -- If no errors COMMIT;    
  4. -- If there's an error -- ROLLBACK;  


This example demonstrates a transaction: inserting a new student record within a transaction block. If the insertion is successful, the transaction is committed, saving the changes. If an error occurs, the transaction is rolled back, undoing the changes.

Conclusion:

It is necessary to become familiar with various kinds of SQL commands DDL, DML, DCL, and TCL as an efficient method of controlling and protecting data and database processing. Every type of command
supports a very unique role in defining the database structure, data manipulation, data control and processing of transactions. Such masters of these types of commands of a database administrator and
data integrity, security, and efficient databases performance can be guaranteed by developers.
 

0 Comments

Post Comment

Your email address will not be published. Required fields are marked *