Structured Query Language (SQL) serves as the foundation for managing and manipulating relational databases, providing a structured approach to interact with data. Understanding the basic components of SQL is essential for anyone involved in database management or web development.
SQL consists of several key elements, including Data Definition Language (DDL) for defining database structures, Data Manipulation Language (DML) for handling data operations, and Data Query Language (DQL) for retrieving specific information.
This article explores the basic components of SQL, diving deep into semantic of each. The knowledge gained will help you to understand what are the basic and important commands that any developers and database administrators should know.Database Languages / Basic Components of SQL
Database Languages / Basic Components of SQL
The SQL commands are categorised into different database languages as below:
1) DDL (Data Definition Language):
It is set of commands used to create, modify or change and delete or remove database objects such as tables, views, indices etc. It is used to define the database structure.
Database Administrator (DBA) and database designers normally use it.
It provides commands like –
i) CREATE:
to create objects in a database.
ii) ALTER: to change the schema or logical structure of the database.
iii) DROP: to delete objects from the database when they are no longer needed.
iv) TRUNCATE: to remove all records from the table.
v) RENAME: to change the name of the table.
2) DML (Data Manipulation Language):
It is set of commands used to add,
modify or change and delete or remove data (rows) in a database. It is used to
manage data within objects.
General users who are accessing database via pre-developed applications normally use it.
It provides commands like –
i) INSERT:
to add new rows of data in the table. (To insert data into a table).
ii) UPDATE: to modify or change existing data in a table. (To modify column values in existing rows).
iii) DELETE: to delete records from a table. (To remove the rows from a table).
iv) LOCK: to lock tables to provide concurrency control among multiple users.
3) DCL (Data Control Language):
It is set of commands used to control access to data and database.
Occasionally DCL commands are grouped with DML commands.
It provides commands like –
i) GRANT:
to give access rights to users on the database
ii) REVOKE: to withdraw access rights given to the users on the database
4) TCL (Transaction Control Language):
It is set of commands to manage the
changes made by DML statements to the database.
It provides commands like –
i) COMMIT:
to save the changes permanently.
ii) ROLLBACK: to undo work and restore database to previous state.
iii) SAVEPOINT: to identify a point in a transaction to which work can be undone.
5) DQL (Data Query Language):
It is a component of SQL that allows
data retrieval from the database in any combination, expression or order.
Queries usually begin with reserved work like SELECT followed by data desired, and the tables or views containing the source data.
Eg. SELECT ename, sal from emp;
Query do not change any data, they only retrieve data.
They are often categorized with DML statements.
Conclusion:
In conclusion, a comprehensive understanding of the basic components of SQL is key for developers and database administrators to manage databases efficiently and help in performing data operations with ease.