Chapter 08 - Database Concepts

CBSE Class 12 Computer Science

8.1 Introduction

What is Data?

Data refers to raw facts and figures such as numbers, text, images, etc., which are collected for processing.

What is a Database?

A database is an organized collection of related data stored in a structured way so that it can be:

  • Easily accessed
  • Efficiently managed
  • Quickly updated

📌 Example: A school database storing student details like roll number, name, class, and marks.


Need for Databases

  • Large volume of data
  • Faster searching and retrieval
  • Reduced duplication
  • Data security and integrity
  • Multi-user access

8.2 File System

What is a File System?

A file system stores data in separate files, where each file is independent of others.

📌 Example:

  • students.txt
  • marks.txt
  • fees.txt

Limitations of File System (Very Important)

Limitation Explanation
Data Redundancy Same data stored in multiple files
Data Inconsistency Different values of same data
Data Isolation Difficult to retrieve combined data
Security Issues Poor access control
No Integrity No rules to ensure correctness
Difficult Sharing Multi-user access is hard

📌 Because of these problems, DBMS was introduced.


8.3 Database Management System (DBMS)

What is DBMS?

A Database Management System (DBMS) is software that allows users to:

  • Create databases
  • Store data
  • Retrieve data
  • Update data
  • Control access

📌 Examples:

  • MySQL
  • Oracle
  • MS Access
  • PostgreSQL

Advantages of DBMS

Advantage Description
Reduced redundancy Single copy of data
Improved consistency Same data everywhere
Data security Authorization & access control
Data integrity Valid data ensured
Backup & recovery Protection against failure
Concurrent access Multiple users supported

DBMS vs File System (VERY IMPORTANT)

File System DBMS
High redundancy Low redundancy
Poor security Strong security
No integrity Integrity constraints
Difficult access Easy querying
Manual backup Automatic backup

8.4 Relational Data Model

What is Relational Model?

The relational data model organizes data into tables, also called relations.


Components of Relational Model

🔹 Table (Relation)

A table consists of:

  • Rows (Tuples) → Records
  • Columns (Attributes) → Fields

Example table: STUDENT

RollNo Name Class Marks
101 Amit XII 90
102 Ravi XII 85

Terminology (Exam Favourite)

Term Meaning
Relation Table
Tuple Row
Attribute Column
Degree Number of columns
Cardinality Number of rows
Domain Set of allowed values

Advantages of Relational Model

  • Simple structure
  • Easy to understand
  • Powerful querying (SQL)
  • Reduced data duplication

8.5 Keys in a Relational Database

What is a Key?

A key is an attribute (or combination of attributes) used to uniquely identify a record in a table.


Types of Keys (VERY IMPORTANT)


🔹 1️⃣ Primary Key

  • Uniquely identifies each record
  • Cannot be NULL
  • Only one per table

📌 Example:

RollNo → Primary Key

🔹 2️⃣ Candidate Key

  • Attributes that can act as primary key
  • One of them is chosen as primary key

📌 Example:

  • RollNo
  • AadhaarNo

🔹 3️⃣ Alternate Key

  • Candidate keys not selected as primary key

📌 Example:

  • AadhaarNo (if RollNo is primary key)

🔹 4️⃣ Foreign Key

  • Attribute that refers to primary key of another table
  • Used to establish relationship

📌 Example:

StudentID in FEES table → Foreign Key

🔹 5️⃣ Composite Key

  • Combination of two or more attributes
  • Used when single attribute is not enough

📌 Example:

(OrderID, ProductID)

🔹 6️⃣ Super Key

  • Set of attributes that uniquely identify a record
  • May contain extra attributes

📝 NCERT EXAM SUMMARY (Must Memorize)

  • Database = organized data
  • File system has many limitations
  • DBMS overcomes file system problems
  • Relational model uses tables
  • Tuple = row, Attribute = column
  • Primary key is unique and not null
  • Foreign key links two tables
  • Candidate → possible PK
  • Alternate → unused candidate key

Short Answer Questions & Answers

Q1. What is a database?

Answer: A database is an organized collection of related data stored in a structured manner so that it can be easily accessed, managed, and updated.

Q2. Why is a database preferred over traditional file systems?

Answer: A database reduces data redundancy, improves data consistency, provides better security, and supports multi-user access, which is difficult in file systems.

Q3. What is data redundancy?

Answer: Data redundancy refers to unnecessary duplication of data at multiple places, which may lead to inconsistency and wastage of storage space.

Q4. Define DBMS. Give one example.

Answer: A Database Management System (DBMS) is software that helps users create, store, retrieve, and manage databases. Example: MySQL.

Q5. What is data inconsistency?

Answer: Data inconsistency occurs when different versions of the same data exist at different locations due to lack of centralized control.

Q6. What is the relational data model?

Answer: The relational data model organizes data into tables (relations) consisting of rows (tuples) and columns (attributes).

Q7. What is a tuple and an attribute in a table?

Answer:

  • Tuple: A row in a table representing a record
  • Attribute: A column in a table representing a field

Q8. Define primary key.

Answer: A primary key is an attribute that uniquely identifies each record in a table and cannot have NULL values.

Q9. What is a foreign key?

Answer: A foreign key is an attribute in one table that refers to the primary key of another table, used to establish a relationship between tables.

Q10. Differentiate between candidate key and alternate key.

Answer:

  • Candidate Key: Attributes that can uniquely identify records
  • Alternate Key: Candidate keys not chosen as the primary key

Q11. A school stores student data separately in different files for admission, exams, and fees. What problem may arise and how can DBMS solve it?

Answer: This can cause data redundancy and inconsistency. A DBMS stores data centrally, ensuring single-copy storage and consistent data access.

Q12. In a hospital database, each patient is given a unique Patient ID. Which key should be used and why?

Answer: Primary Key should be used because it uniquely identifies each patient and prevents duplicate records.

Q13. An online shopping website stores order details and customer details in separate tables. How are these tables linked?

Answer: The tables are linked using a foreign key, such as CustomerID, which connects orders to the respective customer.

Q14. A library database allows multiple users to search books at the same time without conflict. Which DBMS feature supports this?

Answer: Concurrent access is a DBMS feature that allows multiple users to access the database simultaneously without data inconsistency.

Q15. A college database uses a combination of Roll Number and Subject Code to uniquely identify marks. What type of key is this?

Answer: This is a composite key, as it uses more than one attribute to uniquely identify a record.