This is a very basic question asked by some interviewers. The Subsets are the pillars of Structured query language. Without subsets, it is not possible to manipulate the database and to create and build applications successfully. The DDL, DML, DCL, and TCL are responsible for building robust database applications and they all can be effectively utilized even in procedures and functions of SQL. We can split SQL into these five areas.
It mainly and solely contains the “SELECT” statement. SELECT is concerned simply with retrieving data stored in a database. It has optional clauses and tweaks.
It is concerned about the manipulation of data within a database. DML consists of four commonly used statements: INSERT, UPDATE, DELETE and MERGE. DML gives a method to understand, modify, delete, or merge data accurately. The SQL commands mostly include the modification of data. This contains most of the SQL statements.
INSERT | Insert new records in the table. |
UPDATE | Updates existing records within the table. |
DELETE | Deletes records within tables. |
MERGE | It’s like an upsert operation. It performs both insert and update operations based on conditions. |
The primary purpose of DDL is to create, modify or remove tables and other objects such as stored procedures, functions, triggers; from the database. It consists of variations of CREATE, ALTER, and DROP statements.
Data Definition Language includes the SQL commands that can be applied to specify the database schema. It entirely deals with depictions of the database schema and is utilized to build and change the design of database objects.DDL is a collection of SQL commands utilized to develop, alter, and delete database designs but not data. These commands are usually not utilized by a common user, who should be using the database.
CREATE | It creates SQL objects like stored procedures, tables, columns, etc. |
ALTER | It modifies existing SQL objects. |
DROP | Deletes existing objects. |
It’s for restricting access to tables and database objects. It’s composed of various GRANT and REVOKE statements that allow or deny user access to database objects.
Data control language (DCL) is applied to use the accumulated data. It is primarily utilized for revoking and to allow the user the necessary privileges to a database. It aids in maintaining access to data held in a database. It fulfills the data manipulation language (DML) and the data definition language (DDL). It delivers the managers, to clear and establish database permissions to the users as required.
GRANT | Allows users to read/write on certain objects. |
REVOKE | Denies users to access specific objects. |
TCL is concerned about initiating, committing, or rolling back transactions. A transaction is basically a unit of work performed by a server. Its main purpose is to maintain the integrity of data within SQL statements. It contains statements like BEGIN TRANSACTION, COMMIT, and ROLLBACK.
TCL contains statements that are utilized to manage the modifications that are created from DML statements. It improves the transactional character of SQL. A transaction symbolizes any modification in a database; it is the outcome executed against a database, invariably, and autonomous of other transactions. TCL commands are utilized to follow the consequences of other commands on the database. They are also utilized to maintain transactional processing in a database. The modifications completed by utilizing TCL commands are enduring and cannot be rolled back.
BEGIN TRANSACTION | Opens a transaction. |
COMMIT | Indicates transaction is completed. Closes transaction. |
ROLLBACK | ROLLBACK a transaction in case of error. |
(TCL) Transaction Control Language, the administration of transactions inside a database is dealt with by TCL, a subset of SQL. It contains the words BEGIN TRANSACTION, COMMIT, and ROLLBACK.
In SQL, queries are fundamental processes. This is how the “SELECT” query is used to retrieve data from the database. This procedure is crucial because it allows users to choose particular data from the large quantity of data that has been saved. The data retrieval process may be honed by combining the SELECT statement with different clauses like WHERE, GROUP BY, HAVING, and ORDER BY. Users may more easily examine and comprehend data thanks to these clauses’ assistance in filtering, sorting, and grouping data. Understanding the complexity of queries is crucial for anybody working with SQL since they provide the basis for data manipulation and analysis.
The important SQL subset known as DML is used to manipulate data that is stored in a database. The INSERT, UPDATE, DELETE, and MERGE commands are among its four main components. These commands each have a specific function for handling the data in a database.
To insert new records into a table, use the INSERT command. Users may choose the values for each column in the new record, guaranteeing that the data is properly arranged.
On the other side, the UPDATE statement is utilized to change current records within a table. It may be used to update the data by modifying the values in one or more columns of a record.
To delete records from a table, use the DELETE statement. This command comes in handy especially when a record is outdated or inaccurate.
The INSERT and UPDATE operations are combined in the MERGE statement, commonly called as an upsert operation. It determines if a record already exists, changes it if so, and creates a new record if not. The database’s data integrity is particularly well-served by this command.
(DDL) Data Definition Language DDL is another significant SQL subset that handles the addition, erasure, and change of tables and other database objects. It contains the statements CREATE, ALTER, and DROP.
New SQL entities may be formed with the CREATE statement, including tables, columns, stored procedures, and more. Users can determine the structure of these objects using this DDL commands, including the data types for table columns.
Existing SQL objects can be modified using the ALTER statement. It may be used to rename columns or tables, add, edit, or remove columns from tables, alter the data type of a column, and more.
(DCL) Data Control Language A subset of SQL called DCL deals with a database’s permissions and access restrictions. It contains the statements GRANT and REVOKE.
Giving users access to carry out certain activities on particular database objects is done using the GRANT statement. These permissions may grant access to SELECT, INSERT, UPDATE, DELETE, and other operations.
However, these rights can be revoked using the REVOKE statement. The data is safeguarded and secure because it enables database managers to keep control over who may do what in the database.
A new transaction may be started by using the BEGIN TRANSACTION statement. A series of one or more SQL operations that are carried out simultaneously constitute a transaction. This implies that either all operations are carried out successfully or, if one fails, no operations are carried out at all.
The database changes made by the transaction are saved using the COMMIT command. Changes made after a transaction has been committed cannot be undone.
In order to reverse the changes made by a transaction, use the ROLLBACK statement. The database can be returned to its previous state using the ROLLBACK command in the event that any transactional operation fails. This guarantees that the database’s data integrity is preserved.