Understanding SQL Commands: DDL, DML, DCL, TCL, and DQL

Understanding SQL Commands: DDL, DML, DCL, TCL, and DQL

1. Data Definition Language (DDL)

DDL commands define and manage the structure of a database, including tables, indexes, and schema. These commands modify the database schema itself.

Common DDL Commands:

  • CREATE – Creates a new database object (table, view, index, etc.).

CREATE TABLE Employees (
    ID INT PRIMARY KEY,
    Name VARCHAR(50),
    Age INT,
    Department VARCHAR(50)
);        

  • ALTER – Modifies an existing database object.

ALTER TABLE Employees ADD COLUMN Salary DECIMAL(10,2);        

  • DROP – Deletes an entire database object.

DROP TABLE Employees;        

  • TRUNCATE – Removes all records from a table but retains its structure.

TRUNCATE TABLE Employees;        

2. Data Manipulation Language (DML)

DML commands are used to insert, update and delete data within a database.

Common DML Commands:

  • INSERT – Adds new records to a table.

INSERT INTO Employees (ID, Name, Age, Department) 
VALUES (1, 'John Doe', 30, 'IT');        

  • UPDATE – Modifies existing records.

UPDATE Employees SET Age = 31 WHERE ID = 1;        

  • DELETE – Removes specific records from a table.

DELETE FROM Employees WHERE ID = 1;        

3. Data Control Language (DCL)

DCL commands control access to database objects, ensuring data security and integrity.

Common DCL Commands:

  • GRANT – Provides user access rights to a database.

GRANT SELECT, INSERT ON Employees TO user1;        

  • REVOKE – Removes access rights from a user.

REVOKE INSERT ON Employees FROM user1;        

4. Transaction Control Language (TCL)

TCL commands manage transactions within a database, ensuring consistency and reliability.

Common TCL Commands:

  • COMMIT – Saves all changes made in the current transaction.

COMMIT;        

  • ROLLBACK – Reverts changes made in the current transaction.

ROLLBACK;        

  • SAVEPOINT – Creates a savepoint within a transaction for partial rollbacks.

SAVEPOINT save1;        

  • SET TRANSACTION – Defines transaction properties.

SET TRANSACTION READ ONLY;        

5. Data Query Language (DQL)

DQL is used to retrieve data from the database. It consists mainly of the SELECT statement.

Common DQL Command:

  • SELECT – Fetches records from a database based on specified conditions.

SELECT * FROM Employees WHERE Department = 'IT';        

6. Overview

Understanding these SQL command types is essential for database administrators and developers. DDL manages database structure, DML manipulates data, DCL handles permissions, and TCL ensures transactional integrity. Mastering these commands allows for efficient and secure database operations.

By leveraging these SQL commands effectively, organizations can optimize their database performance and maintain data integrity across applications.



Kaique Perez

Fullstack Software Engineer | Node | Typescript | React | Next.js | AWS | Tailwind | NestJS | TDD | Docker

2 周

Interesting! Thanks for sharing! Luiz Melo

Gabriel Levindo

Android Developer | Mobile Software Engineer | Kotlin | Jetpack Compose | XML

2 周

Great content!! Thanks for sharing!!

Jo?o Paulo Ferreira Santos

Data Engineer | AWS | Azure | Databricks | Data Lake | Spark | SQL | Python | Qlik Sense | Power BI

2 周

Very informative!

Daniel Cardoso

Mobile Senior Software Engineer | Android, Java/Kotlin, IOS Swift

2 周

Insightful

Aleson Fran?a

PHP | Laravel | React | FullStack Backend-focused Engineer | Developer | Engineer | Docker | Kubernetes | GCP

2 周

Interesting

要查看或添加评论,请登录

Luiz Melo的更多文章

  • COBOL Table Declaration: How to Use OCCURS for Data Arrays ????

    COBOL Table Declaration: How to Use OCCURS for Data Arrays ????

    1?? What is OCCURS in COBOL? The OCCURS clause defines a repeating group of fields within a structure, allowing you to…

    14 条评论
  • INSPECT vs. UNSTRING in COBOL: Mastering String Manipulation ????

    INSPECT vs. UNSTRING in COBOL: Mastering String Manipulation ????

    1?? INSPECT – The Quick Way to Analyze and Modify Strings The statement is used to count, replace, or convert…

    12 条评论
  • Common ABEND Codes in COBOL

    Common ABEND Codes in COBOL

    1. S0C4 – Protection Exception (Storage Violation) Cause: Attempt to access restricted or unallocated memory…

    46 条评论
  • Using the ADABAS Database in the NATURAL Language

    Using the ADABAS Database in the NATURAL Language

    ADABAS Structure ADABAS uses a data model based on records organized into files, where each file contains multiple…

    25 条评论
  • Exploring CICS: The IBM Transaction Monitor

    Exploring CICS: The IBM Transaction Monitor

    Key Features CICS offers several functionalities for transactional applications, including: Transaction Management:…

    39 条评论
  • ADABAS vs. DB2: Comparing Databases in Mainframe Environments

    ADABAS vs. DB2: Comparing Databases in Mainframe Environments

    What is ADABAS? ADABAS (Adaptable Database System) is a database management system (DBMS) developed by Software AG. It…

    42 条评论
  • The Importance of ROSCOE in the COBOL Environment

    The Importance of ROSCOE in the COBOL Environment

    What is ROSCOE? ROSCOE is an interactive work environment designed for mainframe systems. It provides a powerful…

    36 条评论
  • The Importance of TSO in the COBOL Environment

    The Importance of TSO in the COBOL Environment

    What is TSO? TSO is an interactive interface that allows users to access the z/OS operating system on a mainframe. It…

    77 条评论
  • COBOL Modernization

    COBOL Modernization

    Evolving Legacy Systems COBOL modernization refers to initiatives aimed at updating legacy applications written in this…

    24 条评论
  • The Importance of JCL in Mainframe

    The Importance of JCL in Mainframe

    Job Control Language (JCL) is an essential tool in mainframe environments, serving as the interface between users and…

    33 条评论

社区洞察