SQL is a standard language for storing, manipulating and retrieving data in databases.
It is used to communicate with a relational database management system.
What is SQL?
- SQL stands for Structured Query Language.
- SQL used for accessing and manipulating databases.
- SQL became a standard of the American National Standards Institute (ANSI) in 1986, and of the International Organization for Standardization (ISO) in 1987.
- SQL is just a query language, it is not a database.
- To perform SQL queries, you need to install any database, for example, Oracle, MySQL, MongoDB, PostGre SQL, SQL Server, DB2 etc.
- SQL is used to perform C.R.U.D (Create, Retrieve, Update & Delete) operations on relational databases.
- SQL can also perform administrative tasks on the database such as database security, backup, user management etc.
What SQL can do?
- SQL can execute queries
- Insert records in a database
- Delete records from a database
- Retrieve data from a database
- Update records in a database
- Create new databases
- Create new tables in a database
- Create stored procedures in a database
- Create views in a database
- SQL can set permissions on tables, procedures, and views.
- It allows users to describe data.
- Allows embedding within other languages using SQL modules, libraries & pre-compilers.
What Is ANSI SQL?
The American National Standards Institute (ANSI) is an organization that approves certain standards in many different industries.
SQL is the standard language in relational database communication, originally approved in 1986 based on IBM’s implementation. In 1987, the ANSI SQL standard was accepted as the international standard by the International Standards Organization (ISO).
The standard was revised again in 1992 (SQL-92) and once again in 1999 (SQL-99).
The newest standard is now called SQL-2016, which was officially adopted in December 2016. It is the eighth revision of the ISO (1987) and ANSI (1986) standard for the SQL database query language.
Although SQL is an ANSI/ISO standard, there are different versions of the SQL language.
Types of SQL Commands
SQL to perform various functions. These functions include building database objects, manipulating objects, populating database tables with data, updating existing data in tables, deleting data, performing database queries, controlling database access, and overall database administration.
The main categories are –
- Data Definition Language (DDL)
- Data Manipulation Language (DML)
- Data Query Language (DQL)
- Data Control Language (DCL)
- Data administration commands
- Transactional control commands
Data Definition Language (DDL)
DDL is the part of SQL that enables a database user to create and restructure database objects, such as the creation or the deletion of a table.
Some of the most fundamental DDL commands –
- CREATE TABLE
- ALTER TABLE
- DROP TABLE
- CREATE INDEX
- ALTER INDEX
- DROP INDEX
- CREATE VIEW
- DROP VIEW
Data Manipulation Language (DML)
DML is used to manipulate data within objects of a relational database.
The three basic DML commands are –
Data Query Language (DQL)
DQL is used to fetch the information from the database which is already stored there.
The base command is –
Data Control Language (DCL)
Data control commands in SQL enable you to control access to data within the database.
Some data control commands are as follows –
- ALTER PASSWORD
- CREATE SYNONYM
Data administration commands
Data administration commands enable the user to perform audits and perform analyses on operations within the database.
Two general data administration commands are as follows –
- START AUDIT
- STOP AUDIT
Transactional control commands
These commands enable the user to manage database transactions.
- COMMIT—Saves database transactions
- ROLLBACK—Undoes database transactions
- SAVEPOINT—Creates points within groups of transactions in which to ROLLBACK
- SET TRANSACTION—Places a name on a transaction
What is a Query?
A Query is a set of instruction given to the database management system, which tells RDBMS what information you would like to get from the database.
For e.g. to fetch the employee name from the database table EMPLOYEE, we write the SQL Query like this: