Hero Vired Logo
Programs
BlogsReviews

More

Vired Library

Complimentary 4-week Gen AI Course with Select Programs.

Request a callback

or Chat with us on

Home
Blogs
Different Types of SQL Commands – DDL, DML, DCL, TCL, DQL

In the dynamic world of databases, SQL commands serve as the guiding stars, illuminating the path to effective data management. As demand for SQL professionals escalates in the corridors of corporate giants, enticing with competitive pay packages and coveted roles, mastering these diverse command types becomes not just a skill but a gateway to unlocking boundless opportunities in the ever-expanding realm of data.

 

Let’s unravel the fascinating tapestry of SQL commands, each with its unique purpose and role. 

 

Table of Contents:

 

 

What are Databases?

 

A database constitutes a methodically arranged assembly of data retained within a computer system, typically overseen by a database management system (DBMS). Within conventional databases, data is structured into tables, optimising the efficacy of querying and processing operations. Frequently employed for data querying and composition tasks, structured query language (SQL) plays a pivotal role in managing databases.

 

Databases permeate various facets of daily life, permeating activities ranging from banking transactions and railway operations to school administration and retail management. These scenarios exemplify instances wherein copious amounts of data necessitate centralised storage and effortless retrieval, underscoring the indispensability of databases in modern society.

 

What is SQL?

 

SQL is a full form of Structured Query Language that describes the foundation of data management and manipulation under relational databases. Since SQL languages are domain-specific languages, SQL helps to form seamless connections and communication within databases. 

 

What is SQL Command?

 

SQL commands serve as directives utilized to interact with databases, facilitating communication and executing specific tasks and data queries. Through SQL, users can undertake a multitude of operations, such as creating tables, adding data to existing tables, dropping tables, modifying table structures, and setting permissions for user access. This language acts as the conduit through which users navigate the complexities of database management, empowering them to wield control over data structures, content, and security measures with precision and efficiency.

 

From the creation of tables to the insertion of data, from querying information to controlling access and security measures, SQL commands encapsulate the essence of database management, acting as the guiding force behind every database operation. Categorised into distinct types, each SQL command fulfils a specific role in the intricate dance of data manipulation, ensuring that databases remain organised, efficient, and secure in the hands of proficient SQL practitioners.

 

Types of SQL Commands

 

There are five types of SQL commands. They are DDLs, DMLs, DCLs, TCLs and DQL. 

 

1. Data Definition Language (DDL):

 

DDL, or Data Definition Language, encompasses actions that alter the structure of tables, such as creating, deleting, or modifying them. Notably, all DDL commands are auto-committed, signifying that any alterations made are instantaneously and permanently saved within the database.

 

Here are some commands that come under DDL:

  • CREATE
  • ALTER
  • DROP
  • TRUNCATE

 

  • CREATE:  It is used to create a new table in the database.
    Syntax:
    CREATE TABLE TABLE_NAME
    (
    COLUMN_NAME1 DATATYPES(size)s

    COLUMN_NAME2 DATATYPES(size)s

    ————–
    COLUMN_NAMEN DATATYPES(size)s
    );Example:CREATE TABLE EMP( EMPNo VARCHAR2(20)s EName VARCHAR2(20)s

     Job VARCHAR2(20)s

     DOB DATE

    );

 

  •  ALTER: This command is used to delete, modify or add constraints or columns in an existing table. The ‘ALTER TABLE’ Statement This statement is used to add, delete, and modify columns in an existing table. The ‘ALTER TABLE’ Statement with ADD/DROP COLUMN You can use the ALTER TABLE statement with the ADD/DROP Column command according to your need. If you wish to add a column, then you will use the ADD command, and if you wish to delete a column, then you will use the DROP COLUMN command.Syntax:
    • ALTER TABLE TableName ADD ColumnName Datatype;

     

    • ALTER TABLE TableName DROP COLUMN ColumnName;

     

    Example

     

    –ADD Column MobNo:

     

           ALTER TABLE Emp ADD MobNo Number(10);

     

    –DROP Column MobNo:

     

     ALTER TABLE Emp DROP COLUMN MobNo ;

     

    The ‘ALTER TABLE’ Statement with ALTER/MODIFY COLUMN

    This statement is used to change the datatype of an existing column in a table.

     

    Syntax

     

          ALTER TABLE TableName ADD COLUMN ColumnName Datatype;

     

    Example

     

       –Add a column DOB and change the data type to Date.

        ALTER TABLE Emp ADD DOB date;

 

  • TRUNCATE:  This command is used to delete the information present in the table but does not delete the table. So, once you use this command, your information will be lost, but not the table.Syntax 
    DROP DATABASE DatabaseName;

    Example
    DROP DATABASE Employee;The ‘DROP TABLE’ Statement This statement is used to drop an existing table. When you use this statement, the complete information present in the table will be lost.  

    Syntax 

     

    DROP TABLE TableName; 

     

    Example 

     

    DROP Table Emp;

 

  • DROP : This statement is used to drop an existing database. When you use this statement, complete information present in the database will be lost.Syntax 
    DROP DATABASE DatabaseName;
    Example

    DROP DATABASE Employee;The ‘DROP TABLE’ Statement

     

    This statement is used to drop an existing table. When you use this statement, the complete information present in the table will be lost. 

     

    Syntax 

     

    DROP TABLE TableName; 

     

    Example 

     

    DROP Table Emp;

 

2. Data Control Language (DCL)

 

DCL commands are used to grant and test back authority from any database user. 

 

Here are some commands that come under DCL: 

 

  • Grant
  • Revoke

 

  • Grant: It is used to give user access privileges to a database.

    Example
    GRANT SELECT,
    UPDATE ON MY_TABLE TO SOME_USERs ANOTHER_USER; 

 

  • Revoke: It is used to get permission from the user
    Example 
    REVOKE SELECTs UPDATE ON MY_TABLE FROM USER1s USER2;

 

3. Data Manipulation Language (DML)

 

DML commands are utilised to alter the database, encompassing all types of modifications.

These commands do not automatically commit changes, implying they cannot permanently store alterations within the database. They are subject to rollbacks.

 

Below are several commands falling under DML:

 

  • INSERT
  • UPDATE
  • DELETE

 

  • INSERT: The INSERT statement is a SQL query. It is used to insert data into the row of a table.Syntax:

    INSERT INTO TABLE_NAME (col1s col2s col3s…. col N) VALUES (value1s value2s value3s …. valueN);
    Or

    INSERT INTO TABLE_NAME 

    VALUES (value1s value2s value3s …. valueN);

     

    For example:

    INSERT INTO EMP(ENamesJob)
    VALUES (“SCOTT”s “MANAGER”);

     

    For example:
    INSERT INTO EMP(ENamesJob) VALUES (“SCOTT”s “MANAGER”);

     

  • DELETE: It is used to remove one or more rows from a table.Syntax1:
    DELETE FROM table_name;
    Syntax1
    DELETE FROM table_name WHERE condition;Example1:
    Delete all rows from emp table

     

     DELETE FROM Emp;

     

    Example2:

    Delete all rows from emp table whose Ename is SCOTT

       DELETE FROM EName WHERE EName=”SCOTT”;

 

  • UPDATE: This command is used to update or modify the value of a column in the table.Syntax:
    UPDATE table_name SET column1= values column2= valuescolumnN = value WHERE CONDITION;For example:
    UPDATE Emp SET Ename = ‘SMITH’ WHERE EmpNo = ‘1003’;

 

4. Transaction Control Language (TCL)

 

TCL commands can only be used in conjunction with DML commands, such as INSERT, DELETE, and UPDATE. 

 

These actions are automatically committed in the database, hence they cannot be employed during table creation or deletion.

 

 Below are some examples of TCL commands:

 

  • COMMIT
  • ROLLBACK
  • SAVEPOINT

 

  • Rollback: The Rollback command is used to undo transactions that have not already been saved to the database.Syntax:
    ROLLBACK;
    Example: 
    DELETE FROM CUSTOMERS WHERE AGE = 25;
      ROLLBACK;

 

  • SAVEPOINT: It is used to roll the transaction back to a certain point without rolling back the entire transaction.Syntax:
    SAVEPOINT SAVEPOINT_NAME;

 

  • Commit: The commit command is used to save all the transactions to the Database.

    Syntax: 

    COMMIT;
    Example:
    DELETE FROM CUSTOMERS WHERE AGE = 25;
     COMMIT;

 

5. Data Query Language (DQL)

 

DQL, or Data Query Language, statements are utilised to execute queries on data stored within schema objects. The primary objective of DQL commands is to fetch specific schema relations based on the provided query. DQL can be defined as a segment of SQL statements dedicated to fetching data from the database and arranging it in a specified order. This functionality is encapsulated within the SELECT statement. 

 

SELECT allows the extraction of data from the database for subsequent operations. Upon executing a SELECT statement against one or more tables, the resulting dataset is typically compiled into a temporary table, which can then be displayed or accessed by the application, such as a front-end interface.

 

Saving a SQL Command

 

You have the option to store the SQL commands you input within SQL Commands.

 

Here’s how to save a SQL command:

 

  1. Navigate to the Workspace home page and select SQL Workshop, then click on SQL Commands.
  2. You’ll be directed to the SQL Commands page.
  3. Input your command into the command editor.
  4. Press the Save button to store the command.
  5. You’ll be asked to provide a name and description for the command.
  6. Choose to Save the command or click Cancel to go back to the command editor without saving.
  7. The saved command will be displayed in the list area.

 

Long Story Short

Therefore, in today’s data-driven era, grasping SQL is essential. SQL’s seamless interaction with databases empowers both individuals and organisations to effectively handle, retrieve, and manipulate extensive datasets. Whether you’re a data analyst, software developer, or business professional, mastering SQL opens doors to diverse career paths and amplifies your capacity to draw informed conclusions from data insights. Choose Certificate Program in Application Development to gain hands-on experience, deepen your understanding of SQL principles, and sharpen your skills in handling complex queries.

 

 

 

FAQ's

SQL serves as a standardised language for interacting with databases. Its commands act as directives, facilitating various tasks, functions, and data queries within the database. These commands encompass searching the database and executing functions such as table creation, data insertion, modification, and table deletion.
SQL helps as the medium for communication with databases, established as the standard language for relational database management systems by the American National Standards Institute (ANSI). SQL statements facilitate various tasks including updating data within a database or retrieving data from it.
Database Management Systems (DBMS) are software systems employed for the storage, retrieval, and execution of queries on data.
Considering the criteria of a programming language, which involves possessing a defined vocabulary and syntax, SQL undeniably meets these qualifications. However, it falls short of being categorised as a General Purpose Language (GPL) and is instead recognised as a Domain-Specific Language (DSL).

High-growth programs

Choose the relevant program for yourself and kickstart your career

You may also like

Carefully gathered content to add value to and expand your knowledge horizons

Hero Vired logo
Hero Vired is a premium LearnTech company offering industry-relevant programs in partnership with world-class institutions to create the change-makers of tomorrow. Part of the rich legacy of the Hero Group, we aim to transform the skilling landscape in India by creating programs delivered by leading industry practitioners that help professionals and students enhance their skills and employability.

Data Science

Accelerator Program in Business Analytics & Data Science

Integrated Program in Data Science, AI and ML

Accelerator Program in AI and Machine Learning

Advanced Certification Program in Data Science & Analytics

Technology

Certificate Program in Full Stack Development with Specialization for Web and Mobile

Certificate Program in DevOps and Cloud Engineering

Certificate Program in Application Development

Certificate Program in Cybersecurity Essentials & Risk Assessment

Finance

Integrated Program in Finance and Financial Technologies

Certificate Program in Financial Analysis, Valuation and Risk Management

Management

Certificate Program in Strategic Management and Business Essentials

Executive Program in Product Management

Certificate Program in Product Management

Certificate Program in Technology-enabled Sales

Future Tech

Certificate Program in Gaming & Esports

Certificate Program in Extended Reality (VR+AR)

Professional Diploma in UX Design

Blogs
Reviews
In the News
About Us
Contact us
Vired Library
18003093939     ·     hello@herovired.com     ·    Whatsapp
Privacy policy and Terms of use

© 2024 Hero Vired. All rights reserved