πŸ—ƒοΈ πŸ” πŸ”‘ πŸ“Š
πŸ—„οΈ

SQL Full Notes

πŸ—ƒοΈ DBMS β€’ SQL β€’ Queries β€’ Database πŸ’»

πŸŽ“ BCA β€’ DATABASE MANAGEMENT β€’ SQL

πŸ—„οΈ 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.

πŸ’‘ Simple Meaning:

A DBMS helps users store and manage large amounts of data efficiently.

πŸ‘€
User

Gives request

πŸ’»
DBMS

Processes request

πŸ—„οΈ
Database

Stores data

⭐ Functions of DBMS

πŸ—ƒοΈ 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.

πŸ—„οΈ Database
β†’
πŸ“Š Tables
β†’
πŸ“ Rows
+
πŸ“Œ 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
πŸ“Œ Remember:

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
SELECT * FROM students;
πŸ’» Select Specific Columns
SELECT name, marks FROM students;
πŸ”Ž WHERE Example
SELECT * FROM students WHERE marks > 80;

βž• 7. INSERT Command

INSERT is used to add new records into a table.

πŸ’» INSERT Example
INSERT INTO students (name, course, marks) VALUES ('Riya', 'BCA', 85);
πŸ“Œ Remember:

INSERT adds a new record.

✏️ 8. UPDATE Command

UPDATE is used to modify existing records.

πŸ’» UPDATE Example
UPDATE students SET marks = 90 WHERE student_id = 101;
⚠️ Important:

Always use a suitable WHERE condition when updating specific records.

πŸ—‘οΈ 9. DELETE Command

DELETE is used to remove records from a table.

πŸ’» DELETE Example
DELETE FROM students WHERE student_id = 101;
⚠️ Important:

A 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.

πŸ‘¨β€πŸŽ“
Students

Student_ID

πŸ”—
JOIN

Common column

πŸ“š
Courses

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.

πŸ’» INNER JOIN Example
SELECT students.name, courses.course_name FROM students INNER JOIN courses ON students.course_id = courses.course_id;

πŸ“Š 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.

πŸ’» Example
SELECT AVG(marks) FROM students;

🧹 12. Normalization

Normalization is the process of organizing data to reduce redundancy and improve data consistency.

πŸ“Š Large Table
β†’
🧹 Normalize
β†’
πŸ—ƒοΈ Organized Tables

πŸ“š 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.

πŸ’» Transaction Example
START TRANSACTION; UPDATE accounts SET balance = balance - 500 WHERE id = 1; COMMIT;

πŸ“ SQL Quick Revision

🎯 BCA SQL Exam Checklist

Before your exam, make sure you can explain these topics and write basic SQL queries.

βœ… DBMS
βœ… Database
βœ… Tables
βœ… Keys
βœ… SQL
βœ… SELECT
βœ… INSERT
βœ… UPDATE
βœ… DELETE
βœ… JOIN
βœ… Normalization
βœ… Transactions