Sri Divya
3 min readFeb 16, 2024

What is SQL? Types of SQL Commands

SQL stands for Structured Query Language, is a language specifically designed for accessing and interacting with databases. It allows users to create tables, modify data, and retrieve information in a fast and efficient manner. It is used to perform various operations on stored data in a database such as querying, update, insert, create and modifying schema(database structure) and also controlling access to the database’s data.

Structured Query Language

There are several types of SQL commands, broadly categorized into the following groups:

SQL Commands

DDL Commands: DDL stands for Data defined languages used to change the structure of the table like creating ,altering and deleting the table.DDL Commands are auto committed that means it permanently save all the changes in the database.

Create : Used to create new tables, databases, or other database objects

Syntax: create table table_name(column1 datatype, column2 datatype2);

Alter: Used to modify the structure of existing database objects.

Syntax: Alter Table table_name ADD column_name datatype;

Truncate: Used to remove all records from a table, including all spaces allocated for the records are removed, but it will not remove the table itself

Syntax: Truncate Table table_name;

RENAME:Renaming offers more flexibility. It allows renaming multiple tables in one statement. This can be useful when replacing a table with a new version.

Syntax: Rename table old table name to new table name

DROP: Used to delete data objects from the database.

Syntax: DROP TABLE table_name;

DML Commands: DML stands for data manipulation language used to eal with the manipulation of data.

Common DML commands are stated below

SELECT: Used to query and retrieve data from a database.

Syntax: select column1,column2 from table

INSERT: Used to insert data into a table.

Syntax: Insert into table_name values(value1,value2,value3)

UPDATE: Used to modify existing data within a table.

Syntax: UPDATE table_name
SET column1 = value1, column2 = value2, …
WHERE condition;

DELETE: Used to remove data from a table.

Syntax: DELETE FROM table_name
WHERE condition;

TCL Commands: TCL stands for Transaction Control Language manage the changes made by DML statements. They are crucial for managing transactional processing within the database.

Common TCL commands are:

COMMIT: Saves all the transactions to the database.

Syntax: commit;

ROLLBACK: Restores the database to the last committed state.

Syntax: Rollback;

SAVEPOINT: Sets a savepoint within a transaction.

Syntax: Savepoint savepoint_name;

DCL Commands: DCL Stands for data control languages and are related to permissions and control access to the database data.

DCL commands include are:

GRANT:Used for access privileges to the tables and database.

Syntax: GRANT permission_type ON data object TO user;

Example: GRANT Select ON employees TO ‘SriDivya’;

REVOKE: Removes access privileges provided by the GRANT command.

Syntax: REVOKE permission_type ON object FROM user;

Example: REVOKE Select ON employees TO ‘SriDivya’;

References:

https://www.sitesbay.com/sql/sql-commands

No responses yet