ποΈ SQL Full Notes
Learn DBMS basics, relational databases, tables, keys, SQL commands, joins, normalization and transactions step by step.
π SQL Topics
ποΈ 1. DBMS Basics
DBMS stands for Database Management System. It is software used to create, store, organize and manage data in databases.
A DBMS helps users store and manage large amounts of data efficiently.
Gives request
Processes request
Stores data
β Functions of DBMS
- ποΈ Data storage
- π Data retrieval
- π Data security
- π₯ Multi-user access
- πΎ Backup and recovery
- π Data management
ποΈ 2. Database & Relational Database
A database is an organized collection of related information that can be easily accessed and managed.
π Relational Database
A relational database stores data in tables made up of rows and columns.
π 3. Tables
A table stores data in rows and columns.
| Student_ID | Name | Course | Marks |
|---|---|---|---|
| 101 | Riya | BCA | 85 |
| 102 | Aman | BCA | 78 |
| 103 | Neha | BCA | 91 |
Row = Record
Column = Field / Attribute
π 4. Database Keys
Keys are used to identify records and establish relationships between tables.
π Primary Key
Uniquely identifies each record in a table.
π Foreign Key
Creates a relationship between two tables.
π Candidate Key
A field that can potentially become a primary key.
π§© Composite Key
A key made using two or more columns.
π» 5. SQL
SQL stands for Structured Query Language. It is used to communicate with relational databases.
π Major SQL Command Categories
ποΈ DDL
CREATE, ALTER, DROP, TRUNCATE
π DML
INSERT, UPDATE, DELETE
π DQL
SELECT
π DCL
GRANT, REVOKE
π TCL
COMMIT, ROLLBACK, SAVEPOINT
π 6. SELECT Command
SELECT is used to retrieve data from a table.
π» Select All Columnsβ 7. INSERT Command
INSERT is used to add new records into a table.
π» INSERT ExampleINSERT adds a new record.
βοΈ 8. UPDATE Command
UPDATE is used to modify existing records.
π» UPDATE ExampleAlways use a suitable WHERE condition when updating specific records.
ποΈ 9. DELETE Command
DELETE is used to remove records from a table.
π» DELETE ExampleA DELETE statement without a WHERE condition can remove all records.
π 10. SQL JOINs
JOINs are used to combine related data from two or more tables.
Student_ID
Common column
Course_ID
π΅ INNER JOIN
Returns matching records from both tables.
π’ LEFT JOIN
Returns all records from the left table and matching records from the right.
π£ RIGHT JOIN
Returns all records from the right table and matching records from the left.
π FULL OUTER JOIN
Returns matching and non-matching records.
π 11. Aggregate Functions
Aggregate functions perform calculations on a group of records.
π’ COUNT()
Counts records.
β SUM()
Calculates total.
π AVG()
Calculates average.
β¬οΈ MAX()
Finds maximum value.
β¬οΈ MIN()
Finds minimum value.
π§Ή 12. Normalization
Normalization is the process of organizing data to reduce redundancy and improve data consistency.
π Normal Forms
1οΈβ£ 1NF
Removes repeating groups and keeps values atomic.
2οΈβ£ 2NF
Meets 1NF and removes partial dependency.
3οΈβ£ 3NF
Meets 2NF and removes transitive dependency.
π 13. Database Transactions
A transaction is a sequence of database operations treated as a single logical unit.
π ACID Properties
π °οΈ Atomicity
A transaction is completed fully or not at all.
π ²οΈ Consistency
Database remains in a valid state.
π ΈοΈ Isolation
Transactions work independently from each other.
π ³οΈ Durability
Committed changes remain saved.
π SQL Quick Revision
- ποΈ DBMS β Manages databases.
- ποΈ Database β Organized collection of data.
- π Table β Stores data in rows and columns.
- π Primary Key β Uniquely identifies a record.
- π Foreign Key β Connects related tables.
- π SELECT β Retrieves data.
- β INSERT β Adds records.
- βοΈ UPDATE β Modifies records.
- ποΈ DELETE β Removes records.
- π JOIN β Combines related tables.
- π Aggregate Functions β Perform calculations.
- π§Ή Normalization β Reduces data redundancy.
- π Transactions β Manage database operations safely.
π― BCA SQL Exam Checklist
Before your exam, make sure you can explain these topics and write basic SQL queries.