This lesson is for beginners who understand tables and rows but need a dependable way to read and change relational data. It connects SQL command families to the database state they affect, then shows how to test filters, handle NULL, protect writes, and reason about query order.
After completing it, you should be able to create a constrained table, retrieve grouped results, change rows inside a transaction, and explain why a query either includes or excludes a particular row.
A Database Management System (DBMS) is software used to define, create, store, organize, retrieve, update, and control access to data. It works as a controlled layer between users or applications and the actual database. Instead of every application directly managing files, storage formats, security, and recovery logic, the DBMS provides standard services for handling data safely and efficiently.
A DBMS keeps related data structured while coordinating concurrent access, validation, security, and recovery. Common database systems include MySQL, PostgreSQL, Oracle Database, SQL Server, SQLite, MongoDB, and IBM Db2.
| Term | Meaning | Example |
|---|---|---|
| Data | Raw facts that can be recorded and processed. | 101, "Amit", "CSE", 85 |
| Information | Processed data that has useful meaning. | Amit scored 85 marks in DBMS. |
| Database | An organized collection of related data with a specific purpose. | College database, bank database, hospital database. |
| DBMS | Software that manages the database and provides controlled access. | MySQL, PostgreSQL, Oracle, MongoDB. |
| Database System | The complete environment: database, DBMS software, users, applications, and hardware. | Online banking system with database server, DBMS, web app, and users. |
Use a DBMS when multiple users or applications need one governed source of data. It centralizes schemas, validation, access control, concurrent updates, querying, backup, and recovery; unmanaged application files leave those responsibilities scattered across programs.
| Function | Explanation |
|---|---|
| Data Definition | Allows creation of database structures such as tables, columns, relationships, indexes, and views. |
| Data Manipulation | Allows inserting, updating, deleting, and retrieving data. |
| Data Security | Controls which users can read, modify, or administer data. |
| Data Integrity | Maintains correctness using constraints such as primary key, foreign key, unique, and check constraints. |
| Concurrency Control | Allows many users to access the database at the same time without corrupting data. |
| Backup and Recovery | Restores the database after hardware failure, software failure, or transaction failure. |
| Data Independence | Allows database structure changes with minimal impact on application programs. |
A DBMS does not work alone. It is part of a complete environment where hardware, software, data, users, and procedures work together.
| User Type | Role |
|---|---|
| Database Administrator (DBA) | Manages database security, backup, performance, user permissions, and recovery. |
| Database Designer | Designs schemas, tables, relationships, constraints, and normalization structure. |
| Application Programmer | Writes application code that connects to the database and performs operations. |
| End User | Uses forms, reports, apps, or dashboards without directly knowing database internals. |
| Data Analyst | Runs queries and reports to convert stored data into useful business insights. |
DBMS architecture is commonly explained using three levels. This separation helps provide data abstraction and data independence.
| Level | Also Called | Description |
|---|---|---|
| External Level | View Level | Shows different users only the part of the database they need. Example: a student sees marks, while an admin sees full records. |
| Conceptual Level | Logical Level | Defines the complete logical structure of the database, including entities, attributes, relationships, and constraints. |
| Internal Level | Physical Level | Describes how data is actually stored using files, indexes, pages, records, and storage structures. |
A schema is the design or structure of a database. It describes tables, columns, data types, constraints, and relationships. An instance is the actual data stored in the database at a particular moment.
| Concept | Meaning | Example |
|---|---|---|
| Schema | Database structure that changes rarely. | Student(RollNo, Name, Course, Email) |
| Instance | Current data stored in the database. | Rows such as (101, "Asha", "BCA", "asha@example.com") |
A data model defines how data is represented, stored, related, and manipulated in a database. It gives a logical way to think about the structure of data.
| Data Model | Basic Idea | Example |
|---|---|---|
| Hierarchical Model | Data is organized like a tree with parent-child relationships. | One department has many employees. |
| Network Model | Data is organized like a graph and supports many-to-many relationships. | Many students can enroll in many courses. |
| Relational Model | Data is stored in tables with rows and columns. | Student, Course, Enrollment tables. |
| Object-Oriented Model | Data is stored as objects with attributes and methods. | Engineering and scientific applications. |
| NoSQL Model | Data may be stored as documents, key-value pairs, columns, or graphs. | MongoDB documents, Redis key-value data. |
DBMS provides languages or command groups to define, manipulate, control, and query data. In relational databases, these commands are usually part of SQL.
| Language | Purpose | Common Commands |
|---|---|---|
| DDL | Data Definition Language: defines database structure. | CREATE, ALTER, DROP, TRUNCATE |
| DML | Data Manipulation Language: changes data. | INSERT, UPDATE, DELETE |
| DQL | Data Query Language: retrieves data. | SELECT |
| DCL | Data Control Language: controls access permissions. | GRANT, REVOKE |
| TCL | Transaction Control Language: manages transactions. | COMMIT, ROLLBACK, SAVEPOINT |
The following example creates a simple student table, inserts records, and fetches students from the BCA course.
CREATE TABLE students (
roll_no INT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
course VARCHAR(50),
email VARCHAR(100) UNIQUE
);
INSERT INTO students (roll_no, name, course, email)
VALUES
(101, 'Asha', 'BCA', 'asha@example.com'),
(102, 'Rahul', 'BSc IT', 'rahul@example.com'),
(103, 'Neha', 'BCA', 'neha@example.com');
SELECT roll_no, name, email
FROM students
WHERE course = 'BCA';
Constraints are rules applied to database columns or tables to keep data correct and meaningful.
A transaction is a logical unit of work that contains one or more database operations. For example, transferring money from one bank account to another requires debiting one account and crediting another. Both operations must succeed together, or both must fail together.
| ACID Property | Meaning |
|---|---|
| Atomicity | A transaction is completed fully or not performed at all. |
| Consistency | A transaction changes the database from one valid state to another valid state. |
| Isolation | Concurrent transactions should not interfere with each other incorrectly. |
| Durability | Once committed, transaction results remain permanent even after failure. |
| Point | File System | DBMS |
|---|---|---|
| Data Redundancy | High, because data is often repeated in many files. | Lower, because data can be centralized and normalized. |
| Data Access | Requires custom programs for different reports. | Uses query languages like SQL for flexible access. |
| Security | Usually limited and application-specific. | Provides user accounts, roles, privileges, and views. |
| Concurrency | Difficult to manage safely. | Handled using locks, transactions, and isolation rules. |
| Recovery | Manual and difficult. | Supported using logs, checkpoints, backup, and recovery tools. |
CREATE TABLE lesson_what (
id INT PRIMARY KEY,
description VARCHAR(120),
amount DECIMAL(10,2),
status VARCHAR(20)
);
INSERT INTO lesson_what VALUES
(1, 'What normal case', 1000.00, 'active'),
(2, 'What boundary case', 0.00, 'review');
SELECT * FROM lesson_what;
BEGIN;
UPDATE lesson_what
SET status = 'checked'
WHERE amount >= 0;
SELECT status, COUNT(*) AS rows_seen
FROM lesson_what
GROUP BY status;
ROLLBACK;
-- Explanation: ROLLBACK lets you test the concept safely before committing changes.
Constraints protect individual rules such as primary keys, foreign keys, uniqueness, and valid values. Transactions protect multi-step changes so related updates succeed or fail together.
The schema is the design: table names, columns, data types, constraints, and relationships. The instance is the current data stored at a particular moment.
The three-level architecture separates external views, logical design, and physical storage. If an index is added or files are reorganized internally, applications should not need to change their SQL queries.
Explore 500+ free tutorials across 20+ languages and frameworks.