Types of SQL Statements

First, Let’s understand what is SQL?

  • SQL stands for Structured Query Language.

  • SQL is used to query or manage the RDBMS.

  • SQL is a database language, it is used for database creation, deletion, fetching rows and modifying rows etc.

 

All DBMS like MySQL, Oracle, MS Access, Sybase, Informix, Postgres and SQL Server use SQL as the standard database language.

 

Uses of SQL

  • SQL is used to execute queries against a database.

  • SQL is used to retrieve data from a database.

  • SQL is used to define the data in the database and manipulate it when needed.

  • SQL is used to create Users, Databases, Tables, Schema and drop them.

  • SQL is used to create the view, stored procedure, function in a database.

  • SQL is used to set permission on tables, procedure, and view.

 

Types of SQL

SQL statements and commands are divided into 4 types. Let’s discuss these all these in details-

1. Data Manipulation Language (DML) Statements

Data Manipulation Language (DML) statements are used for managing data within schema objects.

  • SELECT – retrieve data from the database.

  • INSERT – insert data into a table.

  • UPDATE – updates existing data within a table.

  • DELETE – deletes all records from a table.

  • MERGE – UPSERT operation (insert or update).

 

2. Data Definition Language (DDL) Statements

Data Definition Language (DDL) statements are used to define the database structure or schema.

  • CREATE – to create objects in the database.

  • ALTER – alters the structure of the database.

  • DROP – delete objects from the database.

  • TRUNCATE – remove all records from a table.

  • COMMENT – add comments to the data dictionary.

  • RENAME – rename an object.

 

3. Data Control Language (DDL) Statements

Data Control Language (DCL) statements. DCL statements are used to provide and revoke the access privilege to use on database objects.

  • GRANT – gives user’s access privileges to the database.

  • REVOKE – withdraw access privileges given with the GRANT command.

 

4. Transaction Control Statements(TCL)

Transaction Control (TCL) statements are used to manage the changes made by DML statements. It allows statements to be grouped together into logical transactions.

  • COMMIT – save work done

  • SAVEPOINT – identify a point in a transaction to which you can later roll back

  • ROLLBACK – restore database to original since the last COMMIT

 

So we have seen the types of SQL statements. We will learn about the each statement in details in coming tutorials.

0 Comment

Leave a Reply