ADVERTISEMENT

SQL Statements

SQL statements are the individual commands you use to interact with the database. Each statement tells the database what action to perform — from retrieving data to modifying the structure.

✍️ What Are SQL Statements?

A SQL statement is a complete instruction made up of one or more clauses. These statements can be grouped into several categories based on their purpose:

  • Data Query Language (DQL) – Retrieve data (SELECT)
  • Data Manipulation Language (DML) – Modify data (INSERT, UPDATE, DELETE)
  • Data Definition Language (DDL) – Define or alter database objects (CREATE, ALTER, DROP)
  • Data Control Language (DCL) – Manage permissions (GRANT, REVOKE)
  • Transaction Control Language (TCL) – Manage transactions (COMMIT, ROLLBACK, SAVEPOINT)

⚙️ Common SQL Statements Overview

CategoryStatementPurposeExample
DQLSELECTRetrieve data from tablesSELECT * FROM employees;
DMLINSERTAdd new recordsINSERT INTO employees (name) VALUES ('Alice');
UPDATEModify existing recordsUPDATE employees SET age = 30 WHERE id = 1;
DELETERemove recordsDELETE FROM employees WHERE age < 20;
DDLCREATE TABLECreate a new tableCREATE TABLE employees (id INT, name VARCHAR(50));
ALTER TABLEChange table structureALTER TABLE employees ADD COLUMN salary INT;
DROP TABLEDelete a tableDROP TABLE employees;
DCLGRANTGive permissions to usersGRANT SELECT ON employees TO user1;
REVOKERemove permissionsREVOKE SELECT ON employees FROM user1;
TCLCOMMITSave all changes in a transactionCOMMIT;
ROLLBACKUndo changes since last COMMITROLLBACK;

🧩 Statement Syntax Basics

Every SQL statement has:

  • A command keyword (e.g., SELECT, INSERT)
  • Optional clauses (e.g., WHERE, ORDER BY)
  • Terminates with a semicolon (;)

Example:

SELECT name, age
FROM employees
WHERE age > 25
ORDER BY age DESC;

💡 Tips to Remember

  • Always end statements with a semicolon.
  • Use uppercase for commands to improve readability.
  • Write one statement per query execution (unless your database supports batch execution).
  • Use comments (we’ll cover next) to explain complex queries.

🧠 Quick Recap

Key PointDetails
SQL StatementCommand instructing database action
CategoriesDQL, DML, DDL, DCL, TCL
End with semicolonMarks completion of statement
Write clear and readableUse uppercase commands and formatting

ADVERTISEMENT