0% found this document useful (0 votes)
0 views

What is SQL

SQL (Structured Query Language) is essential for managing relational databases, allowing users to efficiently store, access, and manipulate data. It consists of five main components: DDL for database structure management, DML for data manipulation, DQL for data retrieval, DCL for user access control, and TCL for transaction management. SQL is widely used in various real-world applications, including data analysis, web development, e-commerce, banking, and social media management.

Uploaded by

ushaservices7
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)
0 views

What is SQL

SQL (Structured Query Language) is essential for managing relational databases, allowing users to efficiently store, access, and manipulate data. It consists of five main components: DDL for database structure management, DML for data manipulation, DQL for data retrieval, DCL for user access control, and TCL for transaction management. SQL is widely used in various real-world applications, including data analysis, web development, e-commerce, banking, and social media management.

Uploaded by

ushaservices7
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/ 4

What is SQL (Structured Query Language)?

SQL (Structured Query Language) is a powerful language used for managing and interacting
with relational databases. It is the standard language for accessing and manipulating data
stored in databases such as MySQL, PostgreSQL, SQL Server, SQLite, Oracle, and others.

Why is SQL Important?


SQL is widely used because it allows users to: ✅ Store large volumes of data efficiently.
✅ Access, modify, and manipulate data.
✅ Retrieve specific information from complex datasets.
✅ Ensure data integrity and security.

Main Components of SQL


SQL is divided into five main categories:

1. DDL (Data Definition Language)

Used to define, alter, or delete database structures (like tables, schemas, etc.).

• CREATE — Creates new database objects like tables, views, etc.


• ALTER — Modifies existing database structures.
• DROP — Deletes entire database objects.

Example:

CREATE TABLE Employees (


ID INT PRIMARY KEY,
Name VARCHAR(100),
Age INT,
Salary DECIMAL(10, 2)
);

2. DML (Data Manipulation Language)

Used to manipulate data within the database.

• INSERT — Adds new data into tables.


• UPDATE — Modifies existing data.
• DELETE — Removes data from tables.

Example:
INSERT INTO Employees (ID, Name, Age, Salary)
VALUES (1, 'Ayush', 25, 50000);

UPDATE Employees
SET Salary = 55000
WHERE ID = 1;

DELETE FROM Employees


WHERE ID = 1;

3. DQL (Data Query Language)

Used to retrieve data from databases.

• SELECT — Fetches data based on conditions.

Example:

SELECT Name, Salary


FROM Employees
WHERE Age > 30;

4. DCL (Data Control Language)

Used to control user access and permissions.

• GRANT — Gives user permissions.


• REVOKE — Removes permissions from users.

Example:

GRANT SELECT ON Employees TO 'admin';


REVOKE SELECT ON Employees FROM 'admin';

5. TCL (Transaction Control Language)

Used to manage transactions in SQL.

• COMMIT — Saves all changes made in the current transaction.


• ROLLBACK — Reverts changes since the last COMMIT.
• SAVEPOINT — Sets a point within a transaction to roll back to.

Example:

BEGIN;

UPDATE Employees SET Salary = 60000 WHERE ID = 1;


SAVEPOINT Salary_Update;

ROLLBACK TO Salary_Update;
COMMIT;

Key SQL Concepts and Functions


1. WHERE Clause – Filters records based on conditions.
2. ORDER BY Clause – Sorts records in ascending or descending order.
3. GROUP BY Clause – Groups rows that share similar values.
4. HAVING Clause – Filters grouped records.
5. JOIN – Combines rows from two or more tables.
6. INDEX – Improves query performance.
7. VIEWS – Virtual tables based on SQL queries.

Example SQL Query with Detailed Logic


Suppose you have an Employees table with the following data:

ID Name Age Department Salary


1 Ayush 25 IT 50000
2 Raj 30 HR 60000
3 Neha 27 IT 55000

Query: Show all employees from the IT department earning more than
50,000, sorted by salary in descending order.
SELECT Name, Salary
FROM Employees
WHERE Department = 'IT' AND Salary > 50000
ORDER BY Salary DESC;

Output:

Name Salary
Neha 55000

SQL Best Practices


✅ Use meaningful table and column names for clarity.
✅ Always use the WHERE clause with DELETE or UPDATE to avoid accidental data loss.
✅ Optimize performance with proper indexes.
✅ Use JOIN efficiently to combine data from multiple tables.
Real-World Applications of SQL
Data Analysis for insights and decision-making.
Web Development for managing user data.
E-commerce platforms for handling orders, inventory, and customer data.
Banking Systems for secure transaction management.
Social Media Platforms to manage profiles, posts, and interactions.

You might also like