Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

SQL (Structured Query Language)

SQL (Structured Query Language) is a standard interactive and programming language for getting
information from and updating a database. Queries take the form of a command language that lets you
select, insert, update, find out the location of data, and so forth.

What is SQL?
SQL stands for Structured Query Language. SQL is used to communicate with a database.
According to ANSI (American National Standards Institute), it is the standard language for
relational database management systems(dbms). SQL statements are used to perform tasks such
as update data on a database, or retrieve data from a database. Some common relational database
management systems(dbms) that use SQL are: Oracle, Sybase, Microsoft SQL Server, Access,
Ingres, MySQL, etc. Although most database systems use SQL, most of them also have their
own additional proprietary extensions that are usually only used on their system. However, the
standard SQL commands such as "Select", "Insert", "Update", "Delete", "Create", and "Drop"
can be used to accomplish almost everything that one needs to do with a database. To use SQL
we need an SQL Interpreter.

SQL language is divided into four types of primary language statements: DML, DDL, DCL and
TCL. Using these statements, we can define the structure of a database by creating and altering
database objects, and we can manipulate data in a table through updates or deletions. We also
can control which user can read/write data or manage transactions to create a single unit of work.

The four main categories of SQL statements are as follows:

1. DML (Data Manipulation Language)


2. DDL (Data Definition Language)
3. DCL (Data Control Language)
4. TCL (Transaction Control Language)

DML (Data Manipulation Language)

DML statements affect records in a table. These are basic operations we perform on data such as
selecting a few records from a table, inserting new records, deleting unnecessary records, and
updating/modifying existing records.

DML statements include the following:

SELECT – select records from a table


INSERT – insert new records
UPDATE – update/Modify existing records
DELETE – delete existing records

DDL (Data Definition Language)

DDL statements are used to alter/modify a database or table structure and schema. These
statements handle the design and storage of database objects.

CREATE – create a new Table, database, schema


ALTER – alter existing table, column description
DROP – delete existing objects from database

DCL (Data Control Language)

DCL statements control the level of access that users have on database objects.

GRANT – allows users to read/write on certain database objects


REVOKE – keeps users from read/write permission on database objects

TCL (Transaction Control Language)

TCL statements allow you to control and manage transactions to maintain the integrity of data
within SQL statements.

BEGIN Transaction – opens a transaction


COMMIT Transaction – commits a transaction
ROLLBACK Transaction – ROLLBACK a transaction in case of any error

What are the difference between DDL, DML


and DCL commands?
DDL

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

o CREATE - to create objects in the database


o ALTER - alters the structure of the database
o DROP - delete objects from the database
o TRUNCATE - remove all records from a table, including all spaces allocated for the records are
removed
o COMMENT - add comments to the data dictionary
o RENAME - rename an object
DML

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

o SELECT - retrieve data from the a database


o INSERT - insert data into a table
o UPDATE - updates existing data within a table
o DELETE - deletes all records from a table, the space for the records remain
o MERGE - UPSERT operation (insert or update)
o CALL - call a PL/SQL or Java subprogram
o EXPLAIN PLAN - explain access path to data
o LOCK TABLE - control concurrency

DCL

Data Control Language (DCL) statements. Some examples:

o GRANT - gives user's access privileges to database


o REVOKE - withdraw access privileges given with the GRANT command

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.

o COMMIT - save work done


o SAVEPOINT - identify a point in a transaction to which you can later roll back
o ROLLBACK - restore database to original since the last COMMIT
o SET TRANSACTION - Change transaction options like isolation level and what rollback segment to
use

-------------------------------------------------------------------------------------------------------------------------------------
DDL

DDL is short name of Data Definition Language, which deals with database schemas and descriptions, of
how the data should reside in the database.

CREATE – to create database and its objects like (table, index, views, store procedure, function and
triggers)

ALTER – alters the structure of the existing database

DROP – delete objects from the database

TRUNCATE – remove all records from a table, including all spaces allocated for the records are removed

COMMENT – add comments to the data dictionary


RENAME – rename an object

DML

DML is short name of Data Manipulation Language which deals with data manipulation, and includes
most common SQL statements such SELECT, INSERT, UPDATE, DELETE etc, and it is used to store,
modify, retrieve, delete and update data in database.

SELECT – retrieve data from the a database

INSERT – insert data into a table

UPDATE – updates existing data within a table

DELETE – Delete all records from a database table

MERGE – UPSERT operation (insert or update)

CALL – call a PL/SQL or Java subprogram

EXPLAIN PLAN – interpretation of the data access path

LOCK TABLE – concurrency Control

DCL

DCL is short name of Data Control Language which includes commands such as GRANT, and mostly
concerned with rights, permissions and other controls of the database system.

GRANT – allow users access privileges to database


REVOKE – withdraw users access privileges given by using the GRANT command

TCL

TCL is short name of Transaction Control Language which deals with transaction within a database.

COMMIT – commits a Transaction

ROLLBACK – rollback a transaction in case of any error occurs

SAVEPOINT – to rollback the transaction making points within groups

SET TRANSACTION – specify characteristics for the transaction

You might also like