Database Concepts
Overview
This chapter explains why organisations move from keeping data in separate files to using a database. It lists the limitations of a file system, introduces the Database Management System (DBMS) and its key terms, and then explains the relational data model, where data is kept in related tables. It ends with keys: candidate, primary, alternate, composite and foreign keys, which identify rows and link tables.
Fully in the CBSE 2025-26 syllabus: introduction to database concepts and its need, Database Management System, and the relational data model (domain, tuple, relation, candidate key, primary key, alternate key). Foreign key, composite key, degree and cardinality are not named in the syllabus line but are part of the NCERT chapter, are needed for the SQL chapter and Class XII, and appear regularly in board papers, so they are covered in full.
Learning outcomes
- Students will be able to explain the need for a database using a real-life example.
- Students will be able to describe the limitations of a file system: difficulty of access, redundancy, inconsistency, isolation, dependence and uncontrolled sharing.
- Students will be able to define a DBMS, name common DBMS software, and explain schema, constraint, meta-data, instance and query.
- Students will be able to use relational model terms: relation, attribute, tuple, domain, degree and cardinality.
- Students will be able to state the properties of a relation and the meaning of NULL.
- Students will be able to identify candidate, primary, alternate and composite keys in a given table.
- Students will be able to explain a foreign key and identify it between two related tables.
- Students will be able to redesign file-based records into related tables with suitable keys.
Lesson plan
Show two paper registers: the office admission register and the accounts fee register. Ask: a student's name is misspelt; how many registers must be corrected? Students list the problems on the board. Introduce the term file system.
Use the STUDENT and FEE files from the notes. In pairs, students find one example each of redundancy, inconsistency, isolation, dependence and controlled sharing in the two files. Summarise in a board table.
Define database and DBMS. Students name DBMS software and discuss where databases are used (IRCTC, banks, hospitals, the school ERP). Discuss the limitations of a DBMS (cost, complexity, single point of failure).
Draw a database schema for the school on the board. Explain schema vs instance with the analogy of an empty class register (schema) vs today's filled page (instance). Cover constraint, meta-data (data dictionary), query, data manipulation and database engine.
Project the TRAIN relation. Label relation, attribute, tuple, domain, degree and cardinality with arrows. Students build a CRICKETER relation in their notebooks and state its degree and cardinality. Discuss the properties of a relation and the meaning of NULL.
Give a STUDENT table with AdmNo, RollNo, Section, AadhaarNo and Email. Students test each column for uniqueness and no-NULL, find the candidate keys, choose a primary key and name the alternate keys. In the lab run the candidate-key checker program.
Use the FEE table to show why (AdmNo, Month) is needed as a composite primary key. Link STUDENT to PARENT and FEE to STUDENT with arrows to show foreign keys. Students run the foreign-key checker and explain each invalid row.
Groups convert a library register (book, member, issue) into three related tables, marking primary and foreign keys. Preview the MySQL CREATE TABLE statements with keys. Finish with the MCQ and assertion-reason worksheet.
Notes
Why do we need a database?
Every organisation keeps records: a school keeps admissions, attendance, fees and results; a bank keeps accounts and transactions; Indian Railways keeps trains, seats and bookings. These records must be stored safely, found quickly, kept correct when they change, and shared with the right people.
With a small amount of data, a register or a few computer files are enough. As data grows and many people use it, separate files become hard to manage. A database keeps all related data together in an organised way so that it can be stored, searched, updated and shared efficiently.
A database is an organised collection of logically related data. In the relational model it is a collection of related tables.
File system: the traditional approach
A file is a container that stores data on a computer, such as a text file, a spreadsheet or a CSV file. In a file system, each department keeps its own files and uses its own application programs to read them.
Example: the school office keeps a STUDENT file, and the accounts section keeps a FEE file.
| AdmNo | SName | Class | DOB | ParentName | ParentPhone |
|---|---|---|---|---|---|
| 1101 | Aditi Rao | XI-A | 2009-04-12 | Suresh Rao | 9876501234 |
| 1102 | Kabir Singh | XI-A | 2009-08-30 | Harpreet Singh | 9811122233 |
| 1103 | Meher Gill | XI-B | 2009-01-05 | Navjot Gill | 9988776655 |
| 1105 | Ishaan Rao | IX-C | 2011-11-19 | Suresh Rao | 9876501234 |
The FEE file kept by accounts has columns AdmNo, SName, Month and Amount. Keep both files on the board; every limitation in the next section can be shown using just these two.
The FEE file (kept separately by accounts)
Notice that the student's name is typed again in every fee row, and that the FEE file has no built-in link to the STUDENT file. Only the matching AdmNo values connect them, and only a person or a program knows that.
| AdmNo | SName | Month | Amount |
|---|---|---|---|
| 1101 | Aditi Rao | April | 2500 |
| 1101 | Aditi Rao | May | 2500 |
| 1102 | Kabir Singh | April | 2500 |
| 1103 | Meher Gill | April | 2500 |
Limitations of a file system
- Difficulty in access: files do not provide a way to ask questions of the data. To get "names of students of XI-A who have not paid May fees" someone must write a new program, because the original programs did not anticipate this need.
- Data redundancy: the same data is stored in many places. SName is in both files, and Suresh Rao's name and phone are stored twice because he has two children in the school. Redundancy wastes space and causes inconsistency.
- Data inconsistency: copies of the same data do not match. If the office corrects "Aditi" to "Aditee" but accounts does not, the two files disagree.
- Data isolation: the files are created separately, perhaps in different formats, with no link between them. Combining them needs special programs and knowledge of each file's structure.
- Data dependence: programs depend on the exact structure of the file. If a column is added or its format changes (say DOB from DD-MM-YYYY to YYYY-MM-DD), every program that reads the file must be changed.
- Controlled data sharing is difficult: different users need different rights. Parents should only view fees, accounts should update them, and teachers should not see them at all. Such access control is very hard to enforce on plain files.
| Limitation | One-line meaning |
|---|---|
| Difficulty in access | A new program is needed for every new kind of question |
| Redundancy | The same data is duplicated in many files |
| Inconsistency | Duplicate copies stop matching after an update |
| Isolation | Related files are not linked and may differ in format |
| Dependence | Changing the file structure breaks the programs |
| Controlled sharing | Hard to give different users different access rights |
Board answers usually ask for any two/three limitations with examples. Train students to write the term, a one-line meaning, and an example from the school case.
Database Management System (DBMS)
A Database Management System (DBMS) is software used to create and manage databases. It lets users and application programs define the database structure and store, retrieve, update and delete data.
Examples: MySQL, Oracle, PostgreSQL, Microsoft SQL Server, Microsoft Access, SQLite, MongoDB. MySQL is open source and is the DBMS used in the CBSE IP practicals.
The DBMS sits between the users (or programs) and the stored data. Users send requests (queries); the DBMS finds the data and returns the result. It hides the details of how data is physically stored, giving users an abstract view of the data. Some DBMSs have a graphical interface; others are used through commands typed at a command line.
| Application | Data kept in the database |
|---|---|
| Railway reservation (IRCTC) | Trains, stations, coaches, seats, passengers, PNRs, payments |
| Banking | Customers, accounts, loans, ATM and UPI transactions |
| Hospital | Patients, doctors, appointments, prescriptions, bills |
| School ERP | Students, parents, attendance, fees, marks, timetable |
| Online shopping | Products, stock, customers, orders, deliveries, reviews |
| Kisan Credit Card scheme | Farmers, land holdings, crops, loans, repayments |
From file system to DBMS: redesigning the school data
To move the school files into a database we remove duplication and add links:
- Do not repeat SName in the fee table. The name is kept once, in STUDENT; the fee table keeps only AdmNo, which links to it.
- Keep parent details once. Siblings share a parent, so move parent data to a separate PARENT table and give each parent a unique ParentID. STUDENT stores only the ParentID.
- Use a stable identifier. Two parents may have the same name, and phone numbers can change, so a ParentID created by the school is the safest way to identify a parent.
Resulting design (the schema):
- STUDENT(AdmNo, SName, Class, DOB, ParentID)
- PARENT(ParentID, PName, Phone, Email)
- FEE(AdmNo, Month, Amount, PaidOn)
All three tables live in one database, managed by one DBMS, and can be used by the office, accounts and teachers at the same time, each with suitable permissions.
| Problem in file system | How the DBMS design solves it |
|---|---|
| Name stored in many files (redundancy) | Name stored once in STUDENT; other tables use AdmNo |
| Copies disagree after an update (inconsistency) | Only one copy exists, so one update is enough |
| Files not linked (isolation) | Tables are linked through common attributes (keys) |
| New program for each question (access) | Questions are asked with a query language (SQL) |
| Programs break when structure changes (dependence) | Programs talk to the DBMS, not directly to the files |
| No access control (sharing) | The DBMS gives each user only the rights they need |
Limitations of a DBMS
A DBMS is not free of costs:
- High cost: hardware, software licences (for commercial DBMSs), and training staff to write queries.
- Increased complexity: security, backup, recovery and concurrent use must be planned and managed.
- Increased vulnerability: data is stored centrally, so a hardware or software failure (or an attack) can stop work for all users at once; regular backups are essential.
For very small, single-user data a simple file may still be enough.
Key terms in a DBMS
- Database schema: the design or skeleton of the database: table names, their attributes, the data type of each attribute, constraints, and relationships between tables. It changes rarely.
- Data constraint: a rule that restricts the values allowed in a column, for example
NOT NULL,UNIQUE, or "Phone must be exactly 10 digits". Constraints keep the data accurate and reliable. - Meta-data (data dictionary / catalog): the schema and constraints are stored by the DBMS as data about data, in the database catalog or data dictionary.
- Database instance: the actual data in the database at a particular moment (a snapshot). One schema has many instances over time, because rows are added, changed and deleted.
- Query: a request to the database for information, for example "list students of XI-A who have not paid May fees". Queries are written in a query language such as SQL.
- Data manipulation: changing the data. Insertion (a new student joins), deletion (a student leaves) and update (a parent changes phone number).
- Database engine: the underlying component of a DBMS that actually creates the database and processes queries and data changes.
Schema vs instance analogy: the printed format of an empty attendance register is the schema; the filled page for today is an instance.
Relational data model
A data model describes how data is structured in a database, how it is related, and which constraints apply. Types include the relational, hierarchical, network, object-oriented, entity-relationship and document models. The relational data model is the most widely used; MySQL is a relational DBMS (RDBMS).
In the relational model, data is stored in tables called relations. Each table has a unique name, each column has a unique name within the table, and each row holds the related values of one real-world entity (one student, one train, one fee payment). Relations are linked to each other through common attributes, which is what makes it a relational database.
The example below is the relation TRAIN.
| TrainNo | TrainName | Source | Destination | Type |
|---|---|---|---|---|
| 12951 | Mumbai Rajdhani | Mumbai Central | New Delhi | Rajdhani |
| 12301 | Howrah Rajdhani | Howrah | New Delhi | Rajdhani |
| 12002 | Bhopal Shatabdi | New Delhi | Rani Kamlapati | Shatabdi |
| 22436 | Vande Bharat Express | New Delhi | Varanasi | Vande Bharat |
Relational terminology: attribute, tuple, domain, degree, cardinality
Using the TRAIN relation above:
- Relation: a table. TRAIN is a relation.
- Attribute: a column (field), a characteristic stored for every row. TrainNo, TrainName, Source, Destination and Type are attributes.
- Tuple: a row (record) of the relation. (12301, Howrah Rajdhani, Howrah, New Delhi, Rajdhani) is one tuple.
- Domain: the set of allowed values for an attribute, usually given by a data type and rules. The domain of TrainNo is 5-digit whole numbers; the domain of Type is {Rajdhani, Shatabdi, Vande Bharat, Express, ...}.
- Degree: the number of attributes (columns). Degree of TRAIN = 5.
- Cardinality: the number of tuples (rows). Cardinality of TRAIN = 4.
The column headings themselves are not counted as a tuple.
| Relational term | Common term | Value for TRAIN |
|---|---|---|
| Relation | Table | TRAIN |
| Attribute | Column / field | TrainNo, TrainName, ... |
| Tuple | Row / record | 4 rows |
| Degree | Number of columns | 5 |
| Cardinality | Number of rows | 4 |
# A relation stored as a header plus a list of tuples
header = ("TrainNo", "TrainName", "Source", "Destination", "Type")
rows = [
(12951, "Mumbai Rajdhani", "Mumbai Central", "New Delhi", "Rajdhani"),
(12301, "Howrah Rajdhani", "Howrah", "New Delhi", "Rajdhani"),
(12002, "Bhopal Shatabdi", "New Delhi", "Rani Kamlapati", "Shatabdi"),
(22436, "Vande Bharat Express", "New Delhi", "Varanasi", "Vande Bharat"),
]
print("Degree (number of attributes):", len(header))
print("Cardinality (number of tuples):", len(rows))Degree (number of attributes): 5 Cardinality (number of tuples): 4
Memory aid: Degree goes Down the header, counting columns; Cardinality Counts the rows (records). A classic question: "A table has degree 6 and cardinality 10. Two rows are added and one column is deleted. Find the new degree and cardinality." Answer: degree 5, cardinality 12.
Properties of a relation
A relation is more than a simple table. It follows these rules:
About attributes
- Each attribute in a relation has a unique name.
- The order of attributes does not matter.
About tuples
- Each tuple is distinct: no two rows can have the same values in every attribute.
- The order of tuples does not matter; a relation is not sorted by default.
About values
- All values of an attribute come from the same domain (same data type).
- Each value is atomic, meaning it cannot be meaningfully split further. A single Phone cell cannot hold two numbers.
- A special value NULL represents a value that is unknown or not applicable, for example when a parent has not given an email ID. NULL is not zero and not a blank space.
Students often write NULL = 0. Correct it firmly: 0 is a known value; NULL means "no value known".
Keys: why we need them
Because every tuple must be distinct, there must be some attribute (or set of attributes) whose values identify each row uniquely and are never NULL. Such attributes are called keys. Keys also link tables together. The relational model defines the following kinds:
- Candidate key
- Primary key
- Alternate key
- Composite (primary) key
- Foreign key
We will use this STUDENT relation for the first three:
| AdmNo | RollNo | SName | Section | AadhaarNo | |
|---|---|---|---|---|---|
| 1101 | 1 | Aditi Rao | A | 4521 7788 1290 | aditi@mail.com |
| 1102 | 2 | Kabir Singh | A | 6123 4590 7781 | kabir@mail.com |
| 1103 | 1 | Meher Gill | B | 7712 3409 5566 | meher@mail.com |
| 1104 | 2 | Rohan Das | B | 3390 1287 4410 | rohan@mail.com |
| 1105 | 3 | Aditi Rao | B | 8845 2210 9034 | aditi.r@mail.com |
Candidate key
A candidate key is an attribute (or minimal set of attributes) that can uniquely identify every tuple of a relation. Its values are unique and not NULL. A relation may have more than one candidate key; each is a candidate for becoming the primary key.
In STUDENT:
- AdmNo: unique for every student, so it is a candidate key.
- AadhaarNo: unique for every person, so it is a candidate key.
- Email: unique (if every student must give one), so it is a candidate key.
- RollNo is not: roll number 1 exists in both sections A and B.
- SName is not: two students are named Aditi Rao.
- Section is not: it repeats.
So the candidate keys are {AdmNo}, {AadhaarNo} and {Email}.
To test a column, ask two questions: Can two rows ever have the same value? and Can it ever be empty? If the answer to both is "no", it is a candidate key. Decide from the meaning of the data, not just from the few rows shown.
Primary key and alternate key
The primary key is the one candidate key chosen by the database designer to uniquely identify tuples in the relation. A relation has only one primary key. Its values must be unique and can never be NULL.
The candidate keys that are not chosen as the primary key are called alternate keys.
In STUDENT, the school chooses AdmNo as the primary key: it is short, issued by the school, and never changes. Then AadhaarNo and Email are alternate keys.
Candidate keys = Primary key + Alternate keys
In a schema diagram the primary key is usually underlined; in plain text we often show it in bold: STUDENT(AdmNo, RollNo, SName, Section, AadhaarNo, Email).
| Attribute | Unique? | Never NULL? | Candidate key? | Role |
|---|---|---|---|---|
| AdmNo | Yes | Yes | Yes | Primary key |
| AadhaarNo | Yes | Yes | Yes | Alternate key |
| Yes | Yes (if compulsory) | Yes | Alternate key | |
| RollNo | No | Yes | No | - |
| SName | No | Yes | No | - |
Why not choose Email as the primary key? It can change, and it is long. Good primary keys are short, stable and never empty.
Composite primary key
Sometimes no single attribute can identify each row. Then two or more attributes together form the primary key. This is a composite primary key (composite key).
In the FEE relation (AdmNo, Month, Amount, PaidOn):
- AdmNo repeats, because a student pays every month.
- Month repeats, because many students pay in April.
- But a given student pays only once for a given month, so (AdmNo, Month) together is unique. It is the composite primary key of FEE.
Other examples: (TrainNo, JourneyDate) for a train's daily run; (Class, Section, RollNo) for students.
| AdmNo | Month | Amount | PaidOn |
|---|---|---|---|
| 1101 | April | 2500 | 2025-04-08 |
| 1102 | April | 2500 | 2025-04-10 |
| 1101 | May | 2500 | 2025-05-06 |
| 1103 | April | 2500 | 2025-04-15 |
# FEE relation: neither AdmNo nor Month is unique on its own
fee = [
(1101, "April", 2500), (1102, "April", 2500),
(1101, "May", 2500), (1102, "May", 2700),
(1103, "April", 2500),
]
adm = [r[0] for r in fee]
month = [r[1] for r in fee]
pair = [(r[0], r[1]) for r in fee]
print("AdmNo unique? ", len(adm) == len(set(adm)))
print("Month unique? ", len(month) == len(set(month)))
print("(AdmNo, Month) unique?", len(pair) == len(set(pair)))AdmNo unique? False Month unique? False (AdmNo, Month) unique? True
Foreign key
A foreign key is an attribute (or set of attributes) in one relation whose values are taken from the primary key of another relation. It represents the relationship between the two tables.
- The table that contains the foreign key is the referencing (child) table.
- The table whose primary key is referred to is the referenced (parent, master or primary) table.
Rules:
- Every non-NULL value of a foreign key must match an existing primary-key value in the referenced table. A fee row for AdmNo 9999 is not allowed if there is no student 9999.
- A foreign key may repeat, because many students can have the same parent.
- A foreign key may be NULL, unless it is part of the primary key of its own table.
In the school database:
- STUDENT.ParentID -> PARENT.ParentID (each student refers to a parent)
- FEE.AdmNo -> STUDENT.AdmNo (each fee row refers to a student). Here AdmNo is part of FEE's composite primary key, so it can never be NULL.
A foreign key need not have the same name as the primary key it refers to, but it must have the same domain (data type).
| Table | Primary key | Foreign key (-> refers to) |
|---|---|---|
| PARENT(ParentID, PName, Phone, Email) | ParentID | - |
| STUDENT(AdmNo, SName, Class, DOB, ParentID) | AdmNo | ParentID -> PARENT(ParentID) |
| FEE(AdmNo, Month, Amount, PaidOn) | (AdmNo, Month) | AdmNo -> STUDENT(AdmNo) |
In schema diagrams, a foreign key is drawn as an arrow from the foreign-key column to the primary key it refers to. Ask students to draw this for the three school tables.
Preview: how keys are declared in MySQL
In the next chapter, students create tables in MySQL. Keys and constraints are declared in CREATE TABLE. This preview shows where each idea from this chapter appears. Note that PARENT must be created before STUDENT, and STUDENT before FEE, because a foreign key can only refer to a table that already exists.
If you try to insert a STUDENT row with a ParentID that does not exist in PARENT, MySQL rejects it with a foreign-key constraint error.
CREATE TABLE PARENT (
ParentID INT PRIMARY KEY,
PName VARCHAR(40) NOT NULL,
Phone CHAR(10) UNIQUE,
Email VARCHAR(50) UNIQUE
);
CREATE TABLE STUDENT (
AdmNo INT PRIMARY KEY,
SName VARCHAR(40) NOT NULL,
Class VARCHAR(5),
DOB DATE,
ParentID INT,
FOREIGN KEY (ParentID) REFERENCES PARENT(ParentID)
);
CREATE TABLE FEE (
AdmNo INT,
Month VARCHAR(10),
Amount DECIMAL(8,2),
PaidOn DATE,
PRIMARY KEY (AdmNo, Month),
FOREIGN KEY (AdmNo) REFERENCES STUDENT(AdmNo)
);PRIMARY KEY implies UNIQUE and NOT NULL. UNIQUE on Phone and Email declares them as alternate keys.
Key terms
- File system
- Storing data in separate files, each accessed by its own application programs.
- Database
- An organised collection of logically related data.
- DBMS
- Software used to create, manage and query databases, e.g. MySQL.
- Data redundancy
- Unnecessary duplication of the same data in more than one place.
- Data inconsistency
- Copies of the same data that do not match.
- Database schema
- The design of a database: tables, attributes, data types, constraints and relationships.
- Database instance
- The data stored in a database at a particular moment.
- Meta-data / data dictionary
- Data about data; the stored schema and constraints of a database.
- Relation
- A table in the relational data model.
- Attribute
- A column of a relation.
- Tuple
- A row of a relation.
- Domain
- The set of permitted values for an attribute.
- Degree
- The number of attributes (columns) in a relation.
- Cardinality
- The number of tuples (rows) in a relation.
- Candidate key
- An attribute or minimal set of attributes that can uniquely identify every tuple.
- Primary key
- The candidate key chosen to identify tuples uniquely; unique and never NULL.
- Alternate key
- A candidate key that is not chosen as the primary key.
- Composite key
- A primary key made up of two or more attributes.
- Foreign key
- An attribute whose values refer to the primary key of another relation.
- NULL
- A special marker for a value that is unknown or not applicable; not zero or blank.
MCQs
Tap an option to check it, or use Show answers above to reveal them all.
-
Storing the same data in more than one file is called:
Answer(b) Data redundancy
Redundancy means duplication of data.
-
A student's address is updated in the office file but not in the transport file. This is an example of:
Answer(a) Data inconsistency
The two copies no longer match, so the data is inconsistent.
-
When the format of a date column in a file is changed, all programs using the file must be modified. This limitation is called:
Answer(c) Data dependence
Programs depend on the file's structure: data dependence.
-
Which of the following is NOT a DBMS?
Answer(d) Python
Python is a programming language, not a database management system.
-
The overall design of a database, including tables, attributes and constraints, is called its:
Answer(b) Schema
The schema is the skeleton or design; the instance is the data at a moment.
-
Data about data, stored in the database catalog, is called:
Answer(a) Meta-data
The data dictionary stores meta-data such as the schema and constraints.
-
In the relational model, a row of a table is called a:
Answer(c) Tuple
Row = tuple; column = attribute.
-
The number of attributes in a relation is its:
Answer(d) Degree
Degree counts columns; cardinality counts rows.
-
A table SHOP has 7 columns and 25 rows. Its degree and cardinality are:
Answer(a) 7 and 25
Degree = columns = 7; cardinality = rows = 25.
-
A relation has degree 4 and cardinality 12. After adding 3 rows and 1 column, what are the new degree and cardinality?
Answer(c) 5 and 15
Degree 4 + 1 = 5; cardinality 12 + 3 = 15.
-
The set of permitted values for an attribute is called its:
Answer(b) Domain
For example, the domain of a Gender column might be {M, F, T}.
-
Which statement about a primary key is TRUE?
Answer(c) It uniquely identifies each tuple and cannot be NULL
A primary key is unique and never NULL, and there is only one per table.
-
All attributes that can uniquely identify tuples in a relation are called:
Answer(d) Candidate keys
Every attribute able to serve as primary key is a candidate key.
-
In EMPLOYEE(EmpID, Name, PAN, Mobile, Dept), EmpID, PAN and Mobile are all unique. If EmpID is the primary key, then PAN and Mobile are:
Answer(b) Alternate keys
Candidate keys not chosen as the primary key are alternate keys.
-
A primary key made of more than one attribute is a:
Answer(a) Composite key
For example (AdmNo, Month) in a FEE table.
-
An attribute of one table that refers to the primary key of another table is a:
Answer(c) Foreign key
A foreign key links the referencing table to the referenced table.
-
In ORDERS(OrderID, CustID, OrderDate) and CUSTOMER(CustID, CName, City), the foreign key is:
Answer(d) CustID in ORDERS
CustID in ORDERS refers to CustID, the primary key of CUSTOMER.
-
Which value can a foreign key take, provided it is not part of its own table's primary key?
Answer(b) NULL or a value existing in the referenced primary key
Non-NULL foreign key values must match an existing primary key value; NULL is allowed.
-
Which of these is NOT a property of a relation?
Answer(c) Tuples must be stored in sorted order
The order of tuples does not matter in a relation.
-
Which is a limitation of a DBMS compared with a file system?
Answer(a) Higher cost and complexity
A DBMS reduces redundancy and dependence but needs costly software, hardware and trained staff.
Assertion–Reason
Assertion (A): A DBMS reduces data inconsistency.
Reason (R): In a DBMS, each piece of data is ideally stored only once, so an update is made in one place.
Answer(A)
Inconsistency arises from duplicate copies. Removing redundancy removes the cause, so R explains A.
Assertion (A): RollNo cannot be the primary key of a table storing students of all sections of Class XI.
Reason (R): A primary key must uniquely identify each tuple, and the same roll number appears in different sections.
Answer(A)
Both are true and R gives the reason.
Assertion (A): A relation can have more than one candidate key.
Reason (R): A relation can have more than one primary key.
Answer(C)
A is true. R is false: there is exactly one primary key, though it may be composite.
Assertion (A): A foreign key can have duplicate values in its table.
Reason (R): Every value of a foreign key must be unique in the referenced table.
Answer(B)
A is true: many students may share one ParentID. R is also true, since the referenced attribute is a primary key and so unique, but it does not explain why duplicates are allowed in the referencing table.
Assertion (A): The cardinality of a relation includes the row of column headings.
Reason (R): Cardinality is the number of tuples in a relation.
Answer(D)
Headings are attribute names, not a tuple, so A is false. R is the correct definition.
Short answer
- 2 marks
Define data redundancy and data inconsistency. How are they related?
AnswerData redundancy is the duplication of the same data in more than one place. Data inconsistency is when such duplicate copies do not match, for example after one copy is updated and another is not. Redundancy is the cause; inconsistency is the result.
- 2 marks
What is a DBMS? Name any two DBMS software.
AnswerA Database Management System is software used to create and manage databases: to define their structure and to store, retrieve, update and delete data, and to control access. Examples: MySQL, Oracle (also PostgreSQL, SQL Server, MS Access).
- 2 marks
Differentiate between database schema and database instance.
AnswerThe schema is the design of the database: tables, attributes, data types, constraints and relationships. It rarely changes. The instance is the actual data stored at a particular moment, a snapshot. It changes whenever rows are inserted, updated or deleted. One schema has many instances over time.
- 2 marks
Define degree and cardinality. Find them for a table with columns ItemNo, ItemName, Price, Qty and 9 records.
AnswerDegree is the number of attributes (columns); cardinality is the number of tuples (rows).
Here degree = 4 and cardinality = 9.
- 2 marks
What is a domain? Give the domain of the attributes Gender and Marks (out of 100) in a STUDENT table.
AnswerA domain is the set of permitted values from which an attribute takes its value.
- Gender: {'M', 'F', 'T'} (single characters from a fixed set)
- Marks: whole numbers from 0 to 100
- 2 marks
Differentiate between primary key and alternate key with an example.
AnswerBoth are candidate keys. The primary key is the candidate key chosen to identify tuples; the remaining candidate keys are alternate keys.
Example: in VOTER(VoterID, AadhaarNo, Name, Ward), VoterID and AadhaarNo are both candidate keys. If VoterID is the primary key, AadhaarNo is an alternate key.
- 2 marks
What is a candidate key? Can a table have more than one? Explain.
AnswerA candidate key is an attribute (or minimal set of attributes) whose values are unique and not NULL for every tuple, so it can identify each row. Yes, a table can have several. For example, a BANK_ACCOUNT table may have AccountNo, IBAN and DebitCardNo, each unique.
- 2 marks
What is a composite primary key? Give an example.
AnswerA primary key made of two or more attributes, used when no single attribute is unique. Example: in ATTENDANCE(AdmNo, AttDate, Status), AdmNo repeats every day and AttDate repeats for every student, but (AdmNo, AttDate) is unique, so it is the composite primary key.
- 2 marks
What is a foreign key? Explain with an example of two tables.
AnswerA foreign key is an attribute of one table whose values come from the primary key of another table; it links the two tables.
Example: DEPT(DeptNo, DName) and EMP(EmpNo, EName, DeptNo). DeptNo in EMP is a foreign key referring to DeptNo, the primary key of DEPT. Every DeptNo in EMP must exist in DEPT (or be NULL).
- 2 marks
Explain data isolation and data dependence as limitations of a file system.
AnswerData isolation: related data is kept in separate files, possibly in different formats, with no link between them, so combining them needs special programs.
Data dependence: programs are written for a file's exact structure, so any change in the structure (adding a column, changing a format) forces every program that uses the file to be rewritten.
- 2 marks
What is NULL? How is it different from zero?
AnswerNULL is a special marker meaning the value is unknown or not applicable, for example a phone number not yet given. Zero is a known numeric value. A student's marks being 0 means the student scored zero; marks being NULL means the marks have not been entered.
- 2 marks
Give any two limitations of a DBMS.
Answer- High cost: hardware, software licences, and training users to write queries.
- Increased vulnerability: data is stored centrally, so a single failure can stop all users and can lose data unless regular backups are taken.
(Also accepted: increased complexity of managing security, consistency and recovery.)
Long answer
- 3 marks
Explain any three limitations of a file system with examples from a school.
Answer- Data redundancy: the office's STUDENT file and the library's MEMBER file both store each student's name and class, wasting space.
- Data inconsistency: when a student changes section, the office updates its file but the library does not, so the two files show different sections.
- Controlled data sharing is difficult: parents should only view fee details and accounts staff should update them, but plain files cannot easily give different users different rights.
(Difficulty in access, isolation and dependence are also accepted, each with an example.)
- 3 marks
Consider the relation BOOK(BookID, Title, Author, ISBN, Price) with these tuples (ISBNs are sample values):
- (B01, Wings of Fire, A.P.J. Abdul Kalam, 978-81-0001, 350)
- (B02, Godan, Premchand, 978-81-0002, 250)
- (B03, Malgudi Days, R.K. Narayan, 978-81-0003, 199)
- (B04, Gitanjali, Rabindranath Tagore, 978-81-0004, 150)
(a) Find its degree and cardinality. (b) Identify the candidate keys. (c) If BookID is the primary key, name the alternate key.
Answer(a) Degree = 5 (BookID, Title, Author, ISBN, Price); cardinality = 4.
(b) Candidate keys: BookID and ISBN, since each book has a unique ID and a unique ISBN. Title and Author can repeat (an author writes many books; two books can share a title), and Price obviously repeats.
(c) ISBN is the alternate key.
- 3 marks
Consider the tables:
COACH(CoachID, CName, Sport)
PLAYER(PlayerID, PName, Age, CoachID)(a) Identify the primary key of each table. (b) Identify the foreign key and the table it refers to. (c) Can two players have the same CoachID? Can a player have CoachID = 'C99' if there is no such coach? Explain.
Answer(a) COACH: CoachID. PLAYER: PlayerID.
(b) CoachID in PLAYER is a foreign key referring to CoachID, the primary key of COACH.
(c) Yes, many players can have the same coach, so foreign key values may repeat. No, C99 is not allowed: a non-NULL foreign key value must match an existing primary key value in COACH.
- 3 marks
Differentiate between a file system and a DBMS on any three points.
Answer- Redundancy: in a file system, the same data is duplicated across files. A DBMS stores data once and links tables through keys.
- Consistency: in a file system, duplicate copies may not match after updates. In a DBMS, one copy means one update, so data stays consistent.
- Access: in a file system, a new program is needed for each new question. A DBMS answers questions with queries in a language such as SQL.
- Security/sharing: a file system makes it hard to set user-wise permissions. A DBMS gives each user only the rights they need.
- Dependence: in a file system, programs break when the file structure changes. In a DBMS, programs use the DBMS, which hides the storage details.
(Any three.)
- 5 marks
A hospital keeps the following file:
PATIENT_VISIT(PatientID, PName, Phone, DoctorID, DoctorName, Specialisation, VisitDate, Fee)
The same patient visits many times, and each doctor sees many patients.
(a) Identify two kinds of redundancy in this file. (b) Redesign it as three related tables. (c) Mark the primary key and any foreign keys of each table.
Answer(a) The patient's name and phone are repeated in every visit of that patient. The doctor's name and specialisation are repeated in every visit handled by that doctor.
(b) and (c):
- PATIENT(PatientID, PName, Phone). Primary key: PatientID.
- DOCTOR(DoctorID, DoctorName, Specialisation). Primary key: DoctorID.
- VISIT(PatientID, DoctorID, VisitDate, Fee). Composite primary key: (PatientID, DoctorID, VisitDate). Foreign keys: PatientID -> PATIENT(PatientID) and DoctorID -> DOCTOR(DoctorID).
(A separate VisitID as the primary key of VISIT is also acceptable; PatientID and DoctorID then remain foreign keys.)
Now each patient's and doctor's details are stored once, and a correction is made in one place only.
- 5 marks
Define the following with reference to the relation CRICKETER(CapNo, Name, State, Role, Matches) given below: (a) relation (b) attribute (c) tuple (d) domain (e) degree and cardinality. Also identify a suitable primary key.
- (101, Arjun, Punjab, Batter, 42)
- (102, Kiran, Karnataka, Bowler, 37)
- (103, Sameer, Gujarat, All-rounder, 55)
Answer(a) Relation: a table of data with uniquely named columns and distinct rows. CRICKETER is the relation.
(b) Attribute: a column. CapNo, Name, State, Role and Matches are attributes.
(c) Tuple: a row. (102, Kiran, Karnataka, Bowler, 37) is one tuple.
(d) Domain: the set of allowed values for an attribute. The domain of Role is {Batter, Bowler, All-rounder, Wicketkeeper}; the domain of Matches is non-negative whole numbers.
(e) Degree = 5 (attributes); cardinality = 3 (tuples).
Primary key: CapNo, since each player's cap number is unique and never empty. Names and states can repeat.
- 3 marks
Explain the three properties of a relation and state why NULL is needed.
Answer- Attributes: each attribute has a unique name, and the order of attributes is immaterial.
- Tuples: each tuple is distinct (no two rows identical in all attributes), and the order of tuples is immaterial.
- Values: all values in a column come from the same domain; each value is atomic (one indivisible value per cell, so no list of phone numbers in one cell).
NULL is needed because sometimes a value is unknown or not applicable, for example a guardian's email not yet given, or a 'Spouse' column for an unmarried person. NULL marks this without inventing a fake value like 0 or a blank.
Case-based
Green Valley School keeps admissions in a spreadsheet maintained by the office, and library issues in a separate spreadsheet maintained by the librarian. The library sheet has the columns AdmNo, StudentName, Class, BookTitle, IssueDate. Last month a student's class was changed from XI-A to XI-C in the office sheet, but the library sheet still shows XI-A. The principal now wants a list of students who have overdue books along with their parents' phone numbers, but no one can produce it without writing a new program.
- 1 mark
Name the limitation shown by the class mismatch between the two sheets.
AnswerData inconsistency, caused by the same data (class) being stored redundantly in two places.
- 1 mark
Which limitation makes the principal's request difficult?
AnswerDifficulty in access, together with data isolation: the required data is in two unlinked files, and no existing program answers this question.
- 2 marks
Suggest a database design with two tables to remove the redundancy. Mark the primary key and foreign key.
AnswerSTUDENT(AdmNo, SName, Class, ParentPhone), with primary key AdmNo.
ISSUE(AdmNo, BookTitle, IssueDate), with composite primary key (AdmNo, BookTitle, IssueDate) and foreign key AdmNo -> STUDENT(AdmNo).
(A BOOK table with BookID and an ISSUE table using BookID is an even better design.)
A state transport department stores bus details in the relation BUS(RegNo, Route, Driver, LicenceNo, Seats):
- (JK02-1234, Jammu-Katra, Ravi, JK0220190011, 42)
- (JK02-5678, Jammu-Udhampur, Imran, JK0220170044, 52)
- (JK01-1111, Srinagar-Gulmarg, Ravi, JK0120150098, 42)
- (JK01-2222, Srinagar-Sonamarg, Sunita, JK0120200007, 35)
Each bus has one regular driver, and no driver drives two buses.
- 1 mark
What is the degree and cardinality of this relation?
AnswerDegree = 5; cardinality = 4.
- 1 mark
Can Driver be a primary key? Give a reason.
AnswerNo. Driver names can repeat: there are two drivers named Ravi. A primary key must be unique.
- 1 mark
Identify the candidate keys, the primary key and the alternate key.
AnswerCandidate keys: RegNo and LicenceNo, since each bus has a unique registration and each driver a unique licence, and no driver drives two buses. Choosing RegNo as the primary key makes LicenceNo the alternate key.
- 1 mark
If two new buses are added and the column Seats is removed, what will be the new degree and cardinality?
AnswerDegree = 5 − 1 = 4; cardinality = 4 + 2 = 6.
An online grocery app in Kochi uses these relations:
CUSTOMER(CustID, CName, Mobile, Area)
PRODUCT(ProdCode, PName, Price)
ORDERS(OrderNo, CustID, ProdCode, Qty, OrderDate)
Each customer registers with a unique mobile number. A developer wants to insert an order with CustID = 'C777', but there is no such customer.
- 1 mark
Identify the primary key of each relation.
AnswerCUSTOMER: CustID. PRODUCT: ProdCode. ORDERS: OrderNo.
- 1 mark
Identify the foreign keys in ORDERS and the tables they refer to.
AnswerCustID -> CUSTOMER(CustID) and ProdCode -> PRODUCT(ProdCode).
- 1 mark
Name an alternate key in CUSTOMER.
AnswerMobile, since it is unique for each customer but not chosen as the primary key.
- 1 mark
Will the DBMS accept the order for 'C777'? Why?
AnswerNo. CustID in ORDERS is a foreign key, so its value must match an existing CustID in CUSTOMER. Since C777 does not exist, the DBMS rejects the row and keeps the data valid.
Practicals
1Identify keys in a table (classroom activity)
Give students the relation MOBILE_USER(UserID, Name, MobileNo, Email, City) with eight sample rows, where two users share the name "Rahul Sharma" and three live in Pune. Ask them to: (1) find the degree and cardinality, (2) list the candidate keys with reasons, (3) choose a primary key and justify it, (4) name the alternate keys.
Model answer
1. Degree = 5, Cardinality = 8
2. Candidate keys: UserID, MobileNo, Email
- each is unique for every user and must always be filled
- Name is not (two users are named Rahul Sharma)
- City is not (three users live in Pune)
3. Primary key: UserID - short, assigned by the system, never changes
(mobile numbers and emails can be changed by the user)
4. Alternate keys: MobileNo, EmailViva questions (4)
- Can a table have two primary keys? No; it has one primary key, which may be composite.
- Why is Name not a candidate key? Names can repeat.
- What do the candidate keys add up to? The primary key plus the alternate keys.
- Can a primary key be NULL? Never.
2Candidate-key checker in Python
A STUDENT relation is stored as a list of rows. Write a function can_be_key(col) that returns True if a column has no None values and no duplicates. Use it to report which attributes can be candidate keys for the data given.
# Which attributes of STUDENT can be candidate keys?
header = ["AdmNo", "RollNo", "SName", "Section", "AadhaarNo", "Email"]
rows = [
[1101, 1, "Aditi Rao", "A", "4521 7788 1290", "aditi@mail.com"],
[1102, 2, "Kabir Singh", "A", "6123 4590 7781", "kabir@mail.com"],
[1103, 1, "Meher Gill", "B", "7712 3409 5566", "meher@mail.com"],
[1104, 2, "Rohan Das", "B", "3390 1287 4410", "rohan@mail.com"],
[1105, 3, "Aditi Rao", "B", "8845 2210 9034", "aditi.r@mail.com"],
]
def can_be_key(col):
values = [r[col] for r in rows]
no_null = None not in values
unique = len(values) == len(set(values))
return no_null and unique
for i, name in enumerate(header):
print(f"{name:10}", "candidate key" if can_be_key(i) else "-")AdmNo candidate key RollNo - SName - Section - AadhaarNo candidate key Email candidate key
Viva questions (4)
- Why compare len(values) with len(set(values))? A set removes duplicates, so equal lengths mean all values are unique.
- Why is RollNo rejected? Roll number 1 occurs in two sections.
- If only these five rows were present, would SName be accepted? No, because 'Aditi Rao' occurs twice. Even if it did not, names can repeat in real data, so it should not be a key.
- What does None represent here? A NULL value.
3Composite key test
A FEE relation stores (AdmNo, Month, Amount). Write a program to check whether AdmNo alone, Month alone, or the pair (AdmNo, Month) can uniquely identify each row. State the composite primary key.
# FEE relation: neither AdmNo nor Month is unique on its own
fee = [
(1101, "April", 2500), (1102, "April", 2500),
(1101, "May", 2500), (1102, "May", 2700),
(1103, "April", 2500),
]
adm = [r[0] for r in fee]
month = [r[1] for r in fee]
pair = [(r[0], r[1]) for r in fee]
print("AdmNo unique? ", len(adm) == len(set(adm)))
print("Month unique? ", len(month) == len(set(month)))
print("(AdmNo, Month) unique?", len(pair) == len(set(pair)))AdmNo unique? False Month unique? False (AdmNo, Month) unique? True
Viva questions (3)
- Why is AdmNo alone not unique in FEE? A student pays fees every month.
- What is a composite key? A primary key made of two or more attributes.
- Is AdmNo in FEE also a foreign key? Yes; it refers to STUDENT(AdmNo).
4Foreign-key validator
PARENT has primary key values 501 to 504. Write a program that checks every STUDENT row's ParentID and prints OK if it exists in PARENT, NULL if it is None, and INVALID otherwise.
# Check the foreign key STUDENT.ParentID -> PARENT.ParentID
parent_ids = [501, 502, 503, 504] # primary key of PARENT
students = [ # (AdmNo, SName, ParentID)
(1101, "Aditi Rao", 501),
(1102, "Kabir Singh", 502),
(1103, "Meher Gill", 509),
(1104, "Rohan Das", None),
(1105, "Ishaan Rao", 501),
]
for adm, name, pid in students:
if pid is None:
status = "NULL (allowed, parent not yet linked)"
elif pid in parent_ids:
status = "OK"
else:
status = "INVALID - no such ParentID in PARENT"
print(adm, name, pid, "->", status)1101 Aditi Rao 501 -> OK 1102 Kabir Singh 502 -> OK 1103 Meher Gill 509 -> INVALID - no such ParentID in PARENT 1104 Rohan Das None -> NULL (allowed, parent not yet linked) 1105 Ishaan Rao 501 -> OK
Viva questions (4)
- Why is 509 invalid? No parent with ID 509 exists in the referenced table.
- Is a repeated ParentID (501 twice) an error? No; siblings share a parent, so foreign key values may repeat.
- When can a foreign key not be NULL? When it is part of the primary key of its own table.
- Which table is the referenced (master) table here? PARENT.
5Seeing redundancy and inconsistency
Store a file-system style fee file in which the student's name is repeated in every row. Write a program to count how many redundant copies of names exist. Then simulate the office correcting a spelling only in its own file, and show that the two files are now inconsistent.
# File-system style: the fee file repeats the student's name every month
fee_file = [
(1101, "Aditi Rao", "April", 2500),
(1101, "Aditi Rao", "May", 2500),
(1101, "Aditi Rao", "June", 2500),
(1102, "Kabir Singh", "April", 2500),
(1102, "Kabir Singh", "May", 2500),
]
names_stored = len(fee_file)
distinct_students = len(set(r[0] for r in fee_file))
print("Names stored in fee file :", names_stored)
print("Students actually present:", distinct_students)
print("Redundant copies of names:", names_stored - distinct_students)
# Office corrects a spelling in its own file, but not in the fee file
office_file = {1101: "Aditi Rao"}
office_file[1101] = "Aditee Rao"
fee_names = set(r[1] for r in fee_file if r[0] == 1101)
print("Office file says:", office_file[1101])
print("Fee file says :", fee_names)
print("Inconsistent? :", office_file[1101] not in fee_names)Names stored in fee file : 5
Students actually present: 2
Redundant copies of names: 3
Office file says: Aditee Rao
Fee file says : {'Aditi Rao'}
Inconsistent? : TrueViva questions (3)
- How would a DBMS design avoid this? Store the name once in STUDENT and keep only AdmNo in FEE.
- Which comes first, redundancy or inconsistency? Redundancy; it makes inconsistency possible.
- Name one more file-system limitation visible here. Data isolation: the two files have no link.
6Design a library database (group activity)
A school library register has the columns: MemberAdmNo, MemberName, MemberClass, BookID, BookTitle, Author, IssueDate, ReturnDate. Convert it into three related relations. For each, write the schema, mark the primary key and foreign keys, and give the degree.
Model answer
MEMBER(AdmNo, MName, Class)
Primary key: AdmNo Degree 3
BOOK(BookID, Title, Author)
Primary key: BookID Degree 3
ISSUE(AdmNo, BookID, IssueDate, ReturnDate)
Primary key: (AdmNo, BookID, IssueDate) - composite
Foreign keys: AdmNo -> MEMBER(AdmNo)
BookID -> BOOK(BookID) Degree 4
ReturnDate may be NULL until the book is returned.
Member and book details are now stored once each.Viva questions (4)
- Why is IssueDate part of ISSUE's primary key? The same student may borrow the same book again on another date.
- Can ReturnDate be NULL? Yes; it is unknown until the book comes back, and it is not part of the key.
- Which tables are referenced by ISSUE? MEMBER and BOOK.
- What problem did splitting the register solve? Redundancy of member and book details, and the inconsistency it could cause.
Common mistakes
Confusing degree and cardinality. Correction: degree counts columns (attributes); cardinality counts rows (tuples). The header row is never counted in cardinality.
Writing that a table can have several primary keys. Correction: a table can have several candidate keys but only one primary key; that key may be composite.
Choosing Name as a primary key. Correction: names can repeat, so they cannot uniquely identify rows. Use an ID such as AdmNo.
Saying a primary key can be NULL "if the value is not known yet". Correction: a primary key can never be NULL.
Thinking a foreign key must be unique in its own table. Correction: foreign key values can repeat (many students, one parent); they must only match an existing primary key value.
Treating NULL as 0 or as a blank space. Correction: NULL means unknown or not applicable; 0 and " " are actual values.
Mixing up redundancy and inconsistency. Correction: redundancy is duplication; inconsistency is duplicates that no longer match. Redundancy leads to inconsistency.
Calling the database schema the data itself. Correction: the schema is the structure; the data at a given time is the instance.