CREDENCE IT PROFESSIONAL
TRAINING INSTITUTE, PUNE
Table of Contents
SQL Commands are mainly categorized into five categories: ...................................................... 1
1. DDL – Data Definition Language ....................................................................................................... 1
2. DQL – Data Query Language ............................................................................................................ 2
3. DML – Data Manipulation Language ................................................................................................ 2
4. DCL – Data Control Language ........................................................................................................... 3
5. TCL – Transaction Control Language ................................................................................................. 3
SQL Commands are mainly categorized into five categories:
1. DDL – Data Definition Language
DDL commands are used to define or modify the structure of the database and its objects (like tables).
1. CREATE: Used to create a new table in the database.
Example:
CREATE TABLE Students (
ID INT,
Name VARCHAR(50),
Age INT
);
This creates a table called "Students" with three columns: ID, Name, and Age.
2. DROP: Used to delete a table from the database.
Example:
DROP TABLE Students;
Email: Info@credence.in Website: https://www.credence.in
Contacts: +91 8237916162, +91 7391053250, +91 9579064658, +91 9091929355
CREDENCE IT PROFESSIONAL
TRAINING INSTITUTE, PUNE
This deletes the "Students" table from the database.
3. ALTER: Used to modify an existing table, like adding or removing columns.
Example:
ALTER TABLE Students ADD Address VARCHAR(100);
This adds a new column called "Address" to the "Students" table.
4. TRUNCATE: Used to remove all records from a table, but keeps the structure.
Example:
TRUNCATE TABLE Students;
This removes all data from the "Students" table but keeps the table structure.
2. DQL – Data Query Language
DQL commands are used to query the database and retrieve data.
1. SELECT: Used to fetch data from the database.
Example:
SELECT Name, Age FROM Students WHERE Age > 18;
This retrieves the "Name" and "Age" of students who are older than 18.
3. DML – Data Manipulation Language
DML commands are used to manipulate the data inside tables.
1. INSERT: Used to insert new data into a table.
Example:
INSERT INTO Students (ID, Name, Age) VALUES (1, 'John', 20);
This adds a new record with ID=1, Name='John', and Age=20 to the "Students" table.
Email: Info@credence.in Website: https://www.credence.in
Contacts: +91 8237916162, +91 7391053250, +91 9579064658, +91 9091929355
CREDENCE IT PROFESSIONAL
TRAINING INSTITUTE, PUNE
2. UPDATE: Used to modify existing data in a table.
Example:
UPDATE Students SET Age = 21 WHERE ID = 1;
This updates the "Age" of the student with ID=1 to 21.
3. DELETE: Used to remove specific data from a table.
Example:
DELETE FROM Students WHERE ID = 1;
This removes the student with ID=1 from the "Students" table.
4. DCL – Data Control Language
DCL commands are used to control access to the data.
1. GRANT: Used to give permissions to users.
Example:
GRANT SELECT ON Students TO User1;
This gives "User1" permission to use the SELECT command on the "Students" table.
2. REVOKE: Used to take away permissions from users.
Example:
REVOKE SELECT ON Students FROM User1;
This removes the "SELECT" permission for "User1" on the "Students" table.
5. TCL – Transaction Control Language
TCL commands are used to manage transactions in the database.
1. COMMIT: Used to save changes made by DML commands permanently.
Example:
Email: Info@credence.in Website: https://www.credence.in
Contacts: +91 8237916162, +91 7391053250, +91 9579064658, +91 9091929355
CREDENCE IT PROFESSIONAL
TRAINING INSTITUTE, PUNE
COMMIT;
This saves all changes permanently.
2. ROLLBACK: Used to undo changes made by DML commands.
Example:
ROLLBACK;
This undoes any changes made since the last COMMIT.
3. SAVEPOINT: Used to set a point within a transaction to which you can ROLLBACK later.
Example:
SAVEPOINT Save1;
This creates a save point called "Save1".
Email: Info@credence.in Website: https://www.credence.in
Contacts: +91 8237916162, +91 7391053250, +91 9579064658, +91 9091929355