SQL COMMANDS
What is SQL?
SQL (Structured Query Language) is a standard language used to manage and manipulate relational databases. It is used in database systems like:
-
MySQL
-
PostgreSQL
-
Oracle Database
-
Microsoft SQL Server
SQL allows users to create databases, insert data, update records, retrieve information, and control access.
🔹 Types of SQL Commands
SQL commands are divided into five main categories:
-
DDL – Data Definition Language
-
DML – Data Manipulation Language
-
DQL – Data Query Language
-
DCL – Data Control Language
-
TCL – Transaction Control Language
🔹 1. DDL (Data Definition Language)
DDL commands are used to define and manage the structure of database objects like tables.
✅ CREATE
Used to create new databases, tables, views, or other database objects.
✅ DROP
Used to permanently delete database objects such as tables or databases.
✅ ALTER
Used to modify the structure of an existing table (add, delete, or modify columns).
✅ TRUNCATE
Used to remove all records from a table quickly. It does not delete the table structure.
✅ RENAME
Used to change the name of a database object.
🔹 2. DML (Data Manipulation Language)
DML commands are used to manage the data inside tables.
✅ INSERT
Used to add new records into a table.
✅ UPDATE
Used to modify existing records in a table.
✅ DELETE
Used to remove specific records from a table.
🔹 3. DQL (Data Query Language)
DQL is used to retrieve data from the database.
✅ SELECT
Used to fetch data from one or more tables.
It can be combined with conditions, sorting, grouping, and joins.
🔹 4. DCL (Data Control Language)
DCL commands are related to permissions and access control.
✅ GRANT
Used to give users permission to access or modify database objects.
✅ REVOKE
Used to remove permissions from users.
🔹 5. TCL (Transaction Control Language)
TCL commands manage transactions in the database.
✅ COMMIT
Saves all changes made during the current transaction permanently.
✅ ROLLBACK
Undo changes made in the current transaction before they are saved.
✅ SAVEPOINT
Sets a point within a transaction to which you can later roll back.
🔹 Important SQL Clauses (Descriptions)
✅ WHERE
Used to filter records based on specific conditions.
✅ ORDER BY
Used to sort the result in ascending or descending order.
✅ GROUP BY
Used to group rows that have the same values in specified columns.
✅ HAVING
Used to filter grouped data.
✅ DISTINCT
Used to return only unique values.
Comments
Post a Comment