SQL stands for Structured Query Language. It’s a special programming language used to manage and interact with relational databases. In simple terms, it allows you to store, retrieve, update, and delete data in databases.
Here’s a breakdown:
-
Databases and Tables
- A database is like a digital filing cabinet.
- Inside a database, information is stored in tables, which are like spreadsheets with rows (records) and columns (fields).
-
Core Functions of SQL SQL is mainly used for four things, often called CRUD operations:
- C – Create: Add new data or tables (
INSERT) - R – Read: Retrieve data (
SELECT) - U – Update: Modify existing data (
UPDATE) - D – Delete: Remove data (
DELETE)
- C – Create: Add new data or tables (
-
Other Uses SQL can also:
- Define database structure (
CREATE TABLE,ALTER TABLE) - Control access to data (
GRANT,REVOKE) - Query multiple tables together (
JOIN) - Perform calculations and filtering (
WHERE,GROUP BY,ORDER BY)
- Define database structure (
Example:
-- Create a table
CREATE TABLE Students (
ID INT PRIMARY KEY,
Name VARCHAR(50),
Age INT
);
-- Insert data
INSERT INTO Students (ID, Name, Age) VALUES (1, 'Alice', 16);
-- Retrieve data
SELECT * FROM Students;
-- Update data
UPDATE Students SET Age = 17 WHERE ID = 1;
-- Delete data
DELETE FROM Students WHERE ID = 1;Think of SQL as the language you speak to a database to tell it what you want it to do.