SQL-Commands-A-Comprehensive-Overview
SQL-Commands-A-Comprehensive-Overview
Comprehensive Overview
This presentation provides a comprehensive overview of the core
SQL commands, covering Data Definition Language (DDL), Data
Manipulation Language (DML), Data Control Language (DCL),
Transaction Control Language (TCL), and Data Query Language
(DQL).
uc
by umesh chauhan
Data Definition Language (DDL): Defining
Your Database
CREATE ALTER DROP TRUNCATE
Creates new database Modifies existing Deletes database objects Removes all data from a
objects, including tables, database objects, such permanently from the table, but keeps the
views, indexes, and as adding or removing database, including table structure intact.
stored procedures. columns from a table. tables, views, indexes,
and stored procedures.
DDL Syntax and Examples
CREATE TABLE ALTER TABLE
CREATE TABLE customers ALTER TABLE customers
(customer_id INT PRIMARY ADD COLUMN phone
KEY, customer_name VARCHAR(20);
VARCHAR(255), email
VARCHAR(255));
Adds new rows to a table. Modifies existing rows in a table. Removes existing rows from a table.
DML Syntax and Examples
INSERT UPDATE
INSERT INTO customers UPDATE customers SET
(customer_name, email) email =
VALUES ('John Doe', '[email protected]'
'[email protected]'); WHERE customer_id = 1;
DELETE
DELETE FROM customers WHERE customer_id = 2;
Data Control Language (DCL): Managing
Permissions
GRANT REVOKE
Grants access privileges to database users. Revokes access privileges from database users.
Transaction Control
Language (TCL):
Managing Transactions
1 COMMIT 2 ROLLBACK
Saves all changes made Reverts all changes made
in a transaction in a transaction to their
permanently. original state.
3 SAVEPOINT
Creates a checkpoint within a transaction, allowing you to
rollback to that point if needed.
Data Query Language (DQL): Retrieving
Information
SELECT FROM WHERE GROUP BY
Specifies the columns to Specifies the table to Filters the data based on Groups rows with similar
retrieve from a table. retrieve data from. specific conditions. values in a column.
DQL Syntax and Examples
SELECT * FROM customers; SELECT customer_name, email FROM customers
WHERE customer_id = 1;
Retrieves all columns and rows from the customers table.
Retrieves customer name and email from the customers table
for customer with ID 1.