📌 Snapshot
- Why schools, banks and shops moved from registers and files to databases, and how keys hold tables together.
- The six problems of a file system and how a DBMS fixes them, compared side by side in one table.
- Schema, instance, degree, cardinality and the five keys explained on a school attendance database.
- Worked examples that decide which rows an insert is allowed to add, with the reason for each refusal.
📖 Detailed Notes
Written and reviewed by Rohit Singh, Computer Science & Commerce faculty at UniDrill (MCA, Osmania University · 6 years teaching). Based on NCERT Computer Science Class XII, Chapter 8.
What goes wrong when a school keeps attendance in a register?
A class of 50 students and 26 working days means 50 × 26 = 1,300 entries every month, all written by hand. A student is promoted, and every name must be copied into a new register. A page is torn, and a month of attendance is gone. Someone misspells a name in one place. The office keeps the same students' details in another file, so now two records of the same child disagree. Finding one student's guardian means turning through papers. The fix is to store the data in a computer, and the better fix is to store it in a database. This chapter shows why, and what a database looks like inside.
Files and their limits
A file is a container that stores data on a computer: text, program code, a CSV file, pictures, audio, video and web pages are all files. A file can be searched directly, but to show something on a website, such as a monthly attendance report, someone must write a program to read the file.
The school example uses two files. The office keeps a STUDENT file (RollNumber, SName, SDateofBirth, GName, GPhone, GAddress), and the class teacher keeps an ATTENDANCE file (AttendanceDate, RollNumber, SName, AttendanceStatus). Having two such files shows six limitations of the file system.
| Limitation | What it means | Example from the school |
|---|---|---|
| Difficulty in access | Files give no way to retrieve data; a program must be written for every new kind of request | Printing a report in a new format needs a new program |
| Data redundancy | The same data is stored in more than one place | SName is in both files; two siblings share one guardian name, stored twice |
| Data inconsistency | Copies of the same data stop matching | A name is corrected in STUDENT but not in ATTENDANCE |
| Data isolation | Files are separate, with no link or mapping between them, and may have different formats | Two programs are needed to read the two files |
| Data dependence | Programs depend on the file's structure; changing the structure breaks them | Adding a column to STUDENT forces every program using it to be changed |
| Controlled data sharing | It is hard to give each user only the access they should have | Parents should see attendance but not edit it; only the teacher may update it |
Redundancy and inconsistency are linked but not the same thing. Redundancy is the duplication; inconsistency is the damage that duplication causes when one copy is changed and the other is not. Store the name once, and there is no second copy left to disagree with it.
Database management system (DBMS)
A database is a collection of logically related data organised in tables. A database management system (DBMS) is the software used to create and manage databases, and to store, update and retrieve the data in them. Examples are MySQL, Oracle, PostgreSQL, SQL Server, Microsoft Access and MongoDB. The DBMS sits between the data and the users or programs, and hides how the data is physically stored, which gives users an abstract view. Retrieving data by a command is called querying the database.
Databases run banking (customer, account, loan and transaction data), crop loans (kisan credit card, land and repayment data), inventory (products, orders, delivery), organisation resource management (employees, salaries, departments) and online shopping (item descriptions, user logins, preferences).
How the school files become a database. Three changes remove the problems.
| Change | Why |
|---|---|
| Drop SName from ATTENDANCE and look it up through RollNumber | The name is stored once, so redundancy and inconsistency fall |
| Split STUDENT into STUDENT and GUARDIAN | Siblings share one guardian row, stored once |
| Add a GUID (guardian ID) to GUARDIAN and keep it in STUDENT too | Guardians can share names, so a unique ID is needed to link a student to the correct guardian |
A phone number could have served as the link, but phone numbers change, so they may not truly identify a guardian. The tables now look like this (the full attendance table has 12 rows, of which the first six are shown).
| RollNumber | SName | SDateofBirth | GUID |
|---|---|---|---|
| 1 | Atharv Ahuja | 2003-05-15 | 444444444444 |
| 2 | Daizy Bhutia | 2002-02-28 | 111111111111 |
| 3 | Taleem Shah | 2002-02-28 | NULL |
| 4 | John Dsouza | 2003-08-18 | 333333333333 |
| 5 | Ali Shah | 2003-07-05 | 101010101010 |
| 6 | Manika P. | 2002-03-10 | 466444444666 |
The GUARDIAN table:
| GUID | GName | GPhone | GAddress |
|---|---|---|---|
| 444444444444 | Amit Ahuja | 5711492685 | G-35, Ashok Vihar, Delhi |
| 111111111111 | Baichung Bhutia | 3612967082 | Flat no. 5, Darjeeling Appt., Shimla |
| 101010101010 | Himanshu Shah | 4726309212 | 26/77, West Patel Nagar, Ahmedabad |
| 333333333333 | Danny Dsouza | NULL | S -13, Ashok Village, Daman |
| 466444444666 | Sujata P. | 3801923168 | HNO-13, B- block, Preet Vihar, Madurai |
And the first rows of ATTENDANCE (one row per student per day):
| AttendanceDate | RollNumber | AttendanceStatus |
|---|---|---|
| 2018-09-01 | 1 | P |
| 2018-09-01 | 2 | P |
| 2018-09-01 | 3 | A |
| 2018-09-01 | 4 | P |
| 2018-09-01 | 5 | A |
| 2018-09-01 | 6 | P |
A DBMS keeps one central copy of the data that many users, such as the office staff and the teacher, can use at the same time.
Why it matters. The cost of moving from files to a DBMS is real: buying better hardware and software, training people to write queries, and the recurring cost of backups and recovery. Putting all the data in one place also increases complexity (security, consistency, sharing and integrity must all be managed) and vulnerability, because a hardware or software failure can stop every user at once. Those are the stated limitations of a DBMS.
Key terms of a DBMS
| Term | Meaning | Example |
|---|---|---|
| Database schema | The design of the database: table names, columns, the type of data each column holds, constraints and relationships; the skeleton, or logical architecture | STUDENT(RollNumber, SName, SDateofBirth, GUID) and the other two tables |
| Data constraint | A restriction on what can be inserted in a column, to keep data accurate and reliable | RollNumber must be NOT NULL and UNIQUE; a mobile number must be a 10 digit integer |
| Meta-data (data dictionary) | The schema and the constraints, stored by the DBMS in the database catalog; data about data | The catalog entry that says GUID is a 12 character key |
| Database instance | The state, or snapshot, of the database at a given moment, after data has been loaded | The rows in the tables today |
| Query | A request to the database to obtain information in a desired way | "Find the names of all students present on 2018-09-01" |
| Data manipulation | Insertion, deletion and update of data | See below |
| Database engine | The underlying component, or set of programs, that a DBMS uses to create a database and handle queries | Software inside MySQL |
When a database is first defined (the schema), it is empty. After data is loaded it has an instance, and the instance keeps changing as rows are inserted, updated or deleted. So one schema can have many instances at different times, but the instance at any one moment is a single snapshot.
Data manipulation has three operations. Insertion adds a row (a new student, Rivaan, must be added to STUDENT and GUARDIAN). Deletion removes rows (when a student leaves, his or her data and guardian details are removed from STUDENT, GUARDIAN and ATTENDANCE). Update changes values (a guardian's new mobile number goes into GPhone).
File system and DBMS compared
| Feature | File system | DBMS |
|---|---|---|
| Access to data | A program for each request | Queries in a query language |
| Redundancy | Common | Reduced, since each fact is stored once |
| Consistency | Copies can disagree | Maintained through central control |
| Linking of data | No mapping between files | Tables linked through keys |
| Program dependence on structure | High | Lower, as the DBMS hides storage details |
| Access control | Hard to enforce | Different permissions for different users |
| Cost | Low | Hardware, software, training and backup cost |
Pause and predict: After the split, the school stores the guardian's address only in GUARDIAN. Atharv's guardian moves house. How many places must be updated, and what does this tell you about redundancy?
Check your answer: One place, the GUARDIAN row for GUID 444444444444. Every student record linked to this GUID sees the new address automatically. Because the address is stored once, there is no second copy that can go out of date, which is how a DBMS removes redundancy and inconsistency.
The relational data model
Databases are classified by the data model they use. A data model describes how data is defined and represented, how items relate to one another, and what constraints apply. The most common is the relational data model; others are object oriented, entity relationship, document and hierarchical models. A database built on the relational model is a relational database, and its management software is an RDBMS.
In the relational model a table is called a relation. The terms of the relational model are these.
| Term | Meaning | In the GUARDIAN relation |
|---|---|---|
| Relation | A table of data | GUARDIAN |
| Attribute | A column; a characteristic stored for the relation (also called a field) | GUID, GName, GPhone, GAddress |
| Tuple | A row; one real world entity or record | One guardian's row |
| Domain | The set of values an attribute may take, usually given by its data type | RollNumber takes integers; SName takes character strings |
| Degree | The number of attributes | 4 |
| Cardinality | The number of tuples | 5 |
Worked example: degree and cardinality. Use the three tables above (ATTENDANCE has 12 rows: two days of attendance for six students).
| Relation | Attributes | Degree | Rows | Cardinality |
|---|---|---|---|---|
| STUDENT | RollNumber, SName, SDateofBirth, GUID | 4 | 6 | 6 |
| GUARDIAN | GUID, GName, GPhone, GAddress | 4 | 5 | 5 |
| ATTENDANCE | AttendanceDate, RollNumber, AttendanceStatus | 3 | 12 | 12 |
The trap is to swap them. Remember that degree is the width (columns) and cardinality is the count (rows). If a new student joins, cardinality goes up by one while degree stays the same. If a column is added, degree goes up while cardinality stays the same.
Pause and predict: A relation has 7 tuples and 5 attributes. After deleting 2 tuples and adding 1 attribute, what are its degree and cardinality?
Check your answer: Degree 6 and cardinality 5. Deleting tuples changes the row count (7 minus 2 is 5), and adding an attribute changes the column count (5 plus 1 is 6).
Beyond the textbook. For the exam: a table is a relation and a row is a tuple. In reality: in "relational", the word "relation" does not mean the relationship between tables. It is the mathematical name for a table itself. The links between tables are made by keys. Also, not every DBMS is relational. MongoDB, which appears among the examples in this chapter, uses the document model instead of tables.
Three properties of a relation
A relation is different from an ordinary table or data file because it obeys three properties.
| Property | Rule | What it means in practice |
|---|---|---|
| About attributes | Each attribute has a unique name; the sequence of attributes does not matter | You cannot have two columns called GName; reordering columns changes nothing |
| About tuples | Each tuple is distinct (no two rows are identical in every attribute); the sequence of tuples does not matter | Duplicate rows are not allowed; rows have no built in order |
| About values | All values in an attribute come from the same domain; each value is atomic; an attribute cannot hold many values in one tuple; unknown values are stored as NULL | GPhone holds one 10 digit number per guardian, not a list of phones |
NULL is a special value for a value that is unknown or not applicable. If a guardian has not given a phone number, GPhone is NULL. NULL is not zero and not an empty string.
Worked example: are these two relations the same? Two class sections each list their sports preferences.
Section 1 (arranged on Roll_no):
| Roll_no | Sports |
|---|---|
| 9 | Cricket |
| 13 | Football |
| 17 | Badminton |
| 21 | Hockey |
| 24 | Cricket |
Section 2 (arranged on sports name, with the columns in the other order):
| Sports | Roll_no |
|---|---|
| Badminton | 17 |
| Cricket | 9 |
| Cricket | 24 |
| Football | 13 |
| Hockey | 21 |
Both contain exactly the same five tuples: (9, Cricket), (13, Football), (17, Badminton), (21, Hockey), (24, Cricket). The order of tuples and the order of attributes are immaterial, so the two relations have the same state.
Keys in a relational database
No two tuples may be identical, so there must be at least one attribute whose values are distinct and not NULL, which can pick out a single tuple. Keys are the constraints that make this work and that link relations to one another.
| Key | Definition | In the school database |
|---|---|---|
| Candidate key | Any attribute (or set) that takes distinct values and can identify tuples; a candidate for primary key | In GUARDIAN: GUID and GPhone |
| Primary key | The candidate key chosen by the designer to identify tuples | GUID |
| Alternate key | A candidate key that was not chosen as primary | GPhone |
| Composite primary key | A primary key made of more than one attribute, used when no single attribute is unique | {AttendanceDate, RollNumber} in ATTENDANCE |
| Foreign key | An attribute whose values come from the primary key of another relation; it links the two relations | GUID in STUDENT; RollNumber in ATTENDANCE |
Why ATTENDANCE needs a composite key. RollNumber alone repeats, because the same student appears on every date. AttendanceDate alone repeats, because the same date appears for every student. But a student is marked only once on a given day, so the pair {RollNumber, AttendanceDate} is always unique and together they form the primary key.
Foreign keys connect, and they may be NULL. The relation that holds the foreign key is the referencing (foreign) relation; the one whose primary key it points to is the referenced (primary or master) relation. In the school database there are two foreign keys: GUID in STUDENT refers to GUID in GUARDIAN, and RollNumber in ATTENDANCE refers to RollNumber in STUDENT. In some cases a foreign key can be NULL if it is not part of the primary key of its own table. That is why the row for Taleem Shah can exist with GUID NULL while the guardian is not yet recorded.
Worked example: which inserts will the database accept? Assume the keys above are enforced: the primary key of ATTENDANCE is {AttendanceDate, RollNumber}, RollNumber is a foreign key to STUDENT, and the existing STUDENT rows are roll numbers 1 to 6.
| Row to insert into ATTENDANCE | Accepted? | Reason |
|---|---|---|
| ('2018-09-03', 3, 'A') | Yes | The key pair is new and roll number 3 exists in STUDENT |
| ('2018-09-01', 3, 'P') | No | The pair ('2018-09-01', 3) already exists; the primary key must be unique |
| ('2018-09-03', 9, 'A') | No | Roll number 9 is not in STUDENT; a foreign key must refer to an existing primary key value (or be NULL if allowed) |
| (NULL, 3, 'P') | No | AttendanceDate is part of the primary key, so it cannot be NULL |
Beyond the textbook. For the exam: GUID and GPhone are both candidate keys of GUARDIAN, and GUID is chosen as the primary key. In reality: GPhone is a weak choice for a key, because phone numbers change and some guardians have none, as the NULL for Danny Dsouza shows. A primary key must always have a value, which is why an artificial ID such as GUID is preferred.
Exam traps
| The trap | Why it's tempting | The truth |
|---|---|---|
| "Redundancy and inconsistency are the same." | Both come from duplicate data | Redundancy is the duplication; inconsistency is copies that no longer match |
| "Degree is the number of rows." | Degree sounds like size | Degree = number of attributes (columns); cardinality = number of tuples (rows) |
| "NULL means zero." | Both look like nothing | NULL means unknown or not applicable; it is not zero or blank |
| "A foreign key must be unique and not NULL." | It copies a primary key | It can repeat, and can be NULL if not part of the table's own primary key |
| "A table can have only one candidate key." | Only one primary key is allowed | There can be several candidate keys; one becomes the primary key, the rest are alternate keys |
| "Schema changes whenever data is inserted." | Both describe the database | Schema is the design and is fixed; the instance changes with every insert, update or delete |
| "A relation is the link between two tables." | The word suggests a relationship | A relation is a table; keys create the links |
| "The order of rows in a relation matters." | Tables are shown in an order | The sequence of tuples and attributes is immaterial |
60-second revision
| Topic | Lock this in |
|---|---|
| File system problems | Access, redundancy, inconsistency, isolation, dependence, controlled sharing |
| DBMS | Software to create and manage databases; examples MySQL, Oracle, PostgreSQL, SQL Server, MS Access, MongoDB |
| DBMS limits | Complexity, vulnerability (central failure), cost |
| Schema / instance | Design (fixed) / snapshot (changes) |
| Meta-data | Schema and constraints in the data dictionary; data about data |
| Manipulation | Insertion, deletion, update |
| Relational terms | Relation = table, attribute = column, tuple = row |
| Degree / cardinality | Number of columns / number of rows |
| Relation properties | Unique attribute names, distinct tuples, atomic values from one domain; order immaterial |
| Keys | Candidate, primary, alternate, composite primary, foreign |
Where this chapter connects
- Previous: Understanding Data introduces data storage and the limits of file processing that this chapter solves.
- Next: Structured Query Language (SQL) uses the same StudentAttendance database to create tables, add the keys and write queries.
- Class XI link: Database Concepts (Class XI) is the first look at tables and records.
🎯 Practice MCQs
First 3 questions free · create a free account to unlock the rest — answers & explanations included, no payment needed
Q1. A student's name is stored in two files. It is corrected in one file but not in the other. Which problem has occurred?
▸ Show answer & explanation
Answer: B
Inconsistency means copies of the same data no longer match. Data isolation is the lack of a link between files, data dependence ties programs to file structure, and controlled sharing is about who may see or change data.
Q2. Which of the following is NOT a limitation of the file system?
▸ Show answer & explanation
Answer: D
An abstract view, which hides how data is stored, is what a DBMS provides. The other three are limitations of the file system.
Q3. A relation has 5 attributes and 8 tuples. What are its degree and cardinality?
▸ Show answer & explanation
Answer: B
Degree is the number of attributes (5) and cardinality is the number of tuples (8). Option A swaps them, and the other options combine the numbers wrongly.
🔒 12 more practice MCQs
Create a free account to unlock every MCQ in this chapter — answers and explanations included. No payment needed.
Already registered? Just log in and they'll all appear here.
Q4. Assertion (A): A foreign key can take the value NULL in some cases. Reason (R): A foreign key that is not part of the primary key of its own relation may be left without a value when the referenced record is not yet known.
▸ Show answer & explanation
Answer: A
A foreign key that is not part of its own table's primary key may be NULL, for example a student whose guardian is not yet recorded. R gives exactly that condition.
Q5. In the ATTENDANCE relation of a school, a student is marked once per day. Which is the most suitable primary key?
▸ Show answer & explanation
Answer: D
RollNumber repeats on every date and AttendanceDate repeats for every student, and AttendanceStatus has only two values. The pair of RollNumber and AttendanceDate is unique, so it forms a composite primary key.
Q6. The GUARDIAN relation has candidate keys GUID and GPhone. If GUID is chosen as the primary key, GPhone is called
▸ Show answer & explanation
Answer: C
A candidate key that is not chosen as the primary key is called an alternate key. A foreign key refers to another relation, and a composite key has more than one attribute.
Q7. Which of the following describes the database schema?
▸ Show answer & explanation
Answer: B
The schema is the skeleton or design of the database. Option A describes the instance, option C a query and option D the DBMS.
Q8. Statement I: One database schema can have many database instances at different times. Statement II: The schema changes every time a row is inserted. Which is correct?
▸ Show answer & explanation
Answer: A
Inserting, deleting or updating rows changes the instance, not the schema, so Statement II is false. Statement I is true, since the same design can hold different data at different times.
Q9. A table STUDENT has an attribute GUID that refers to the primary key GUID of table GUARDIAN. Which table is the referenced (master) relation?
▸ Show answer & explanation
Answer: B
The referenced relation is the one in which the primary key being pointed to is defined, which is GUARDIAN. STUDENT, which holds the foreign key, is the referencing relation.
Q10. Which of the following is a property of a relation?
▸ Show answer & explanation
Answer: C
Every value in a relation must be atomic, meaning not divisible into meaningful parts. Tuples must be distinct, their order does not matter, and a tuple cannot hold many values in one attribute.
Q11. Match List I with List II. List I: (i) Candidate key (ii) Composite primary key (iii) Foreign key (iv) Meta-data. List II: (p) Primary key made of more than one attribute (q) Data about data stored in the data dictionary (r) Attribute that refers to the primary key of another relation (s) Attribute that can be chosen as primary key
▸ Show answer & explanation
Answer: A
A candidate key is a candidate for primary key, a composite primary key has more than one attribute, a foreign key refers to another relation's primary key, and meta-data is data about data. The other options swap two or more of these.
Q12. In a school database, a new student is added to STUDENT, so the table now has one more row and no additional column. What changes?
▸ Show answer & explanation
Answer: B
A new row is a new tuple, so cardinality increases. The number of attributes, and therefore the degree and the schema, remain the same. Only the instance changes.
Q13. A DBMS reduces redundancy mainly because
▸ Show answer & explanation
Answer: A
Storing each fact once, for example the guardian details in GUARDIAN, and linking with keys removes duplicate copies. Making copies or removing keys would increase problems instead.
Q14. Which of the following is a limitation of using a DBMS?
▸ Show answer & explanation
Answer: C
Keeping data centrally increases vulnerability, since a hardware or software failure can halt every user. Options A, B and D are problems of the file system that a DBMS solves.
Q15. Which row can be inserted into ATTENDANCE if its primary key is {AttendanceDate, RollNumber}, RollNumber is a foreign key to STUDENT, STUDENT has roll numbers 1 to 6, and ('2018-09-01', 3) already exists?
▸ Show answer & explanation
Answer: C
Row C has a new key pair and a roll number that exists in STUDENT. Row A repeats an existing key pair, row B uses roll number 8 that does not exist in STUDENT, and row D has NULL in a primary key attribute.
📊 Previous-Year Questions
Practise with real CUET Computer Science previous-year papers — every question solved, with the correct answer and a step-by-step explanation.
View solved CUET PYQ papers →Ready to drill Computer Science?
Unlock all MCQs, chapter tests, mocks & PYQs for ₹199/year.
Get UniDrill Pro