A Relational Database Management System (RDBMS) stores data in related tables and provides a structured way to create, retrieve, update, secure, and maintain that data. These notes explain the core concepts with practical examples, making them useful for both exam answers and SQL practice.
DBMS: Software used to store, organize, retrieve, and manage data. It helps control access, reduce duplication, maintain consistency, and support multiple users.
RDBMS: A type of DBMS that stores data in tables, also called relations. Tables are connected through common columns, usually primary keys and foreign keys.
For example, a college database may store student details in one table, course details in another, and enrolment details in a third table. Instead of repeating the complete course information for every student, the tables are linked using keys.
| Feature | DBMS | RDBMS |
|---|---|---|
| Data organization | May use different data models | Uses related tables |
| Relationship between data | May be limited or application-managed | Maintained using keys and constraints |
| Integrity support | Depends on the system | Typically supports primary keys, foreign keys, checks, and transactions |
| Examples | File-based systems and non-relational databases can be managed by DBMS software | MySQL, PostgreSQL, Oracle Database, Microsoft SQL Server |
StudentName.The ANSI/SPARC three-schema architecture separates user views, logical design, and physical storage. Its main purpose is to reduce complexity and support data independence.
Constraints are rules that protect data quality. They stop invalid, duplicate, or inconsistent values from entering the database.
CREATE TABLE Department (
DepartmentID INT PRIMARY KEY,
DepartmentName VARCHAR(100) NOT NULL UNIQUE
);
CREATE TABLE Student (
StudentID INT PRIMARY KEY,
StudentName VARCHAR(100) NOT NULL,
DepartmentID INT,
CONSTRAINT fk_student_department
FOREIGN KEY (DepartmentID)
REFERENCES Department(DepartmentID)
);
In this example, StudentID is the primary key of the Student table. DepartmentID in the Student table is a foreign key, ensuring that a student refers only to an existing department.
SQL stands for Structured Query Language. It is the standard language used to work with relational databases. SQL syntax differs slightly between database systems, but its main concepts remain the same.
| Category | Purpose | Common Commands |
|---|---|---|
| DDL (Data Definition Language) |
Creates and changes database objects. | CREATE, ALTER, DROP, TRUNCATE, RENAME |
| DML (Data Manipulation Language) |
Adds, changes, or removes table data. | INSERT, UPDATE, DELETE |
| DQL (Data Query Language) |
Retrieves data. This is often treated as part of DML. | SELECT |
| DCL (Data Control Language) |
Controls database permissions. | GRANT, REVOKE |
| TCL (Transaction Control Language) |
Manages transaction boundaries. | COMMIT, ROLLBACK, SAVEPOINT |
| Command | Effect | Structure Remains? |
|---|---|---|
| DELETE | Removes selected rows; a WHERE clause can be used. | Yes |
| TRUNCATE | Removes all rows efficiently. Behaviour around logging, identity reset, and rollback varies by DBMS. | Yes |
| DROP | Removes the database object itself, such as a table. | No |
SELECT DepartmentID, COUNT(*) AS TotalStudents
FROM Student
WHERE DepartmentID IS NOT NULL
GROUP BY DepartmentID
HAVING COUNT(*) >= 10
ORDER BY TotalStudents DESC;
This query finds departments with at least ten students and displays them from the largest count to the smallest.
Although we write SELECT first, a simplified logical processing order is:
FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY
A transaction is a logical unit of work that should either complete correctly or leave the database unchanged. Transferring money between two accounts is a common example: the debit and credit operations must both succeed, or neither should take effect.
Normalization is a database-design process that organizes data to reduce unnecessary repetition and avoid update problems. The goal is not to create as many tables as possible; it is to store facts in the right place while keeping the design practical.
Suppose a table stores StudentID, StudentName, DepartmentID, DepartmentName. DepartmentName depends on DepartmentID, not directly on StudentID. To avoid repeated department names, separate the design into:
Student(StudentID, StudentName, DepartmentID)
Department(DepartmentID, DepartmentName)
The Entity-Relationship (ER) model is used before implementation to represent real-world data requirements visually. It identifies entities, their attributes, and the relationships between them.
A many-to-many relationship is usually implemented with a junction table. For example:
Student(StudentID, StudentName)
Course(CourseID, CourseName)
Enrollment(StudentID, CourseID, EnrolledOn)
Joins combine related data from two or more tables. They are essential because normalized databases store related facts in separate tables.
| Join Type | Result |
|---|---|
| INNER JOIN | Returns rows with matching values in both tables. |
| LEFT OUTER JOIN | Returns all rows from the left table and matched rows from the right table. |
| RIGHT OUTER JOIN | Returns all rows from the right table and matched rows from the left table. |
| FULL OUTER JOIN | Returns matched rows plus unmatched rows from both tables, where supported by the DBMS. |
| CROSS JOIN | Returns every possible combination of rows from two tables. |
| SELF JOIN | Joins a table with itself, often used for employee-manager relationships. |
SELECT s.StudentName, d.DepartmentName
FROM Student AS s
INNER JOIN Department AS d
ON s.DepartmentID = d.DepartmentID;
A schema is the database blueprint, while an instance is the actual data stored at a particular point in time.
A table has one primary-key constraint, but that primary key may be composite and contain multiple columns.
Normalization reduces duplicate data and helps prevent insertion, update, and deletion anomalies.
A foreign key connects related tables and helps maintain referential integrity by preventing invalid references.