KnowledgeBoat Logo
OPEN IN APP

Chapter 8

Database Concepts

Class 12 - NCERT Computer Science Solutions



Exercise

Question 1

Give the terms for each of the following:

(a) Collection of logically related records.

(b) DBMS creates a file that contains description about the data stored in the database.

(c) Attribute that can uniquely identify the tuples in a relation.

(d) Special value that is stored when actual data value is unknown for an attribute.

(e) An attribute which can uniquely identify tuples of the table but is not defined as primary key of the table.

(f) Software that is used to create, manipulate and maintain a relational database.

Answer

(a) Table

(b) Data dictionary

(c) Primary key

(d) NULL

(e) Alternate Key

(f) Database Management System (DBMS)

Question 2

Why foreign keys are allowed to have NULL values? Explain with an example.

Answer

A null value can be entered in a foreign key, indicating that the records are not related. In certain situations, a foreign key may accept a NULL value if it's not a part of the primary key of the foreign table.

For example, consider an Orders table in a database. Each order may or may not be associated with a customer. If an order is placed by a guest or a new customer who hasn't been added to the system yet, the CustomerID foreign key in the Orders table can be NULL to indicate that there is no associated customer record for that order.

Question 3(a)

Differentiate between database state and database schema.

Answer

Database stateDatabase schema
The data stored in database at a particular moment of time (i.e., the state of the database at a particular instance of time) is called database state or instance of database.The database schema defines the design, structure, and organization of the database, serving as the blueprint or skeleton that determines how data is organized and related within the database.

Question 3(b)

Differentiate between primary key and foreign key.

Answer

Primary KeyForeign Key
Primary Key is a column or group of columns in a table that uniquely identify every row in that table.A foreign key is an attribute whose value is derived from the primary key of another table. A foreign key is used to represent the relationship between two tables.
Primary key cannot have Null values.Foreign key can have Null values.
There can be only one primary key in a table.Multiple foreign keys can exist in a table.
It is used to enforce entity integrity and ensure data uniqueness.It is used to enforce referential integrity and maintain data consistency across related tables.

Question 3(c)

Differentiate between degree and cardinality of a relation.

Answer

Degree of a relationCardinality of a relation
The number of attributes in a relation is called the Degree of the relation.The number of tuples in a relation is called the Cardinality of the relation.
For example, if a relation has attributes like Name, Age, and Address, then its degree is 3.For example, if a relation contains 10 records or tuples, then its cardinality is 10.

Question 4

Compared to a file system, how does a database management system avoid redundancy in data through a database?

Answer

A database stores the data at a central location wherefrom all application programs can access data. This removes the need of saving own data by application program and thus it reduces data redundancy.

Question 5

What are the limitations of file system that can be overcome by a relational DBMS?

Answer

The limitations of file system overcome by a relational DBMS are as follows:

  1. Data Redundancy
  2. Data Inconsistency
  3. Data Isolation
  4. Data Dependence
  5. Difficulty in data access
  6. Controlled data sharing

Question 6

A school has a rule that each student must participate in a sports activity. So each one should give only one preference for sports activity. Suppose there are five students in a class, each having a unique roll number. The class representative has prepared a list of sports preferences as shown below. Answer the following:

Table: Sports Preferences

Roll_noPreference
9Cricket
13Football
17Badminton
17Football
21Hockey
24NULL
NULLKabaddi
  1. Roll no 24 may not be interested in sports. Can a NULL value be assigned to that student’s preference field ?
  2. Roll no 17 has given two preferences in sports. Which property of relational DBMS is violated here ? Can we use any constraint or key in the relational DBMS to check against such violation, if any?
  3. Kabaddi was not chosen by any student. Is it possible to have this tuple in the Sports Preferences relation ?

Answer

  1. In a relational database model where each student is required to have exactly one preference for a sports activity, assigning a NULL value to Roll no 24's preference field is not permitted.
  2. The primary key constraint ensures uniqueness in a relational database table. If Roll no 17 has two sports preferences, it violates this rule because a primary key constraint on "Roll_no" would not allow different values for the same roll number. By using a primary key constraint on "Roll_no," the relational database management system (DBMS) can prevent such violations by rejecting attempts to insert rows with duplicate roll numbers.
  3. No, since no student has selected Kabaddi as their preferred sport, there should not be an entry for Kabaddi in the Sports Preferences table.

Question 7

In another class having 2 sections, the two respective class representatives have prepared 2 separate Sports Preferences tables, as shown below:

Sports preference of section 1 (arranged on roll number column)

Table: Sports Preferences

Roll_noSports
9Cricket
13Football
17Badminton
21Hockey
24Cricket

Sports preference of section 2 (arranged on Sports name column, and column order is also different)

Table: Sports Preferences

SportsRoll_no
Badminton17
Cricket9
Cricket24
Football13
Hockey21

Are the states of both the relations equivalent? Justify.

Answer

Yes, the states of both the relations are equivalent as the order of rows and columns does not matter and data is just the same in both the relations.

Question 8

The school canteen wants to maintain records of items available in the school canteen and generate bills when students purchase any item from the canteen. The school wants to create a canteen database to keep track of items in the canteen and the items purchased by students. Design a database by answering the following questions:

(a) To store each item name along with its price, what relation should be used? Decide appropriate attribute names along with their data type. Each item and its price should be stored only once. What restriction should be used while defining the relation ?

(b) In order to generate bill, we should know the quantity of an item purchased. Should this information be in a new relation or a part of the previous relation ? If a new relation is required, decide appropriate name and data type for attributes. Also, identify appropriate primary key and foreign key so that the following two restrictions are satisfied:

  1. The same bill cannot be generated for different orders.
  2. Bill can be generated only for available items in the canteen.

(c) The school wants to find out how many calories students intake when they order an item. In which relation should the attribute 'calories' be stored?

Answer

(a) To store each item name along with its price in the canteen database, we can create a relation (table) called "Items" with the following attributes:

Items table

AttributesDatatypeConstraints
ItemNoIntegerPrimary Key, Unique, non-null value
ItemNameVARCHARNon-null value
PriceFloatNon-null value

The restriction that should be used while defining the "Items" relation is to set the "ItemNo" attribute as the primary key. This ensures that each item number is unique and that each item and its price are stored only once in the database.

(b) Yes, the item sale information should be stored in a separate relation, say "SaleOrders".

SaleOrders table

AttributesDatatypeConstraints
ordernointegerPrimary Key Unique, Non-null value
ItemNointegerForeign key,Unique, Non-null value
QuantityintegerNon-null value
PriceFloatNon-null value

With this design, we satisfy both restrictions:

Each order has a unique OrderNo, ensuring that the same bill cannot be generated for different orders. The foreign key constraint on ItemNo ensures that bills can only be generated for available items in the canteen.

(c) 'Calories' should be stored in the "Items" table because they are directly associated with specific items.

Question 9

An organisation wants to create a database EMPDEPENDENT to maintain following details about its employees and their dependent.

EMPLOYEE(AadharNumber, Name, Address, Department, EmployeeID)
DEPENDENT(EmployeeID, DependentName, Relationship)

(a) Name the attributes of EMPLOYEE, which can be used as candidate keys.

(b) The company wants to retrieve details of dependent of a particular employee. Name the tables and the key which are required to retrieve this detail.

(c) What is the degree of EMPLOYEE and DEPENDENT relation?

Answer

(a) In the EMPLOYEE table, the attributes AadharNumber and EmployeeID can be used as candidate keys. This means that either AadharNumber or EmployeeID can uniquely identify each record in the EMPLOYEE table.

(b) The EMPLOYEE and DEPENDENT tables are linked using the EmployeeID key, which is utilized to retrieve details of dependents associated with a specific employee.

(c) In the EMPLOYEE relation, there are five attributes, resulting in a degree of 5. Similarly, the DEPENDENT relation has three attributes, making its degree 3.

Question 10

School uniform is available at M/s Sheetal Private Limited. They have maintained SCHOOL_UNIFORM Database with two relations viz. UNIFORM and COST. The following figure shows database schema and its state.

School Uniform Database

Attributes and Constraints

Table: UNIFORM

AttributeUCodeUNameUColor
ConstraintsPrimary KeyNot Null-

Table: COST

AttributeUCodeSizePrice
ConstraintsComposite Primary Key>0

Table: UNIFORM

UCodeUNameUColor
1ShirtWhite
2PantGrey
3SkirtGrey
4TieBlue
5SocksBlue
6BeltBlue

Table: COST

UCodeSizeCOST Price
1M500
1L580
1XL620
2M810
2L890
2XL940
3M770
3L830
3XL910
4S150
4L170
5S180
5L210
6M110
6L140
6XL160

(a) Can they insert the following tuples to the UNIFORM Relation ? Give reasons in support of your answer.

  1. 7, Handkerchief, NULL
  2. 4, Ribbon, Red
  3. 8, NULL, White

(b) Can they insert the following tuples to the COST Relation ? Give reasons in support of your answer.

  1. 7, S, 0
  2. 9, XL, 100

Answer

(a)

1. Tuple (7, Handkerchief, NULL): This tuple can be inserted because there is no constraint mentioned in the schema that prohibits NULL values for the UColor attribute.

2. Tuple (4, Ribbon, Red): This tuple can be inserted as all attributes have valid non-null values.

3. Tuple (8, NULL, White): This tuple cannot be inserted because UName attribute cannot be NULL as per the schema constraints.

(b)

1. Tuple (7, S, 0): This tuple cannot be inserted because the COST Price attribute must be greater than 0 as per the schema constraints.

2. Tuple (9, XL, 100): This tuple can be inserted as all attributes have valid values and the COST Price is greater than 0.

Question 11

In a multiplex, movies are screened in different auditoriums. One movie can be shown in more than one auditorium. In order to maintain the record of movies, the multiplex maintains a relational database consisting of two relations viz. MOVIE and AUDI respectively as shown below :

Movie(Movie_ID, MovieName, ReleaseDate)
Audi(AudiNo, Movie_ID, Seats, ScreenType, TicketPrice)

(a) Is it correct to assign Movie_ID as the primary key in the MOVIE relation ? If no, then suggest an appropriate primary key.

(b) Is it correct to assign AudiNo as the primary key in the AUDI relation ? If no, then suggest appropriate primary key.

(c) Is there any foreign key in any of these relations ?

Answer

(a) Yes, assigning Movie_ID as the primary key in the MOVIE relation is correct because each movie has a unique Movie_ID.

(b) It is not correct to assign AudiNo as the primary key in the AUDI relation because an AudiNo can be repeated for different movies screened in different auditoriums. To uniquely identify each record in the AUDI relation, a composite primary key consisting of AudiNo and Movie_ID should be used.

(c) Yes, there is a foreign key in the AUDI relation. The Movie_ID attribute in the AUDI relation is a foreign key that references the Movie_ID primary key in the MOVIE relation.

Question 12

For the below given database STUDENT-PROJECT, answer the following:

(a) Name primary key of each table.

(b) Find foreign key(s) in table PROJECT-ASSIGNED.

(c) Is there any alternate key in table STUDENT? Give justification for your answer.

(d) Can a user assign duplicate value to the field RollNo of STUDENT table? Justify.

Student Project Database

Table: STUDENT

Roll NoNameClassSectionRegistration_ID
11MohanXI1IP-101-15
12SohanXI2IP-104-15
21JohnXII1CS-103-14
22MeenaXII2CS-101-14
23JuhiXII2CS-101-10

Table: PROJECT

ProjectNoPNameSubmissionDate
101Airline Database12/01/2018
102Library Database12/01/2018
103Employee Database15/01/2018
104Student Database12/01/2018
105Inventory Database15/01/2018
106Railway Database15/01/2018

Table: PROJECT ASSIGNED

Registration_IDProjectNo
IP-101-15101
IP-104-15103
CS-103-14102
CS-101-14105
CS-101-10104

Answer

(a) Primary key of each table:

STUDENT: Roll No.
PROJECT: ProjectNo.
PROJECT ASSIGNED: Registration_ID.

(b) The ProjectNo column in the PROJECT ASSIGNED table is a foreign key that references the ProjectNo column in the PROJECT table.

(c) In the STUDENT table, the Registration_ID column serves as an alternate key since it uniquely identifies each student.

(d) No, a user cannot assign a duplicate value to the Roll No field of the STUDENT table because Roll No is the primary key of the table and it must be unique.

Question 13

For the below given database STUDENT-PROJECT, can we perform the following operations?

(a) Insert a student record with missing roll number value.

(b) Insert a student record with missing registration number value.

(c) Insert a project detail without submission-date.

(d) Insert a record with registration ID IP-101-19 and ProjectNo 206 in table PROJECT-ASSIGNED.

Student Project Database

Table: STUDENT

Roll NoNameClassSectionRegistration_ID
11MohanXI1IP-101-15
12SohanXI2IP-104-15
21JohnXII1CS-103-14
22MeenaXII2CS-101-14
23JuhiXII2CS-101-10

Table: PROJECT

ProjectNoPNameSubmissionDate
101Airline Database12/01/2018
102Library Database12/01/2018
103Employee Database15/01/2018
104Student Database12/01/2018
105Inventory Database15/01/2018
106Railway Database15/01/2018

Table: PROJECT ASSIGNED

Registration_IDProjectNo
IP-101-15101
IP-104-15103
CS-103-14102
CS-101-14105
CS-101-10104

Answer

(a) No. the Roll No attribute in the STUDENT table is marked as primary key and NOT NULL. Therefore, inserting a student record with a missing Roll No value would violate the NOT NULL constraint and is not allowed.

(b) Yes, the registration_ID attribute in the STUDENT table does not have a NOT NULL constraint specified in the schema. Therefore, it is possible to insert a student record without registration number value.

(c) Yes, the SubmissionDate attribute in the PROJECT table does not have a NOT NULL constraint specified in the schema. Therefore, it is possible to insert a project detail without a SubmissionDate value.

(d) No, we cannot perform this operation. ProjectNo in PROJECT ASSIGNED table serves as a foreign key that references the primary key in the PROJECT table. Since ProjectNo "206" is not present in the PROJECT table, it cannot be inserted into the PROJECT ASSIGNED table.

PrevNext