3. Types of SQL

                                    



    
  1. Data Definition Language (DDL): It is used to define or modify the structure of database object such as table, views, index, etc. Some of DDL commands are as follows.
    • CREATE: It is used to create a new database object such as a table, view or index.
    • ALTER: It is used to modify the structure of an existing database object such as a table, view, or index.
    • DROP: It is used to delete an existing database object such as a table, view, or index.
    • TRUNCATE: It is used to delete all rows from a table, but it does not delete the table itself.
    • RENAME: It is used to rename an existing database object as a table, view or index.
    • COMMENT: It is used to add a comment to a database object as a table, column, or view. 
    • CONSTRAINT: It is used to define a rule or restriction on a table or column. Constraints can be used to enforce data integrity and maintain consistency in the database. 
    • INDEX: It is used to create an index on one or more columns in a table. Indexes can improve the performance of queries that search or sort data in the table. 
    • VIEW: It is used to create a virtual table that is based on the data from one or more tables in the database. Views can simplify complex queries and provide a more intuitive interface to the database. 
    • GRANT: It is used to give a user or role permission to access a database object such as a table, view, or index. Permission can be granted for different types of actions such as DELECT, INSERT, UPDATE, and DELETE.

  2. Data Manipulation Language (DML): It is used to manipulate data stored in database objects. Some common DML commands are: 
    • SELECT: It is used to retrieve data from one or more tables in the database. SELECT command is used to read the data and not to modify the data. 
    • INSERT: It is used to insert new rows of data into a table in the database. 
    • UPDATE It is used to modify existing data in a table in the database.
    • DELETE: It is used to delete one or more rows of data from a table in the database. 
    • MERGE: It is used to perform an UPSERT operation (a combination of INSERT and UPDATE) on a target table based on the contents of a source table. 

  3. Data Control Language (DCL): It is used to control access to the database objects.
    • GRANT: It is used to give a user or role permission to access a database object such as a table, view, or index. Permissions can be granted for different types of actions such as SELECT, INSERT, UPDATE, and DELETE. 
    • REVOKE: It is used to remove the permission of a user or role to access a database object. 
    • DENY: It is used to deny permission to a user or role to access a database object. This command is less commonly used as it is not supported by all database management system. 

  4. Transaction Control Language (TCL): It is used to control transactions in the database. Some common TCL commands are: 
    • COMMIT: It is used to permanently save the changes made during a transaction to the database.
    • ROLLBACK: It is used to undo the changes made during a transaction and restore the database to its previous state. 
    • SAVEPOINT: It is used to mark a point in a transaction to which the transaction can be rolled back later. 

  5. Data Query Language (DQL): It is used to retrieve data from one or more tables. 
    • SELECT: It is used to retrieve data from one or more tables in the database. SELECT command is used to read the data and not to modify the data. It allows users to specify which columns they want to retrieve, filter the data using WHERE clause, sort the data using ORDER BY clause, and group the data using GROUP BY clause. It is the most commonly used DQL command and is essential for retrieving data from databases. 



    Comments