5. Why SQL
Execute queries against a database
Retrieve data from a database
Insert records in a database
Update records in a database
Delete records from a database
Create new databases
Create new tables in a database
Create views in a database
6. Important SQL Commands
SELECT - extracts data from a database
UPDATE - updates data in a database
DELETE - deletes data from a database
INSERT INTO - inserts new data into a database
CREATE DATABASE - creates a new database
ALTER DATABASE - modifies a database
CREATE TABLE - creates a new table
ALTER TABLE - modifies a table
DROP TABLE - deletes a table
CREATE INDEX - creates an index (search key)
DROP INDEX - deletes an index
9. WHERE Clause
SELECT column1, column2, ...
FROM table_name
WHERE condition;
Example:
SELECT * FROM students
WHERE age='15';
10. Operators
= Equal
<> Not equal. Note: ( != )
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
BETWEEN Between an inclusive range
LIKE Search for a pattern
IN To specify multiple possible values for a column
11. AND, OR and NOT
AND
SELECT * FROM table_name
WHERE condition1 AND condition2 AND condition3;
OR
SELECT * FROM table_name
WHERE condition1 OR condition2 OR condition3 ;
NOT
SELECT * FROM table_name
WHERE NOT condition;
12. ORDER BY
SELECT column1, column2, ...
FROM table_name
ORDER BY column ASC/DESC;
Example:
SELECT * FROM students ORDER BY id;
SELECT * FROM students ORDER BY id ASC;
SELECT * FROM students ORDER BY id DESC;