SQL- DDL, DML, DCL, DTL, DQL- SQL Commands With Examples
SQL- DDL, DML, DCL, DTL, DQL- SQL Commands With Examples
SQL, Structured Query Language, is a programming language designed to manage data stored in relational databases.
SQL Commands:-
SQL commands are instructions. It is used to communicate with the database.
Types of SQL Commands:-

Data Definition Language (DDL):-
- CREATE
- ALTER
- DROP
- TRUNCATE
CREATE:-
This statement is used to create a table or a database.
‘CREATE DATABASE’ Statement:- this statement is used to create a database.
Syntax:-
CREATE DATABASE DatabaseName;
Example:-
CREATE DATABASE School;
‘CREATE TABLE’ Statement:-This statement is used to create a table.
Syntax:-
CREATE TABLE TableName (
Column1 datatype,Column2 datatype,
….
ColumnN datatype
);
Example:-
Tid INT NOT NULL AUTO_INCREMENT,
Tname VARCHAR(255),
Tmob VARCHAR(255),
Address VARCHAR(255),
City VARCHAR(255),
Country VARCHAR(255),
PRIMARY KEY(Tid)
);
DROP:-
‘DROP DATABASE’ Statement:-This statement is used to drop an existing database.
Syntax:-
DROP DATABASE DatabaseName;
Example:-
DROP DATABASE School;
‘DROP TABLE’ Statement:-This statement is used to drop an existing table.
Syntax:-
DROP TABLE TableName;
Example:-
DROP Table Teacher_Info;
TRUNCATE:-
It is used to delete all the rows from the table and free the space containing the table( it also deleted the index file of that table).
Syntax:-
TRUNCATE TABLE TableName;
Example:-
TRUNCATE Table Teacher_Info;
ALTER:-
This command is used to delete, modify or add constraints or columns in an existing table.
ADD/DROP COLUMN:-we can use the ALTER TABLE statement with ADD/DROP Column command according to our need.
Syntax:-
ALTER TABLE TableName ADD ColumnName Datatype;
Example:-
ALTER TABLE Teacher_Info ADD Salary varchar(255);
Syntax:-
ALTER TABLE TableName DROP COLUMN ColumnName;
ALTER TABLE Statement with ALTER COLUMN:-This statement is used to change the data type of an existing column in a table.
Syntax:-
ALTER TABLE TableName MODIFY COLUMN ColumnName Datatype;
Example:-
ALTER TABLE Teacher_Info MODIFY COLUMN salary INT;
Data Manipulation Language:-
- INSERT
- UPDATE
- DELETE
Read Complete Article click here
Originally published at https://pywix.blogspot.com.