0% found this document useful (0 votes)
5 views6 pages

DDL,DML,DRL DAY -3

The document outlines the various languages of SQL, including DDL, DML, DQL, TCL, and DCL, along with their respective commands. It provides detailed syntax and examples for commands like CREATE, ALTER, INSERT, UPDATE, DELETE, and SELECT. Additionally, it highlights the differences between DELETE and TRUNCATE commands.

Uploaded by

krishnasain5359
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

DDL,DML,DRL DAY -3

The document outlines the various languages of SQL, including DDL, DML, DQL, TCL, and DCL, along with their respective commands. It provides detailed syntax and examples for commands like CREATE, ALTER, INSERT, UPDATE, DELETE, and SELECT. Additionally, it highlights the differences between DELETE and TRUNCATE commands.

Uploaded by

krishnasain5359
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

SUB - LANGUAGES OF SQL:

1) DDL (DATA DEFINITION LANGUAGE):

> CREATE, ALTER, RENAME, TRUNCATE, DROP

2) DML (DATA MANIPULATION LANGUAGE):

> INSERT, UPDATE, DELETE

3) DQL / DRL (DATA QUERY / DATA RETRIVE LANGUAGE):

> SELECT

4) TCL (TRANSACTION CONTROL LANGUAGE):

> COMMIT, ROLLBACK, SAVEPOINT

5) DCL (DATA CONTROL LANGUAGE):

> GRANT, REVOKE

1) DDL (DATA DEFINITION LANGUAGE):

> CREATE

> ALTER

> RENAME

> TRUNCATE

> DROP

1. CREATE: CREATE A NEW TABLE IN SSMS DB.

SYNTAX:

CREATE TABLE <TABLE NAME> (<COLUMN NAME1> <DATATYPE>[SIZE],


<COLUMN NAME 2> <DATATYPE>[SIZE],
....................................................................................

EX: CREATE TABLE Person (

PersonID INT ,
FirstName VARCHAR(50),

LastName VARCHAR(50),

BirthDate DATE,

Email VARCHAR(100)

);

2. ALTER:

IT IS USED TO MODIFY THE STRUCTURE OF A TABLE IN


DATABASE.THIS COMMAND IS HAVING THE FOLLOWING FOUR SUB
COMMANDS ARE

ii) ALTER - ADD: ADDING A NEW COLUMN TO AN EXISTING TABLE.

SYNTAX:

ALTER TABLE <TN> ADD <NEW COLUMN NAME> <DATATYPE>[SIZE];

EX: Alter Table Person Add Phonenum Bigint;

iv) ALTER - DROP: TO DROP AN EXISTING COLUMN FROM A TABLE.

SYNTAX:

ALTER TABLE <TN> DROP <COLUMN> <COLUMN NAME>;

EX: Alter Table Person Drop Column Email;

i) ALTER - MODIFY: TO CHANGE DATATYPE AND ALSO SIZE OF DATATYPE OF A


PARTICULAR COLUMN.

SYNTAX:
ALTER TABLE <TN> ALTER <COLUMN NAME> <NEW DATATYPE>[NEW SIZE];

EX:

Alter Table Person Alter Column Phonenum Varchar(10);

iii) ALTER - RENAME: TO CHANGE A COLUMN NAME IN A TABLE.

SYNTAX:

ALTER TABLE <TN> RENAME <COLUMN> <OLD TABLE NAME> TO <NEW TABLE
NAME>;
(OR)
ALTER TABLE <TN> RENAME <COLUMN> <OLD COLUMN NAME> TO <NEW
COLUMN NAME>;

EX: Exec Sp_rename 'person','people' ---run stored procedure

4. TRUNCATE: To Delete All Rows From A Table At A Time. By Using Truncate


Command, We Cannot Delete A Specific Row From A Table Because Truncate
Does Not Supports "Where Clause" Condition. Is Deleting Rows But Not Columns
Of A Table.

SYNTAX:

TRUNCATE TABLE <TABLE NAME>;

EX:

TRUNCATE TABLE PEOPLE;

5. DROP: To Drop A Table (I.E., Rows And Columns) From Database.

SYNTAX:

DROP TABLE <TABLE NAME>;

EX: DROP TABLE PEOPLE;

2) DML (DATA MANIPULATION LANGUAGE)


> INSERT

> UPDATE

> DELETE

1. INSERT: Inserting A New Row Data Into A Table.

SYNTAX1:

INSERT INTO <TN> VALUES (VALUE1, VALUE2,.................);

EX: Insert values into the Person table

INSERT INTO Person (PersonID, FirstName, LastName, BirthDate,

Email)

VALUES

(1, 'John', 'Doe', '1990-05-15', '[email protected]'),

(2, 'Jane', 'Smith', '1985-08-22', '[email protected]'),

(3, 'Bob', 'Johnson', '1978-11-10',

'[email protected]');

UPDATE: Updating All Rows Data At A Time In A Table (Or) Updating A


Single Row Data In A Table By Using "Where Clause"Condition.

SYNTAX:

UPDATE <TN> SET <COLUMN NAME1> = <VALUE1>,<COLUMN


NAME2>=<VALUE2>,...............[ WHERE <CONDITION> ];

EX1:

update people set phonenum = '12345678';

DELETE: To Delete All Rows From A Table At A Time (Or) To Delete A Specific Row
From A Table By Using "Where Clause" Condition.

SYNTAX:

DELETE FROM <TN> [WHERE <CONDITION>];

EX: delete from people where personid = 1;

DIFFERENCE BETWEEN DELETE & TRUNCATE COMMAND:

DELETE TRUNCATE

1. It Is A Dml Command.

2. It Can Delete A Specific Row From A Table

4. It Temporary Data Deletion

5. We Can Restore Deleted Data

By Using "Rollback" Command.

6. Execution Speed Is Slow (Deleting Rows In One By One Manner )

TRUNCATE COMMAND

1. It Is A Ddl Command.

2. It Cannot Delete A Specific Row From A Table.

3. It Does Not Supports "Where Clause" Condition.

4. It Is Permanent Data Deletion.

5. We Cannot Restore Deleted Data By Using "Rollback".

6. Execution Speed Is Fast

(Deleting Group Of Rows At A Time )

3) DQL / DRL (DATA QUERY LANGUAGE / DATA RETRIVE


LANGUAGE):

> SELECT
SELECT: TO RETRIEVE ALL ROWS FROM A TABLE AT A TIME (OR) TO
RETRIEVE A SPECIFIC ROW FROM A TABLE BY USING "WHERE CLAUSE"
CONDITION.

SYNTAX:

SELECT * FROM <TABLE NAME> [WHERE <CONDITION>];

Here, " * " IS REPRESENT ALL COLUMNS IN A TABLE.

EX: SELECT * FROM PERSON;

You might also like