SQL- DDL, DML, DCL, DTL, DQL- SQL Commands With Examples

Digital Classes
2 min readJan 31, 2021

--

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:-

sql commands- pywix

Data Definition Language (DDL):-

DDL changes the structure of the table like creating a table, deleting a table, altering a table, etc.

  • 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:-

This statement is used to drop an existing table or a database. It is used to delete both the structure and record stored in the table or a database.

‘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:-

DML commands are used to modify the database. It is responsible for all form of changes in the database. commands that come under DML are:-

  • INSERT
  • UPDATE
  • DELETE

Read Complete Article click here

Originally published at https://pywix.blogspot.com.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response