SQL stands for Structured Query Language. It is an international standard database query language introduced and developed by IBM in early 1970s. It was able to control relational database. SQL is not a complete programming language rather only used for communicating with database. SQL has several statement for data definition, data manipulation and data control generally known as DDL, DML and DCL respectively. A query is a request to a DBMS for the retrieval, modification, insertion and deletion of the data from database.
1) Data Definition Language (DDL)
DDL is used by database designer and programmer to specify the content and the structure of table. DDL is used to define the physical characteristics of records in a database table. It includes command than manipulate the structure of object such as table. Some DDL statements are: CREATE, DROP, ALTER
1.1 CREATE statement
In order to create a database we can use CREATE statement as follows:
CREATE DATABASE database_name;
Eg,
CREATE DATABASE student;
The above statement will create a database with the name student.
In order to create a database table we can use CREATE statement as follows:
CREATE TABLE table_name(col1 datatype, col2 datatype);
Eg,
CREATE TABLE student(SN Number, Fname Text);
The above statement will create a database table named student with two column SN and Fname. The number of column can be increased accordingly.
1.2 DROP statement
It is used to delete database or table from the SQL server.
DROP DATABASE database_name;
Eg,
DROP DATABASE student;
This statement will delete database named student from the SQL server.
DROP TABLE table_name;
Eg,
DROP TABLE student;
This statement will delete database table named student from the SQL server.
2) Data Manipulation Language (DML)
DML is related with manipulation of records such as retrieval, sorting, displaying and deleting records or data. It helps user to submit query and display report of the table. It provide technique for processing the database. It includes commands like SELECT, INSERT, DELETE and UPDATE to manipulate the information stored in the database.
2.1) SELECT statement
SELECT * FROM table_name;
Eg:
SELECT * FROM student;
This statement will select all the columns from the database table named student.
2.2) INSERT statement
INSERT INTO table_name(col1, col2...) VALUES (Value1, Value2...);
Eg,
INSERT INTO student(SN,Fname) VALUES (3,"Ram");
The above statement will insert 3 and Ram into the database table named student.
2.3) DELETE statement
DELETE FROM table_name WHERE condition;
Eg,
DELETE FROM student WHERE Fname = "Ram";
This statement will delete all the records from the student table where the Fname value is 'Ram'.
2.4) UPDATE statement
UPDATE table_name SET col1=value1, col2=value2, WHERE condition;
Eg,
UPDATE student SET SN=3, Fname = "Hari", WHERE Fname = "Ram";
This stament will update the update the table record whose fname is "Ram".
3) Data Control Language (DCL)
DCL provides additional feature for security of table and database. It includes commands for controlling data and access to the database. Some of the example of this command are GRANT, COMMIT etc.