Home / Computer Science / Class XI / Database Concepts
Database Concepts — CUET Computer Science hero
Class XI 💻 Computer Science Ch 18 of 19

Database Concepts

CUET unit: Database Concepts

📌 Snapshot

  • Why databases replaced files: DBMS, schema, relations and keys explained with a school attendance example.
  • The six problems of a file system, and how a database removes each one.
  • Degree, cardinality, domain and tuple, plus the three properties that make a relation more than a table.
  • Candidate, primary, alternate, composite and foreign keys, with worked examples and the traps NTA sets.

📖 Detailed Notes

Written and reviewed by Rohit Singh, Computer Science & Commerce faculty at UniDrill (MCA, Osmania University · 6 years teaching). Based on NCERT Informatics Practices Class XI, Chapter 7.

Why does the attendance register keep going wrong?

A class teacher marks P or A for 50 students on each of 26 working days. That is 1,300 entries a month, written by hand. A name is misspelled in March, a page is lost in April, and a total is added wrongly in May. Meanwhile the office keeps its own list of students and guardians, so the same names live in two places and nobody notices when they stop matching.

This chapter explains how a database fixes those problems, and then teaches you the vocabulary of the relational model, which is the most common design for databases and the base for all of SQL.

Files first: what goes wrong

Moving records from paper to computer files helps. You can copy the student list to a new file when the class is promoted, search for a student, add, edit and delete records. A file is simply a container for data, and the data can be text, CSV, pictures, audio or a web page. But to read data from a file inside a program, someone has to write code for it, and trouble starts as the files multiply.

Take two files from the school: a STUDENT file kept by the office (roll number, name, date of birth, guardian name, phone, address) and an ATTENDANCE file kept by the teacher (date, roll number, name, status).

Limitation What it means School example
Difficulty in access A file has no built in way to answer questions; you write a program for each new question "List students absent on both days" needs a new program
Data redundancy The same data is stored in more than one place Student name is in both files; two siblings share one guardian's name, phone and address, 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 related in real life but nothing links them, and they may have different formats STUDENT and ATTENDANCE both describe students, yet each needs a separate program
Data dependence Programs depend on the exact structure of the file Adding a column to STUDENT breaks every program that reads it
Controlled data sharing Hard to give each user only the access they need Guardians should only read attendance; only the class teacher may edit it

Why redundancy causes inconsistency. Redundancy is the cause and inconsistency is the effect. If a fact is stored once, it can only be wrong in one way. If it is stored twice, it can be right in one place and wrong in another. Students often learn the two as synonyms; keep them apart: redundancy is duplication, inconsistency is disagreement.

Pause and predict: two siblings, roll numbers 3 and 5, live with the same guardian, Himanshu Shah. In the single STUDENT file, how many times is his phone number stored, and what goes wrong if it changes?

Check your answer: Twice, once per sibling. If the office updates only one row, the file now holds two different phone numbers for the same person. That is redundancy leading to inconsistency.

The database management system (DBMS)

A database is a collection of logically related data organised so that it can be stored and managed efficiently. A database management system (DBMS) is the software used to create and manage databases: to store, update and retrieve data. Examples are MySQL, Oracle, PostgreSQL, SQL Server, Microsoft Access and MongoDB.

A DBMS hides how data is physically stored and gives users an abstract view of it. It sits between the data and the people (or programs) using it, so the teacher and the office staff can work on one shared, central copy at the same time. Asking the database for information is called querying, and you do it with a query language (SQL, in the next chapter).

Databases run banking (customers, accounts, loans, transactions), online shopping (items, users, orders), inventory systems, crop loan records, and employee and payroll systems in organisations.

Problem in a file system How a DBMS handles it
Difficulty in access Queries fetch any required data without writing a program
Redundancy and inconsistency Data is stored once and linked through common columns
Isolation Tables are related through keys, so they are not separate islands
Dependence The DBMS hides the storage details from programs
Controlled sharing The DBMS can give each user their own level of access

A DBMS is not free of drawbacks. It needs costly hardware and software, trained users and regular backups. It is more complex to run. And because the data is kept centrally, a hardware or software failure can halt work for everyone.

From files to a database

To convert the school files into a database, three changes are made. First, student name is removed from ATTENDANCE, since it can be fetched from STUDENT using the roll number. Second, the guardian details are moved into a separate GUARDIAN table, so each guardian is stored once. Third, a new column GUID (guardian ID) is added, with a unique value for each guardian, and the same column is also placed in STUDENT to link the two tables.

Why a new ID rather than the guardian's name? Two guardians can share a name. Why not the phone number? Phone numbers can change, so they do not reliably identify a person.

The result is three tables: STUDENT(RollNumber, SName, SDateofBirth, GUID), GUARDIAN(GUID, GName, GPhone, GAddress) and ATTENDANCE(AttendanceDate, RollNumber, AttendanceStatus).

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

Why it matters. Notice that roll number 3 has no GUID yet. The database accepts this because a foreign key may hold NULL, an idea we meet below. Once the guardian is known, one UPDATE fills it in.

Key terms of a DBMS

Term Meaning Example
Database schema The design: table names, columns, data types, constraints and relationships. It is the skeleton, with no data STUDENT(RollNumber, SName, SDateofBirth, GUID) and the types of each column
Data constraint A restriction on the values a column can hold, to keep data accurate and reliable RollNumber must be unique and not null; a mobile number must have 10 digits
Meta data (data dictionary) The schema and constraints, stored by the DBMS in its catalog. It is "data about data" The record that GPhone is a 10 digit column
Database instance The snapshot: the data in the database at one moment The 6 student rows today
Query A request to the database for information "Names of students present on 2018-09-01"
Data manipulation Changing data: insertion, deletion, update Adding a new student, removing one who left, changing a phone number
Database engine The component of the DBMS that creates databases and runs the queries The MySQL server program

Schema versus instance. The schema changes rarely; the instance changes all the time. Create an empty STUDENT table and you have a schema with an empty instance. Insert six rows and the same schema now has a different instance. Think of a blank school timetable form (the schema) versus the timetable filled in for this week (the instance).

Beyond the textbook. For the exam: the schema and constraints are stored as meta data in the database catalog. In reality: you can query that catalog like any other table. In MySQL, commands such as SHOW TABLES and DESC report what the catalog knows about your tables. Why it matters: "data about data" is not an abstract slogan; it is the reason a database can describe itself.

The relational model

A data model describes how data is defined and represented, how items relate and what constraints apply. The most widely used model is the relational data model, and a DBMS built on it is a relational database management system (RDBMS). Other models exist (object oriented, entity relationship, document and hierarchical), but this book uses the relational one.

In this model a table is called a relation, and relations in a database are linked to each other, not independent. ATTENDANCE is linked to STUDENT through RollNumber, and STUDENT is linked to GUARDIAN through GUID. Without those linking columns you could not retrieve valid combined information.

Term Meaning Also called
Relation A table Table
Attribute A column: a characteristic for which data is stored Column, field
Tuple A row: one real world entity's data Row, record
Domain The set of values an attribute can take, usually fixed by its data type Allowed values
Degree Number of attributes (columns) Column count
Cardinality Number of tuples (rows) Row count

Worked example: degree and cardinality. Find the degree and cardinality of the three tables in the school database.

Step What we do Result
1 GUARDIAN has GUID, GName, GPhone, GAddress Degree 4
2 GUARDIAN holds 5 guardian rows Cardinality 5
3 STUDENT has RollNumber, SName, SDateofBirth, GUID, with 6 rows Degree 4, cardinality 6
4 ATTENDANCE has AttendanceDate, RollNumber, AttendanceStatus, with 12 rows (6 students on 2 days) Degree 3, cardinality 12

The common wrong step is to count the header row as a tuple, or to swap the two words. A memory aid: degree counts across the header (columns), cardinality counts down the rows.

For domains, RollNumber takes integer values, so its domain is the set of integers, and SName takes character strings.

Three properties that make a relation special

A relation is not just any table. It obeys three groups of rules.

Property Rule Example
About attributes Each attribute has a unique name. The order of attributes does not matter GUARDIAN cannot have two columns called GName
About tuples Every tuple is distinct, so no two rows are identical in all attributes. The order of tuples does not matter Two rows of ATTENDANCE cannot be identical
About the state All values in a column come from the same domain. Each value is atomic (cannot be split into meaningful parts). A cell cannot hold many values. Unknown or not applicable values are stored as NULL GPhone holds one 10 digit number, never two numbers in one cell

NULL. NULL means a value that is unknown or does not apply. It is not zero and it is not an empty string. If a guardian has not shared a phone number, GPhone is NULL.

Beyond the textbook. For the exam: every tuple in a relation must be distinct. In reality: a table in an actual DBMS will happily store two identical rows if you never gave it a key. It is the primary key constraint that enforces the "distinct tuples" rule. Also, any calculation with NULL gives NULL, so 5 + NULL is NULL. Why it matters: this is why defining a primary key is part of designing every table.

Pause and predict: a class list for sports is stored as (Roll_no, Preference) with the rows (9, Cricket), (17, Badminton) and (17, Football). Which property of a relation is broken if each student may give only one preference?

Check your answer: Roll number 17 has two values for the preference, so the "one value per cell and unique identification" rule fails. Making Roll_no the primary key would stop the second row for roll number 17 from being accepted.

Keys: how a relation keeps rows distinct

Because tuples must be distinct, at least one attribute (or group) must hold different, non-null values in every row. These are the keys.

Key Meaning In the school database
Candidate key Any attribute (or set) that can uniquely identify every tuple. They are candidates for the primary key In GUARDIAN: GUID and GPhone
Primary key The one candidate 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 RollNumber and AttendanceDate together in ATTENDANCE
Foreign key An attribute in one relation that refers to the primary key of another relation GUID in STUDENT; RollNumber in ATTENDANCE

The relation that holds the foreign key is the referencing (foreign) relation; the relation whose primary key is referred to is the referenced (primary or master) relation. A foreign key may be NULL unless it is part of that table's primary key.

Worked example: choosing keys for ATTENDANCE. Which attribute or attributes can be the primary key of ATTENDANCE(AttendanceDate, RollNumber, AttendanceStatus)?

Step What we test Verdict
1 RollNumber alone: roll number 1 appears once for every date Not unique
2 AttendanceDate alone: each date is repeated for every student Not unique
3 AttendanceStatus alone: only P or A Not unique
4 RollNumber and AttendanceDate together: a student is marked once on a given day Unique for every row
5 Conclusion Composite primary key {RollNumber, AttendanceDate}

The wrong move is to pick RollNumber because "it identifies the student". It does, but the question is what identifies a row, and a row is one student on one day.

Why a foreign key can be NULL. A foreign key only says "if there is a value, it must exist in the other table". Roll number 3 has no guardian recorded yet, so GUID is NULL and no rule is broken. This is not allowed when the foreign key is also part of the primary key, because a primary key attribute can never be NULL. In ATTENDANCE, RollNumber is both a foreign key and part of the primary key, so it can never be NULL.

Beyond the textbook. For the exam: GUID is chosen as the primary key and GPhone becomes an alternate key. In reality: designers often avoid keys taken from the real world, such as phone numbers or government ID numbers, because they can change or may be sensitive. A neutral auto generated number is common. Why it matters: a key must stay the same for the life of the row, otherwise every table that refers to it breaks.

Exam traps

Trap Why it is tempting The truth
"Degree is the number of rows" The word sounds like size Degree is the number of attributes; cardinality is the number of tuples
"A table and a relation are exactly the same" The book uses them as synonyms A relation also obeys rules: unique attributes, distinct tuples, atomic values
"Schema and instance mean the same" Both describe the database Schema is the design; instance is the data at a moment
"Redundancy and inconsistency are identical" They arrive together Redundancy is duplication; inconsistency is disagreement between copies
"A foreign key can never be NULL" Keys sound strict It can be NULL if it is not part of the primary key
"A candidate key and the primary key are different attributes" Different names The primary key is one of the candidate keys; the rest are alternate keys
"Data about data is the data itself" Both are stored in the database Meta data describes the structure and constraints; it is stored in the catalog
"ATTENDANCE can use RollNumber as the primary key" Roll number identifies a student It repeats on every date, so a composite key is needed

60-second revision

Topic Remember
File system problems Access, redundancy, inconsistency, isolation, dependence, controlled sharing
DBMS Software to create and manage databases: MySQL, Oracle, PostgreSQL, SQL Server, MS Access, MongoDB
DBMS drawbacks Cost, complexity, a single failure point
Schema The design (skeleton); stored as meta data in the catalog
Instance A snapshot of the data at one time
Relation terms Relation is table, attribute is column, tuple is row
Degree and cardinality Degree is columns; cardinality is rows
Relation properties Unique attribute names, distinct tuples, atomic values, one domain per column
NULL Unknown or not applicable, not zero
Keys Candidate, primary, alternate, composite, foreign

Where this chapter connects

Everything here is put to work in Introduction to Structured Query Language (SQL), where you create the StudentAttendance database, add the primary and foreign keys with SQL and query it. The quality of the data you store is the theme of Understanding Data. In Class XII the same ideas continue in Database Concepts and Querying and SQL Functions, where two tables are combined through their keys.

🎯 Practice MCQs

First 3 questions free · create a free account to unlock the rest — answers & explanations included, no payment needed

Q1. In a file system, the same guardian's address is stored once for each of two siblings. This problem is called

▸ Show answer & explanation

Answer: C

Storing the same data in more than one place is redundancy. Inconsistency (A) is what happens later if the copies stop matching. Isolation (B) is about files that cannot be linked, and dependence (D) is about programs breaking when file structure changes.

Q2. A student corrects the spelling of her name in the STUDENT file but not in the ATTENDANCE file, so the two files now show different spellings. This is

▸ Show answer & explanation

Answer: B

Copies of the same data that no longer match are inconsistent. Redundancy (A) is only the duplication. Controlled sharing (C) deals with who may access what. An instance (D) is a snapshot of data, so it does not name the problem.

Q3. The design of a database, covering table names, columns, data types, constraints and relationships, is called the

▸ Show answer & explanation

Answer: C

The schema is the skeleton of the database. The instance (A) is the data at a moment, a query (B) is a request for information, and the engine (D) is the software component that runs queries.

🔒 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.

📊 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