1. What is SQL
What is SQL?
SQL (Structured Query Language) is a standard language used for managing and manipulating relational databases. It allows users to store, retrieve, update, and delete data, as well as define and control database structures.
What is SQL Used For?
-
Data Retrieval – Query databases to fetch specific records using
SELECT.
SELECT name, age FROM users WHERE age > 25; -
Data Insertion – Add new records to a table using
INSERT.
INSERT INTO users (name, age) VALUES ('John Doe', 30); -
Data Modification – Update existing records using
UPDATE.
UPDATE users SET age = 35 WHERE name = 'John Doe'; -
Data Deletion – Remove records using
DELETE.
DELETE FROM users WHERE age < 18; -
Schema Definition – Create and modify database structures (
CREATE,ALTER,DROP).
CREATE TABLE employees (id INT PRIMARY KEY, name VARCHAR(100)); -
Data Security & Access Control – Manage user permissions with
GRANTandREVOKE.
GRANT SELECT ON users TO admin; -
Transactions & Concurrency Control – Ensure database consistency using transactions (
BEGIN,COMMIT,ROLLBACK).
BEGIN; UPDATE accounts SET balance = balance - 100 WHERE id = 1; UPDATE accounts SET balance = balance + 100 WHERE id = 2; COMMIT;
Types of SQL Commands
SQL is categorized into different groups based on its purpose:
- Data Definition Language (DDL) – Defines database structure.
-
CREATE,ALTER,DROP,TRUNCATE -
Data Manipulation Language (DML) – Works with data.
-
SELECT,INSERT,UPDATE,DELETE -
Data Control Language (DCL) – Manages user permissions.
-
GRANT,REVOKE -
Transaction Control Language (TCL) – Manages transactions.
COMMIT,ROLLBACK,SAVEPOINT
Why Use SQL?
- Standardized – Used in almost all relational database systems (MySQL, PostgreSQL, SQL Server, Oracle, SQLite).
- Efficient – Optimized for handling large amounts of structured data.
- Scalable – Works for small applications to enterprise-level systems.
- Essential for Data Management – Used in software development, analytics, business intelligence, and more.