0% found this document useful (0 votes)
8 views26 pages

Data Base Presentation.

The document provides an overview of SQL commands, categorizing them into Data Definition Language (DDL), Data Manipulation Language (DML), Data Query Language (DQL), Data Control Language (DCL), and Transaction Control Language (TCL). It includes syntax and examples for key commands such as CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT, GRANT, REVOKE, COMMIT, ROLLBACK, and SAVEPOINT. The document serves as a comprehensive guide for understanding and utilizing SQL commands in database management.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views26 pages

Data Base Presentation.

The document provides an overview of SQL commands, categorizing them into Data Definition Language (DDL), Data Manipulation Language (DML), Data Query Language (DQL), Data Control Language (DCL), and Transaction Control Language (TCL). It includes syntax and examples for key commands such as CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT, GRANT, REVOKE, COMMIT, ROLLBACK, and SAVEPOINT. The document serves as a comprehensive guide for understanding and utilizing SQL commands in database management.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

TITLE: SQL COMMANDS

NAME : UZAIR MEMON


. MANKASHY JADOON
COURSE : DATA BASE
DEPARTMENT : CYBER SECURITY
INTRODUCTION TO SQL COMMANDS

Definition: SQL commands are instructions used to communicate with a


database.
Categories of SQL Commands:
Data Definition Language (DDL)
Data Manipulation Language (DML)
Data Query Language (DQL)
Data Control Language (DCL)
Transaction Control Language (TCL)
DATA DEFINITION LANGUAGE (DDL)

• Purpose: Defines and manages all database objects.


• Key Commands:
• CREATE: Create new tables or databases.
• ALTER: Modify existing database objects.
• DROP: Delete tables or databases.
• TRUNCATE: Remove all records from a table without logging
individual row deletions.
CREATE COMMAND:

• SYNTAX:
• CREATE TABLE table_name (
• column1 datatype,
• column2 datatype,
• ...
• );
CREATE COMMAND:

• Example:
• CREATE TABLE employees (
• id INT PRIMARY KEY,
• first_name VARCHAR(50),
• last_name VARCHAR(50),
• hire_date DATE
• );
ALTER COMMAND

• SYNTAX:
• 1) Add a Column:
• ALTER TABLE table_name ADD column_name datatype;
• 2) Modify a Column:
• ALTER TABLE table_name MODIFY column_name new_datatype;
• 3) Drop a Column:
• ALTER TABLE table_name DROP COLUMN column_name;
ALTER COMMAND

EXAMPLE:
• ALTER TABLE employees ADD email VARCHAR(100);
DROP COMMAND

• SYNTAX:
• 1) Drop a Table
• DROP TABLE table_name;
• 2) Drop a Database
• DROP DATABASE database_name;
DROP COMMAND

• EXAMPLE:
• DROP TABLE employees;
TRUNCATE COMMAND

Purpose: Quickly remove all records from a table without


logging individual row deletions.

SYNTAX:
TRUNCATE TABLE table_name;

EXAMPLE:
TRUNCATE TABLE employees;
DATA MANIPULATION LANGUAGE (DML)

Purpose: Manipulates data within existing tables.


Key Commands:
INSERT: Add new records.
UPDATE: Modify existing records.
DELETE: Remove records.
INSERT COMMAND

SYNTAX:
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);

EXAMPLE:
INSERT INTO employees (first_name, last_name, hire_date)
VALUES (‘Uzair’, ‘Memon', '2023-01-15');
UPDATE COMMAND:

SYNTAX:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
EXAMPLE:
UPDATE employees
SET last_name = ‘Memon'
WHERE id = 1;
UPDATE COMMAND:

SYNTAX:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
EXAMPLE:
UPDATE employees
SET last_name = ‘Memon'
WHERE id = 014;
DELETE COMMAND:

SYNTAX:
DELETE FROM table_name
WHERE condition;

EXAMPLE:
DELETE FROM employees
WHERE id = 014;
DATA QUERY LANGUAGE (DQL)

Purpose: Retrieve data from the database.


Key Command:
SELECT: Fetch data from one or more tables.
SELECT COMMAND:

SYNTAX:
SELECT column1, column2, ...
FROM table_name
WHERE condition
ORDER BY column1 [ASC|DESC];
SELECT COMMAND:

EXAMPLE:
SELECT first_name, last_name
FROM employees
WHERE hire_date > '2022-01-01'
ORDER BY last_name ASC;
DATA CONTROL LANGUAGE (DCL)

Purpose: Control access to data in the database.


Key Commands:
GRANT: Give user access privileges.
REVOKE: Remove user access privileges
GRANT COMMAND:

SYNTAX:
GRANT privilege ON object TO user;

EXAMPLE:
GRANT SELECT ON employees TO user1;
REVOKE COMMAND:

SYNTAX:
REVOKE privilege ON object FROM user;
EXAMPLE:
REVOKE SELECT ON employees FROM user1;
TRANSACTION CONTROL LANGUAGE (TCL)

Purpose: Manage transactions in a database, ensuring data integrity.


Key Commands:
COMMIT: Save all changes made during the current transaction.
ROLLBACK: Undo changes made during the current transaction.
SAVEPOINT: Set a point within a transaction to which you can later roll back.
COMMIT COMMAND:

SYNTAX:
COMMIT;

EXAMPLE:
INSERT INTO employees (first_name, last_name) VALUES (‘Uzair',
‘Memon');
COMMIT;
ROLL BACK COMMAND:

SYNTAX:
ROLLBACK;
EXAMPLE:
UPDATE employees SET last_name = ‘Memon' WHERE id = 014;
ROLLBACK; -- (This will undo the last update)
SAVEPOINT COMMAND:

SYNTAX:
SAVEPOINT savepoint_name;
EXAMPLE:
SAVEPOINT sp1;
UPDATE employees SET last_name = ‘Memon' WHERE id = 014;
ROLLBACK TO sp1; -- (This will undo the last update but keep previous
changes)
PROMPT: OPEN THE FLOOR FOR ANY QUESTIONS OR
DISCUSSIONS.

THANK YOU!

You might also like