Database Management System
Unit:1
Class 12 ┬╖Database Management System ┬╖ NEB Exam Preparation Guide
How to use this guide: Learn the definitions first, then study the tables and examples. Normalization and SQL are the most practical parts, so practice writing them by hand. Practice questions are at the end.
Table of Contents
- Basic Concepts: Data, Information, Data Processing
- File-Based System vs Database System
- Database and DBMS
- Database Terminology and Objects
- Keys
- Database Models
- Entity-Relationship (E-R) Diagram
- Normalization
- Centralized vs Distributed Database
- Data Dictionary, Integrity and Security
- Database Administrator (DBA)
- SQL
- Quick Revision Table
- Practice Questions
1. Basic Concepts: Data, Information, Data Processing
Data
Data means raw facts and figures (numbers, text, images, sounds) that have no clear meaning on their own.
Example: 101, Hari, Bharatpur
| Type | Meaning | Examples |
|---|---|---|
| Primary data | Collected first-hand for a specific purpose | Surveys, questionnaires, observations |
| Secondary data | Already collected by someone else | Census reports, sales reports, financial statements |
Data processing
Data processing is the series of steps that convert raw data into meaningful output (information): input тЖТ processing тЖТ output.
Information
Information is processed data that has meaning and is useful for decisions. It answers questions such as who, what, where, and when.
Example: "Hari lives in Bharatpur-11, Chitwan."
Difference between data and information
| Basis | Data | Information |
|---|---|---|
| Nature | Raw, unorganized facts | Processed, meaningful facts |
| Meaning | May have no clear meaning | Always has meaning |
| Use | Input to a system | Output of a system |
| Format | No fixed format | Presented as tables, charts, reports |
| Dependence | Independent | Depends on data |
| Example | 101, Hari, 85 | "Hari (Roll 101) scored 85 marks" |
2. File-Based System vs Database System
File-based (flat-file) system
Records are stored in separate files, either on paper or in computer files, and each application manages its own files.
Limitations of the file-based system
- Data redundancy: the same data is stored in many files
- Data inconsistency: copies of the same data may not match
- Program-data dependence: changing a file structure requires changing the program
- Poor data control: no central control over data
- Limited data sharing: each department keeps its own files
- Security problems: weak protection of data
- Incompatible file formats: files from different programs cannot be easily combined
- Fixed queries: only pre-written reports are possible
Comparison
| Basis | File-based system | Database system |
|---|---|---|
| Data storage | Separate files for each application | Central, integrated database |
| Redundancy | High | Low (controlled) |
| Consistency | Often inconsistent | Consistent |
| Data sharing | Difficult | Easy among many users |
| Security | Weak | Strong (user rights, passwords) |
| Backup and recovery | Little or no support | Built-in support |
| Searching | Slow, needs effort | Fast and easy |
| Maintenance | Difficult | Easier |
| Data independence | No | Yes |
3. Database and DBMS
Database
A database is an organized collection of related data stored so that it can be easily accessed, managed, and updated.
Database system
A database system is the combination of the database, the DBMS software, the application programs, and the users that work together to store and manage data.
DBMS
A Database Management System (DBMS) is software that lets users create, store, retrieve, update, and manage data in a database. It sits between the user and the database and controls all access to the data.
Examples: MySQL, Oracle, Microsoft Access, SQL Server, PostgreSQL, SQLite.
Why use a DBMS?
- Faster development of applications
- Data independence and efficient data access
- Uniform administration of data
- Better integrity and security
- Concurrent access by many users and recovery after crashes
- Easy-to-use query language (SQL)
Functions of a DBMS
- Create new tables and files
- Insert data
- Retrieve (view) data
- Update existing data
- Delete data
- Remove tables and files
Advantages of DBMS
- Reduced data redundancy
- Data sharing among users
- Improved data consistency and integrity
- Better data security
- Data independence
- Backup and recovery support
- Multiple user views
- Ability to answer complex queries
Disadvantages of DBMS
- Costly: software, hardware, and training cost money
- Complex: needs skilled people to design and manage
- Single point of failure risk: a fault can affect many users
- Regular backup needed to avoid data loss
- Needs updating as technology changes
4. Database Terminology and Objects
| Term | Meaning |
|---|---|
| Table (Relation) | Data arranged in rows and columns |
| Field (Attribute / Column) | One piece of information about an item, such as Name |
| Record (Tuple / Row) | A complete set of fields about one item, such as one student |
| Entity | A real-world thing about which data is stored (student, teacher, book) |
| Schema | The overall structure of a database: tables, fields, data types, relationships, and constraints |
| Instance | The actual data stored in the database at a particular moment |
| Domain | The set of allowed values for a field |
Example table: Student
| RollNo | Name | Address |
|---|---|---|
| 1 | Gita | Narayangarh |
| 2 | Sita | Gaindakot |
| 3 | Arjun | Bharatpur |
Here the table has 3 records, 3 fields, and RollNo can act as the primary key.
Database objects
| Object | Purpose |
|---|---|
| Table | Basic storage unit made of rows and columns |
| Query | Retrieves or modifies data based on conditions |
| Form | A screen used to enter, edit, and view records |
| Report | A formatted, printable output of data (view only, not editable) |
| View | A virtual table showing selected data from one or more tables |
| Index | Speeds up searching and sorting |
| Sequence | Generates automatic numbers (often for IDs) |
5. Keys
A key is a field (or group of fields) that helps identify records uniquely and link tables together.
| Key | Description |
|---|---|
| Primary key | Uniquely identifies each record. It cannot be duplicate or NULL. A table has only one primary key. |
| Candidate key | Any field (or group) that could serve as the primary key because it is unique |
| Alternate key | A candidate key that was not chosen as the primary key |
| Composite (compound) key | A key made of two or more fields together |
| Foreign key | A field in one table that refers to the primary key of another table, creating a link |
Example:
Student(RollNo, Email, Name)
- Candidate keys:
RollNo,Email - Primary key:
RollNo - Alternate key:
Email
In a Marks(StudentID, SubjectID, Marks) table, StudentID + SubjectID together form a composite key, and each of them is also a foreign key.
6. Database Models
A database model defines the logical structure of a database and how data is stored, connected, and accessed.
6.1 Hierarchical model
Data is arranged like an upside-down tree with parent and child records. Each child has only one parent.
College
/ | \
Science Humanities Management
/ | \
Physics Chemistry Biology
| Advantages | Disadvantages |
|---|---|
| Simple and easy to understand | Cannot represent many-to-many relationships |
| Fast searching when the parent is known | Same data may be repeated (redundancy) |
| Efficient for one-to-many relationships | Rigid; hard to change the structure |
| Old and rarely used now |
6.2 Network model
Records are connected like a graph. A child can have more than one parent.
Example: An employee works in two departments, so that record links to both.
| Advantages | Disadvantages |
|---|---|
| Supports many-to-many relationships | Complex structure that is difficult to design and manage |
| More flexible than hierarchical | Programs become complicated |
| Fast access using links (pointers) | Less secure because of widely shared links |
| Reduces redundancy | Changes in structure are difficult |
6.3 Relational model
Data is stored in tables (relations) made of rows and columns. Tables are connected using keys. This is the most widely used model today (MySQL, Oracle, SQL Server).
Example:
Student
| RollNo | Name |
|---|---|
| 1 | Hari |
| 2 | Sita |
Marks
| RollNo | Subject | Marks |
|---|---|---|
| 1 | Computer | 95 |
| 2 | Computer | 85 |
RollNo links the two tables.
| Advantages | Disadvantages |
|---|---|
| Simple, table-based and easy to understand | Needs more powerful hardware for large data |
| Low redundancy (with normalization) | Complex designs can need many tables and joins |
| Easy to apply integrity rules | Performance may drop with very complex queries |
| Flexible; SQL makes queries easy |
6.4 Object-oriented model
Data and its operations are stored together as objects (like objects in object-oriented programming). Supports inheritance and complex data such as images and multimedia.
| Advantages | Disadvantages |
|---|---|
| Handles complex data types well | Complex and has a steep learning curve |
| Supports inheritance and reuse | Lack of a universally accepted standard |
| Objects hold data and behavior together | Higher system overhead |
Model comparison
| Feature | Hierarchical | Network | Relational | Object-oriented |
|---|---|---|---|---|
| Structure | Tree | Graph | Tables | Objects |
| Parents per child | One | Many | Not applicable | Not applicable |
| Many-to-many | No | Yes | Yes | Yes |
| Popularity today | Low | Low | Very high | Moderate |
7. Entity-Relationship (E-R) Diagram
An E-R diagram is a graphical representation of the entities, their attributes, and the relationships in a database. It is used during database design.
Components
| Symbol | Represents |
|---|---|
| Rectangle | Entity (e.g., Student) |
| Ellipse (oval) | Attribute (e.g., Name) |
| Diamond | Relationship (e.g., Enrolls) |
| Line | Link connecting the components |
Types of relationships
| Type | Meaning | Examples |
|---|---|---|
| One-to-one (1:1) | One record of A relates to only one record of B | College тАУ Principal, Country тАУ President |
| One-to-many (1:M) | One record of A relates to many records of B | College тАУ Students, Bank тАУ Employees |
| Many-to-many (M:M) | Many records of A relate to many records of B | Teachers тАУ Students, Books тАУ Readers |
Simple text example:
[College] ----<has>---- [Principal] (1 : 1)
[College] ----<has>---- [Student] (1 : M)
[Teacher] ----<teaches>---- [Student] (M : M)
8. Normalization
Definition
Normalization is the process of organizing data in a database by splitting large tables into smaller, related tables to reduce redundancy and avoid problems when inserting, updating, or deleting data.
Note: Normalization reduces redundancy; it does not completely eliminate it, because keys must still be repeated to link tables.
Advantages
- Reduces data redundancy
- Improves consistency and integrity
- Makes table structure simpler and clearer
- Makes the database easier to maintain
Disadvantages
- Design becomes more complex
- More tables mean more joins, which can slow some queries
- Needs more processing and storage for large systems
Key terms for normalization
- Atomic value: a value that cannot be divided further (one value per cell)
- Functional dependency: field B depends on field A if knowing A tells you B (e.g.,
StudentID тЖТ Name) - Partial dependency: a non-key field depends on only part of a composite primary key
- Transitive dependency: a non-key field depends on another non-key field, not directly on the primary key
Normal forms
| Normal form | Rule |
|---|---|
| 1NF | Every field holds a single (atomic) value; no repeating groups |
| 2NF | Must be in 1NF and have no partial dependency |
| 3NF | Must be in 2NF and have no transitive dependency |
Worked example (1NF тЖТ 2NF тЖТ 3NF)
Un-normalized table: Result
| StudentID | StudentName | Subjects | Teacher | ExamName | FullMarks |
|---|---|---|---|---|---|
| 1 | Anil | Math, Science | Mr. Rai, Ms. Gurung | Terminal | 100 |
| 2 | Binita | Math | Mr. Rai | Final | 75 |
Problem: the Subjects and Teacher cells contain more than one value.
Step 1: First Normal Form (1NF)
Make each cell atomic by giving each subject its own row.
| StudentID | StudentName | Subject | Teacher | ExamName | FullMarks |
|---|---|---|---|---|---|
| 1 | Anil | Math | Mr. Rai | Terminal | 100 |
| 1 | Anil | Science | Ms. Gurung | Terminal | 100 |
| 2 | Binita | Math | Mr. Rai | Final | 75 |
Primary key (composite): StudentID + Subject
Step 2: Second Normal Form (2NF)
Partial dependencies found:
StudentNamedepends only onStudentIDTeacherdepends only onSubject
Fix: split into separate tables.
Student
| StudentID | StudentName | ExamName | FullMarks |
|---|---|---|---|
| 1 | Anil | Terminal | 100 |
| 2 | Binita | Final | 75 |
Subject
| Subject | Teacher |
|---|---|
| Math | Mr. Rai |
| Science | Ms. Gurung |
Enrollment
| StudentID | Subject |
|---|---|
| 1 | Math |
| 1 | Science |
| 2 | Math |
Step 3: Third Normal Form (3NF)
Transitive dependency found: in the Student table, FullMarks depends on ExamName, which is not the primary key (StudentID тЖТ ExamName тЖТ FullMarks).
Fix: move exam details to their own table.
Student
| StudentID | StudentName | ExamID |
|---|---|---|
| 1 | Anil | E1 |
| 2 | Binita | E2 |
Exam
| ExamID | ExamName | FullMarks |
|---|---|---|
| E1 | Terminal | 100 |
| E2 | Final | 75 |
Result: every non-key field now depends on the primary key of its own table, and the data is stored without repeated, mixed-up details.
9. Centralized vs Distributed Database
Centralized database
All data is stored at one central location (a single server). Users access it from different places.
| Advantages | Disadvantages |
|---|---|
| Easy to manage and maintain | If the server fails, all data may be unavailable |
| Consistent data and uniform standards | Heavy load on one server slows response |
| Better security control | Harder to serve very large or distant user groups |
| Lower cost |
Distributed database
Data is split or copied across several locations (sites) connected by a network, but users see it as a single database.
| Advantages | Disadvantages |
|---|---|
| More reliable: failure of one site does not stop everything | Complex to manage and administer |
| Faster local access and load sharing | Expensive to set up |
| Easy to expand by adding new sites | Higher security risk because data is spread out |
| Supports many users | Keeping all copies consistent is difficult |
Comparison
| Basis | Centralized | Distributed |
|---|---|---|
| Data location | One site | Many sites |
| Complexity | Simple | Complex |
| Cost | Lower | Higher |
| Reliability | Low (single point of failure) | High |
| Maintenance | Easier | Harder |
| Suitable for | Small organizations | Large, multi-location organizations |
| Load balancing | No | Yes |
| Network traffic | High towards one server | Spread across sites |
10. Data Dictionary, Integrity and Security
Data dictionary
A data dictionary is a store of metadata ("data about data"). It describes table names, field names, data types, sizes, keys, relationships, and user access rights. It is also called the system catalog.
Data integrity
Data integrity means the data in the database is accurate, valid, and consistent.
| Integrity type | Meaning |
|---|---|
| Domain integrity | Values in a field must be within the allowed range or type (e.g., age must be a number; marks 0тАУ100) |
| Entity integrity | Every record must be uniquely identifiable; primary key must be unique and not null |
| Referential integrity | A foreign key value must match an existing primary key value in the related table (or be null) |
Data security
Data security means protecting the database from unauthorized access, modification, loss, or destruction. It is done through passwords, user privileges, encryption, backups, and firewalls.
11. Database Administrator (DBA)
Definition
A Database Administrator (DBA) is the person responsible for the overall design, management, security, and performance of the database system in an organization.
Responsibilities
- Install, configure, and upgrade the DBMS
- Design and create the database structure
- Give and control user access rights
- Take backups and perform recovery after failure
- Monitor performance and fix problems
- Maintain security and integrity of data
- Train users on how to use the database
Qualities of a good DBA
- Strong knowledge of DBMS software (MySQL, Oracle, etc.)
- Knowledge of the operating system and networking
- Good database design and problem-solving skills
- Honesty and responsibility, since the DBA handles sensitive data
12. SQL (Structured Query Language)
Definition
SQL is the standard language used to create, manage, and query relational databases.
Features
- Easy, English-like commands
- Non-procedural: you say what you want, not how to get it
- Works on single records or sets of records
- Used to define tables, views, security, and transactions
- Supported by almost all relational DBMSs
Categories of SQL commands
| Category | Full form | Purpose | Commands |
|---|---|---|---|
| DDL | Data Definition Language | Define or change the structure of database objects | CREATE, ALTER, DROP, TRUNCATE, RENAME |
| DML | Data Manipulation Language | Work with the data inside tables | SELECT, INSERT, UPDATE, DELETE |
| DCL | Data Control Language | Control access and permissions | GRANT, REVOKE |
Note: In many textbooks, transaction commands
COMMITandROLLBACKare grouped under DCL. In standard SQL they belong to TCL (Transaction Control Language). Write them under DCL if your syllabus says so.
DDL commands
| Command | Use |
|---|---|
CREATE | Creates a database or table |
ALTER | Changes the structure of a table |
DROP | Deletes a database or table completely |
TRUNCATE | Removes all records but keeps the table structure |
RENAME | Renames an object |
DML commands
| Command | Use |
|---|---|
SELECT | Retrieves data |
INSERT | Adds new records |
UPDATE | Modifies existing records |
DELETE | Removes records |
SQL statements with examples
Create and delete a database
CREATE DATABASE School;
DROP DATABASE School;
Create a table
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
FName VARCHAR(50),
LName VARCHAR(50),
Address VARCHAR(100),
Class INT
);
Alter a table
-- Add a column
ALTER TABLE Students ADD Email VARCHAR(100);
-- Delete a column
ALTER TABLE Students DROP COLUMN Email;
-- Change a column's data type (MySQL syntax)
ALTER TABLE Students MODIFY COLUMN Class VARCHAR(10);
Delete a table
DROP TABLE Students;
Insert data
INSERT INTO Students (StudentID, FName, LName, Address, Class)
VALUES (101, 'Ram', 'Sharma', 'Pokhara', 7);
Select data
-- All columns
SELECT * FROM Students;
-- Specific columns
SELECT FName, LName FROM Students;
-- With a condition
SELECT * FROM Students WHERE Class = 7;
Update data
UPDATE Students
SET Address = 'Kathmandu'
WHERE StudentID = 101;
Delete data
DELETE FROM Students
WHERE StudentID = 101;
Warning: Always use
WHEREwithUPDATEandDELETE. Without it, all records are changed or removed.
Grant and revoke permissions
GRANT SELECT, INSERT ON Students TO 'user1';
REVOKE INSERT ON Students FROM 'user1';
Tip: In MySQL/XAMPP (phpMyAdmin), run these statements from the SQL tab.
13. Quick Revision Table
| Topic | Key point |
|---|---|
| Data | Raw facts without meaning |
| Information | Processed, meaningful data |
| Database | Organized collection of related data |
| DBMS | Software to create and manage a database |
| Primary key | Unique, non-null identifier of a record |
| Foreign key | Field linking to another table's primary key |
| Hierarchical model | Tree; one parent per child |
| Network model | Graph; many parents allowed |
| Relational model | Tables linked by keys; most popular |
| E-R diagram | Entities, attributes, relationships |
| 1NF | Atomic values |
| 2NF | 1NF + no partial dependency |
| 3NF | 2NF + no transitive dependency |
| Data dictionary | Metadata (data about data) |
| DBA | Manages and secures the database |
| DDL | CREATE, ALTER, DROP, TRUNCATE, RENAME |
| DML | SELECT, INSERT, UPDATE, DELETE |
| DCL | GRANT, REVOKE |
14. Practice Questions
Short-answer questions
- Differentiate between data and information.
- What is a database? What is a DBMS? Give two examples of DBMS software.
- Write any four limitations of the file-based system.
- Define the following: (a) data dictionary (b) primary key (c) relationship (d) DML (e) SQL (f) data integrity (g) DDL (h) data security (i) database system
- Differentiate between a primary key, a candidate key, and a foreign key.
- Write any four responsibilities of a DBA.
- What is a schema? How is it different from an instance?
Long-answer questions
- What is a database and DBMS? Write the advantages and disadvantages of DBMS.
- Explain the different database models with their advantages and disadvantages.
- Differentiate between centralized and distributed database systems.
- Who is a DBA? Explain the major responsibilities and qualities of a DBA.
- What is normalization? Explain 1NF, 2NF, and 3NF with examples.
- Explain the types of data integrity constraints.
- Draw an E-R diagram for a college and its students/teachers, and explain the types of relationships.
SQL practice
Given the table Students(StudentID, FName, LName, Address, Class), write SQL statements to:
- Create the table.
- Add a column
Phone. - Insert two records.
- Display all students of Class 10.
- Change the address of student 101 to
Chitwan. - Delete the record of student 102.
Fill in the blanks
- A key that cannot contain NULL values is the ______ key. (primary)
- In the ______ model, a child can have more than one parent. (network)
- A table in 2NF must not have ______ dependency. (partial)
- ______ is data about data. (Metadata)
- The SQL command used to remove all records but keep the table structure is ______. (TRUNCATE)
Prepared for NEB Class 12 Computer Science exam revision. Always cross-check key definitions with your prescribed textbook and your teacher's guidance.