Topics
Unit 3: Database Concepts and Structured Query Language
1. Introduction to Database
What is a Database?
A database is an organized collection of structured data stored and accessed electronically. It provides efficient storage, retrieval, and management of large amounts of data.
Key Characteristics of Database:
- Organized and structured data
- Persistent storage
- Quick and efficient data retrieval
- Data integrity and security
- Multi-user access control
Types of Database
| Type | Description |
|---|---|
| Relational Database | Uses tables with rows and columns, supports SQL queries |
| Hierarchical Database | Organizes data in a tree-like structure |
| Network Database | Allows multiple relationships between records |
2. SQL Basics
What is SQL?
SQL (Structured Query Language) is a standard language for managing relational databases. It allows users to create, retrieve, update, and delete data.
SQL Commands Categories
- DDL (Data Definition Language): CREATE, ALTER, DROP
- DML (Data Manipulation Language): INSERT, UPDATE, DELETE, SELECT
- DCL (Data Control Language): GRANT, REVOKE
- TCL (Transaction Control Language): COMMIT, ROLLBACK, SAVEPOINT
3. DDL Commands
CREATE TABLE
CREATE TABLE student (
RollNo INT PRIMARY KEY,
Name VARCHAR(50),
Age INT,
Marks FLOAT
);ALTER TABLE
ALTER TABLE student ADD COLUMN Email VARCHAR(50); ALTER TABLE student MODIFY COLUMN Marks DECIMAL(5,2); ALTER TABLE student DROP COLUMN Email;
DROP TABLE
DROP TABLE student; TRUNCATE TABLE student;
4. DML Commands
SELECT
SELECT * FROM student; SELECT Name, Marks FROM student; SELECT * FROM student WHERE Marks > 80;
INSERT
INSERT INTO student (RollNo, Name, Age, Marks) VALUES (101, 'Alice', 25, 85);
UPDATE
UPDATE student SET Marks = 90 WHERE RollNo = 101;
DELETE
DELETE FROM student WHERE RollNo = 101;
5. Querying Data
WHERE Clause
SELECT * FROM student WHERE Age > 20; SELECT * FROM student WHERE Name LIKE 'A%';
ORDER BY and GROUP BY
SELECT * FROM student ORDER BY Marks DESC; SELECT Age, COUNT(*) FROM student GROUP BY Age;
Aggregate Functions
| Function | Purpose |
|---|---|
| COUNT() | Count number of rows |
| SUM() | Sum of values |
| AVG() | Average of values |
| MAX() / MIN() | Maximum/Minimum value |
Related Resources
- 📹
SQL Tutorial Video
video
- 📖
Database Concepts
pdf
- ❓
Practice MCQs
quiz
- 📚
SQL Reference
resource
