SQL Basics - Extended
SQL Basics
SQL (Structured Query Language) is used to manage and manipulate relational databases. It allows
users to create, read, update, and delete data from databases.
1. SELECT Statement:
Used to retrieve data from one or more tables.
Example: SELECT * FROM customers;
2. WHERE Clause:
Filters records based on conditions.
Example: SELECT * FROM customers WHERE age > 30;
3. INSERT INTO Statement:
Adds new records to a table.
Example: INSERT INTO customers (name, age) VALUES ('John', 28);
4. UPDATE Statement:
Modifies existing data.
Example: UPDATE customers SET age = 29 WHERE name = 'John';
5. DELETE Statement:
Removes records.
Example: DELETE FROM customers WHERE name = 'John';
6. ORDER BY Clause:
Sorts the results.
Example: SELECT * FROM customers ORDER BY age DESC;
7. GROUP BY Clause:
Groups rows that have the same values.
Example: SELECT city, COUNT(*) FROM customers GROUP BY city;
8. Aggregates:
Functions like COUNT, SUM, AVG, MAX, MIN.
Example: SELECT AVG(age) FROM customers;
9. Aliases:
Gives temporary names to tables or columns.
Example: SELECT name AS customer_name FROM customers;
10. SQL Constraints:
Rules enforced on data: PRIMARY KEY, FOREIGN KEY, NOT NULL, UNIQUE, CHECK.