Posted by : Akshay Patil
Tuesday, 14 April 2015
SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving data stored in relational database.
SQL is the standard language for Relation Database System. All relational database management systems like MySQL, MS Access, Oracle, Sybase, Informix, postgres and SQL Server use SQL as standard database language.
Initially, It was named as SEQUEL(Structured English Query Language) as it is very familiar with English language that is Human readable and understandable language which is used to perform interaction with database.SEQUEL later became SQL.Why SQL?
SQL allows to perform various operations like :- Execute queries against a database
- Retrieve data from a database
- Insert records in a database
- Update records in a database
- Delete records from a database
- Create new databases
- Create new tables in a database
- Create stored procedures in a database
- Create views in a database
- Set permissions on tables, procedures, and views
Types of SQL commands :
SQL provides 4 types of SQL commands or statements as given below :
DDL
Data Definition Language (DDL) statements are used to define the database structure or schema.
Some examples:
CREATE - to create objects like Table,Views,Sequences,Indexes,Synonyms etc. in the database
CREATE - to create objects like Table,Views,Sequences,Indexes,Synonyms etc. in the database
ALTER - alters the structure of the database
DROP - delete objects like Table,Views,Sequences,Indexes,Synonyms etc. 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
Data Manipulation Language (DML) statements are used for accessing and managing data within relational database tables.
Some examples:
SELECT - retrieve data from the a database tables
INSERT - insert data into a table
UPDATE - updates existing data within a table
DELETE - deletes specific or all records from a table, the space for the records remain
MERGE - UPSERT operation (insert or update)
CALL - call a PL/SQL or Java subprogram
EXPLAIN PLAN - explain access path to data
LOCK TABLE - control concurrency
Data Manipulation Language (DML) statements are used for accessing and managing data within relational database tables.
Some examples:
SELECT - retrieve data from the a database tables
INSERT - insert data into a table
UPDATE - updates existing data within a table
DELETE - deletes specific or all records from a table, the space for the records remain
MERGE - UPSERT operation (insert or update)
CALL - call a PL/SQL or Java subprogram
EXPLAIN PLAN - explain access path to data
LOCK TABLE - control concurrency
DCL
Data Control Language (DCL) statements are used to control privileges in database.
To perform any operation in database such as creating tables,views or perform insert,delete to table we need privileges.
Some examples:
GRANT - gives user's access privileges to database
REVOKE - withdraw access privileges given with the GRANT command
The operations for which privileges may be granted to or revoked from a user or role may include CONNECT, SELECT, INSERT, UPDATE, DELETE, EXECUTE, and USAGE.
Data Control Language (DCL) statements are used to control privileges in database.
To perform any operation in database such as creating tables,views or perform insert,delete to table we need privileges.
Some examples:
GRANT - gives user's access privileges to database
REVOKE - withdraw access privileges given with the GRANT command
The operations for which privileges may be granted to or revoked from a user or role may include CONNECT, SELECT, INSERT, UPDATE, DELETE, EXECUTE, and USAGE.
In the Oracle database, executing a DCL command issues an implicit commit. Hence you cannot roll back the command.
TCL
Transaction Control Language (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 or return
ROLLBACK - restore database to original since the last COMMIT
SET TRANSACTION - Change transaction options like isolation level and what rollback segment to use
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 or return
ROLLBACK - restore database to original since the last COMMIT
SET TRANSACTION - Change transaction options like isolation level and what rollback segment to use