w3resource

SQL Commands


SQL (Structured Query Language) is used to communicate with relational databases.

Using SQL commands, we can create databases, store data, retrieve records, update information, and control access securely.

SQL commands are broadly classified based on what they do and how they affect data.


What Are SQL Commands?

SQL commands are predefined instructions used to perform operations on a database, such as:

  • Creating tables and databases
  • Inserting, updating, and deleting data
  • Retrieving records
  • Managing user access and permissions
  • Controlling transactions

They work across most relational database systems with minor syntax differences.


Types of SQL Commands

SQL commands are mainly divided into five categories:

  1. DDL – Data Definition Language
  2. DML – Data Manipulation Language
  3. DQL – Data Query Language
  4. DCL – Data Control Language
  5. TCL – Transaction Control Language

1. Data Definition Language (DDL)

DDL commands are used to define and modify database structure.

Common DDL Commands

Command Purpose
CREATE Creates database objects
ALTER Modifies existing objects
DROP Deletes objects permanently
TRUNCATE Removes all records from a table

Example :



CREATE TABLE students (
    id INT,
    name VARCHAR(50)
);

2. Data Manipulation Language (DML)

DML commands are used to insert, update, and delete data in tables.

Common DML Commands

Command Purpose
INSERT Adds new records
UPDATE Modifies existing records
DELETE Removes records

Example :


INSERT INTO students VALUES (1, 'Rahul');

3. Data Query Language (DQL)

DQL commands are used to retrieve data from databases.

Main DQL Command

  • SELECT

Example :


SELECT name FROM students;

DQL is the most frequently used category in SQL.


4. Data Control Language (DCL)

DCL commands manage user permissions and access control.

Common DCL Commands

Command Purpose
GRANT Gives permissions
REVOKE Removes permissions

Example :


GRANT SELECT ON students TO user1;

5. Transaction Control Language (TCL)

TCL commands manage transactions to maintain data integrity.

Common TCL Commands

Command Purpose
COMMIT Saves changes permanently
ROLLBACK Undoes changes
SAVEPOINT Sets a rollback point

Example :


ROLLBACK;

Difference Between DDL, DML, and DQL

Feature DDL DML DQL
Structure Defines structure Manipulates data Retrieves data
Rollback Not possible Possible Not applicable
Common Use Table creation Data changes Data fetching

Why SQL Commands Are Important

  • Used in almost all database-driven applications
  • Essential for backend development
  • Required for data analysis and reporting
  • Frequently asked in interviews and exams
  • Forms the base for advanced database concepts

Real-World Uses of SQL Commands

  • Banking systems
  • Student and employee databases
  • E-commerce applications
  • Hospital management systems
  • Reporting and analytics dashboards

Common Mistakes Beginners Make

  • Forgetting WHERE clause in DELETE or UPDATE
  • Mixing DDL and DML concepts
  • Not using transactions for critical operations
  • Assuming SQL is case-sensitive (mostly it’s not)

Previous : SQL Question Answer
Next : SQL: Quizzes



Follow us on Facebook and Twitter for latest update.