Introduction to SQL
• SQL: Structured Query Language
• Used to interact with relational databases
• Performs CRUD operations: Create, Read,
Update, Delete
Types of Databases
• Relational (SQL): Data stored in tables
• Non-relational (NoSQL): Data not stored in
tables
SQL Commands Categories
• DDL: create, alter, drop, rename, truncate
• DML: select, insert, update, delete
• DCL: grant, revoke
• DQL: select
• TCL: commit, rollback
Creating Databases & Tables
• CREATE DATABASE db_name;
• DROP DATABASE db_name;
• CREATE TABLE table_name (column_name
datatype constraint);
SQL Datatypes
• TINYINT, INT, VARCHAR, DATE, etc.
• Signed & Unsigned ranges for numeric types
Constraints in SQL
• NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN
KEY
• DEFAULT, CHECK
Keys in SQL
• Primary Key: Uniquely identifies each row
• Foreign Key: Refers to Primary Key in another
table
Basic Queries
• SELECT * FROM table_name;
• INSERT INTO table_name (cols) VALUES (vals);
• UPDATE table_name SET col = val WHERE
condition;
• DELETE FROM table_name WHERE condition;
Clauses in SQL
• WHERE: Filtering rows
• ORDER BY: Sort results
• LIMIT: Limit number of rows returned
Aggregate Functions
• COUNT(), SUM(), AVG(), MIN(), MAX()
• Often used with GROUP BY
GROUP BY and HAVING
• GROUP BY: Groups rows into summary rows
• HAVING: Filters after grouping
Joins in SQL
• INNER JOIN: Matching rows from both tables
• LEFT JOIN / RIGHT JOIN: All rows from one
table, matched from another
• FULL JOIN: All rows from both tables
• SELF JOIN: Join table with itself
Subqueries & Views
• Subquery: Nested SELECT inside WHERE or
FROM
• Views: Virtual table based on SQL query result
End of Presentation
• Thank you!