0% found this document useful (0 votes)
161 views18 pages

ER Model and Relational Model: Learning Objectives

This document provides an overview of entity relationship (ER) modeling and relational databases. It defines key concepts such as entities, attributes, relationships, and the three-schema architecture. It explains that an ER model uses entities, relationships, and attributes to conceptualize a database, while a relational database implements the model using tables and tuples. The document also covers entity types, schemas, mapping cardinality constraints, and other foundational database concepts.

Uploaded by

AKASH PAL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
161 views18 pages

ER Model and Relational Model: Learning Objectives

This document provides an overview of entity relationship (ER) modeling and relational databases. It defines key concepts such as entities, attributes, relationships, and the three-schema architecture. It explains that an ER model uses entities, relationships, and attributes to conceptualize a database, while a relational database implements the model using tables and tuples. The document also covers entity types, schemas, mapping cardinality constraints, and other foundational database concepts.

Uploaded by

AKASH PAL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Chapter 1

ER Model and Relational Model


LEARNING OBJECTIVES

 Data model  Entity types, entity sets and value sets


 Schemas  Weak entity set
 Three-schema architecture  Relational database
 ER model  NULL in tuples
 Types of attributes  Inherent constraint
 Mapping cardinality  Referential and entity integrity constraint
 Complex attributes

intRodUCtion Data Model


A database is a collection of related data. By data, we mean facts A data model is a collection of concepts that can be used to describe
that can be recorded and that have implicit meaning. the structure of a database. It provides the necessary means to
achieve abstraction.
Example: Consider the names, telephone numbers and addresses
of the people. We can record this data in an indexed address book
and store it as Excel file on a hard drive using a personal computer. sChEMas
This is a collection of related data with an implicit meaning and In any data model, it is important to distinguish between the
hence is a database. description of the database and the database itself. The descrip-
A database management system (DBMS) is a collection of pro- tion of a database is called the database schema, which is
grams that enables users to create and maintain a database. The specified during database design and is not expected to change
DBMS is a general-purpose software system that facilitates the frequently.
processes of defining, constructing, manipulating and sharing The actual data in a database may change frequently, for exam-
databases among various users and applications. ple the student database changes every time we add a student or
1. Defining the database involves specifying the data types, enter a new grade for a student. The data in the database at a par-
structures, and constraints for the data to be stored in the ticular moment in time is called a database state or snapshot. It
database. is also called the current set of occurrences or instances in the
2. Constructing the database is the process of storing the data database.
itself on some storage medium that is controlled by the The distinction between database schema and database state is
DBMS very important. When we define a new database, we specify its
3. Manipulating a database includes such functions as querying database schema only to the DBMS. At this point, the correspond-
the database to retrieve specific data, updating the database ing database state is the empty state with no data. We get the ini-
to reflect changes. tial state of the database when the database is first loaded with
4. Sharing a database allows multiple users and programs to the initial data. The DBMS stores the description of the schema
access the database concurrently. constructs and constraints, also called the metadata in the DBMS
5. Fundamental characteristics of the database approach is that catalog so that DBMS software can refer to the schema whenever
it provides some level of data abstraction by hiding details of it needs. The schema is sometimes called the intension, and the
data storage that are not needed by users. database state an extension of the schema.
4.4 | Unit 4  •  Databases

Three-schema Architecture as entities. In general, there is no presumption that an entity


The goal of the three-schema architecture is to separate the is animate.
user applications and the physical database. 1. An object with a physical existence
Example:  A particular person, car, house, employee.
Levels of Abstraction 2. An object with a conceptual existence
Example: A company, a job, a university course.
View 1 View 2 View 3 Each entity has attributes, the particular properties
that describe it.
Example: An employee entity can be described by
Conceptual schema
employee’s name, age, address, salary and job.

Physical schema
Entity Set
Set of entities of same type that shares the same properties.
Example:  All persons, all companies etc.
Example:  Entity sets of customer and loan
1. The external or view level includes a number of
external schemas or user views. Each external schema Table 1  Customer Entity Set
describes the part of the database that a particular Customer-id Cust-name Cust-street City
user group is interested in and hides the rest of the
C-143 John MG Road Sec.bad
database.
2. The conceptual level has a conceptual schema, which C-174 Mary SP Road Hyd.bad
describes the structure of the whole database for a C-183 Tony KD Road Sec.bad
community of users. The conceptual schema hides the
C-192 Satya SG Road Eluru
details of physical storage structures and concentrates
on describing entities, data types, relationships, user
operations, and constraints.
3. The internal level has an internal schema, which Table 2  Loan Entity Set
describes the physical storage structures of the Loan-no Amount
database. It describes the complete details of data L-30 $3000
storage and access paths for the database.
L-31 $4000
L-32 $3500
ER Model L-33 $4500
Entity relationship model is a popular high-level conceptual L-34 $5000
data model. This model and its variations are used for the
conceptual design of database applications, and many data- An entity is represented by a set of attributes and by a descrip-
base design tools employ its concepts. ER model describes tive properties possessed by all members of an entity set.
data as entities, relationships and attributes. The basic object
that the ER model represents is an entity.
Types of Attributes
1. Simple versus composite
Entity 2. Single valued versus multivalued
It is an object that exists and is distinguishable from other 3. Stored versus derived.
objects
(or) Composite attribute: Composite attributes can be divided
Entity is a “thing” in the real world with an independent into smaller subparts, which represent more basic attribute
existence. that has their own meaning (Figure 1).
(or) Example:  A common example is Address, it can be broken
An entity is something that has a distinct, separate exist- down into a number of subparts such as street address,
ence, although it need not be a material existence. In par- city, postal code; street address is further broken down into
ticular, abstractions and legal functions are usually regarded Number, street Name and Apartment number.
Chapter 1  •  ER Model and Relational Model  |  4.5

Address One-to-one: An entity in A is associated with at most one


entity in B and an entity in B is associated with at most one
Street address City State Zip entity in A (Figure 3).

a1 b1
a2 b2
Number Street House-No a3 b3
a4 b4
Figure 1  A hierarchy of composite attributes.
Street address is a composite attribute. Attributes that are Figure 3  One-to-one relationship set.
not divisible are called simple (or) atomic attributes.
One-to-many: An entity in A is associated with any number
Single-valued versus multivalued attributes: Most attributes of entities in B. But an entity in B is associated with at most
have a single value for a particular entity, such attributes are one entity in A (Figure 4).
called single-valued attribute.
b1
Example:  Age is a single-valued attribute a1
b2
Multivalued attributes: An attribute can have a set of values a2 b3
for the same entity. a3 b4
Example:  College degrees attribute for a person b5
Example:  Name is also a multivalued attribute (Figure 2).
Figure 4  One-to-many relationship set.
Name Many-to-one: An entity in A is associated with at most one
entity in B. But an entity in B can be associated with any
First name Last name number of entities in A (Figure 5).
Middle name
a1
Figure 2  Multivalued attribute. b1
a2
Stored versus derived attributes: Two (or) more attribute a3 b2
values are related. a4 b3
a5
Example:  Age can be derived from a person’s date of birth.
The age attribute is called derived attribute and is said to be Figure 5  Many-to-one relationship set.
derivable from the DOB attribute, which is called a stored
attribute. Many-to-many: An entity in A is associated with any num-
ber of entities in B. But an entity in B can be associated with
Domain: The set of permitted values for each attribute.
any number of entities in A (Figure 6).
Example:  A person’s age must be in the domain {0-130}
a1 b1
a2 b2
Relationship Sets a3 b3
A relationship is an association among several entities. a4 b4
Relationship sets that involve two entity sets are binary.
Figure 6  Many-to-many relationship set.
Generally, most relationships in databases are binary.
Relationship sets may involve more than two entity sets. Example:  One customer can have multiple accounts
Example:  Employee of a bank may have responsibilities at Customer(c-Name) (Acc. no, Amount)
multiple braches, with different jobs at different branches, then Table 3  Example of One-to-many Relationship Set
there is a ternary relation between employee, job and branch.
Arun A-101 $3000

Mapping Cardinality Bunny A-102 $3500


For a binary relationship set, mapping cardinality must be: Kate A-103 $2000
1. One-to-one Mary A-104 $2500
2. One-to-many John A-105 $4000
3. Many-to-one
4. Many-to-many In Table 3, many-to-one relationship is not possible.
4.6 | Unit 4  •  Databases

Complex Attributes ({Phone (Areacode, phoneNumber)}, Address (StreetAddress


Composite and multivalued attributes can be nested in an (StreetNumber, streetName, ApartmentNumber), city, state,
arbitrary way. We can represent arbitrary nesting by group- zip))}
ing components of a composite attribute between parenthe-
ses () and separating the components with commas, and by Entity types, entity sets and value sets
displaying multivalued attributes between braces { }. Such
An entity type defines a collection of entities that have the
attributes are called complex attributes.
same attributes. Each entity type in the database is described
Example:  A person can have more than one residence and each by its name and attribute. The following figure shows two
residence can have multiple phones, an attribute AddressPhone entity types, named STUDENT and EMPLOYEE and a list
for a person can be specified as shown below. {AddressPhone of attributes for each

ENTITY TYPE NAME STUDENT EMPLOYEE


ATTRIBUTES: R.No, Name, Grade Name, Salary, Age

S 1. e 1.

(86, Arun, A) (Kamal, 20K, 42)


ENTITY SET S2. e 2.

(87, Pavan, B) (Bharat, 25K, 41)


(EXTENSION)
S 3. e 3.

(89, Karan, A) (Bhanu, 26K, 41)

The collection of all entities of a particular entity type in the Binary relation  If a relationship type is between entities
database at any point in time is called an entity set. in one type and entities in another type then it is called a
binary relation, because two entity types are involved in the
Types of relations relation.
1. Unary relation. 4. Quadnary relation.
2. Binary relation. 5. N-ary relation
Customer Purchased Product
3. Ternary relation.
Relationship
The above relation indicates that customers purchased prod-
uct (or) products are purchased by customers.
Number of
Degree Quadnary relation  If a relationship type is among entities
entity types
of four different types, then it is called quadnary relation.
1. Unary
2. Binary
Lecturer
3. Ternary Cardinality Optionality
1:1 Optional
N–ary 1:N Mandatory
N:1
M:N Student Register Course
Unary relation  If a relationship type is between entities in a
single entity type then it is called a unary relationship type.

Department
Employee Managed-by
In the above ER-diagram, any two entities can have a
relation.

In employee entity, we will have all the employees including N-ary relation ‘N’ number of entities will participate in
‘manager’, this relation indicates, employees are managed a relation, and each entity can have a relation with all the
by manager. other entities.
Chapter 1  •  ER Model and Relational Model  |  4.7

E1 relationship, whereas partial participation is represented by


EN E2 a single line.

E6
ER Diagrams (Figure 7 and 8)
E3
E5 Cust-street
E4
C-name L No Amount
Cust-city
Cust-id
Cardinality Ratio Customer Borrower Loan
and Participation Constraints
The cardinality ratio for a binary relationship specifies the Figure  7 ER diagram.
maximum number of relationship instances that an entity
can participate in Notations:

1. The participation constraint specifies whether → Represents entity


the existence of an entity depends on its being
related to another entity via the relationship type. → Represents relationship sets
This constraint specifies the minimum number of ––––  → Represents links between attributes to entity
relationship instances that each entity can participate sets and entity sets to relationship sets
in, and is some times called the minimum cardinality → Represents attributes
constraint. → Represents multivalued attributes
2. There are two types of participation constraints: → Represents primary key attribute
a. Total participation
b. Partial participation Phone-no DOB
Example:  If a company policy states that every employee Age
must work for a department, then an employee entity Cust-id
can exist only if it participates (or) works for at least one
Customer
department.

EMPLOYEE WORKS-FOR DEPARTMENT Name

First name
Last
r1
e1 Middle name
d1
r2 name
e2
r3 Figure 8  ER diagram.
e3 d2
r4 → Derived attribute
e4 .  → Multivalued attribute
. . .
. .

→ Weak entity

Every entity in the EMPLOYEE set must be related to a
DEPARTMENT entity via WORK-FOR. Total participa-
tion is also called existence dependency. If we do not expect → Weak entity set relation

every employee to manage a department, so the partici-


pation of EMPLOYEE in the relationship type is partial,
means not necessarily all employees’ entities are related to
some department entity.
Cardinality ratio and participation constraints are taken
together as the structural constraints of a relationship type. → Composite attribute
In ER diagrams, total participation is displayed as a dou-
ble line connecting the participating entity type to the
4.8 | Unit 4  •  Databases

R
Many-to-many
E E Total Participation
of E2 in R1 Examples: 
1. Many students are taught by many teachers.
1 N
E R E Cardinality 2. Many patients are treated by many doctors.
ratio 1: n 3. Many medications are taken by many patients.
Structural
4. Many customers buy many products.
(min, max) constraint on 5. Many books are written by many authors.
R E
participation of
E In R

Cardinality Constraints Customer Borrower Loan


One-to-one
Each entity of one entity set is related to at most one entity Customer is associated with several loans and loan is asso-
of the other set. Only one matching record exists between ciated with several customers.
two tables.
Example:  Assume each owner is allowed to have only ER Diagram with a Ternary
one dog and each dog must belong to one owner. The own Relationship
relationship between dog and owner is one-to-one. One-to-
one relationships can often combine the data into one table. Title Level

Examples:  Job
1. One birdfeeder is located in one place in the yard. E-name Street Assets
B-city
2. One state has one governor. E-id
City B-name
3. One yard has one address.
4. One patient has one phone number.
2. One student has one ID. Employee Works-on Branch

Figure 9  ER diagram with a ternary relationship.

Weak Entity Set


Customer Borrower Loan
An entity set that does not have a primary key is called weak
entity set.
One customer is associated to one loan via borrower Weak entity set is represented by →
Underline the primary key of a weak entity with a dashed line.
One-to-many
Example: 
Examples: 
P-date
1. One birdfeeder is visited by many birds.
2. One student can have many degrees. L-no
Amount Amount
3. One Book can be written by many authors. P-no
4. One yard contains many bird feeders.
5. One patient has many prescriptions. Loan
Loan payment Payment
In the one-to-many relationship, a loan is associated with
one customer via borrower.

Many-to-one Relational Database


Relational Model
The relational model represents the database as a collection
of relations. When a relation is thought of as a table of val-
Customer Borrower Loan
ues, each row in the table represents a collection of related
data values. Each row in the table represents a fact that typi-
A customer is associated with at most one loan via borrower. cally corresponds to a real-world entity. The table name and
Chapter 1  •  ER Model and Relational Model  |  4.9

column names are used to help in interpreting the meaning •• Manipulative aspect: The operators available to
of the values in each row. the user for manipulating those tables, for purposes
In formal relational model terminology, a row is called a of data retrieval, these operators derive tables form
tuple, a column header is called an attribute, and the table tables, the most important operators are ‘SELECT’,
is called a relation. ‘PROJECT’ and JOIN.

Domain Relation Schema


A domain is a set of atomic values. A common method of A relation schema ‘R’ denoted by R(A1, A2, . . . An) is made
specifying a domain is to specify a data type from which the up of a relation name R and a list of attributes A1, A2, . . . An.
data values forming the domain are drawn. It is also useful Each Attribute Ai is the name of role played by some domain
to specify a name for the domain, to help in interpreting its D in the relation schema R. D is called the domain of Ai and
values is denoted by dom(Ai).
A relation schema is used to describe a relation and R is
Example: 
called the name of this relation. The degree of a relation is
1. Set of telephone numbers: The set of valid numbers in the number of attributes ‘n’ of its relation schema.
a particular country.
2. Employee id numbers: The set of valid employee Example:
numbers in a company. A relation schema of degree ‘7’, which describes an
3. Names: The set of character strings that represent employee is given below:
names of persons.
EMPLOYEE (Name, EId, HomePhone, Address, Office
4. Grade-point average: Possible values of computed
phone, Age, Salary)
grade point averages, each must be real (floating
point) number between 0 and 4 Using the data type of each attribute, the definition is
5. Research department names: The set of research written as:
department names in a specialization, such as computer EMPLOYEE (Name: String, EId: INT, Homephone: INT,
science, chemistry and applied mathematics. Address: String, OfficePhone: String, Age: Real, Salary: INT)
6. Research department codes: The set of Research For this relation schema, EMPLOYEE is the name of the
department codes, such as CS, CHE, AM. relation, which has ‘7’ attributes.
2. A relation ‘r’ of the relation schema R(A1, A2 . . . An),
The preceding is called logical definitions of domains.
also denoted by r(R), is a set of n-tuples. r = {t1, t2 . . . tm}.
The data type for research department names is set of
Each n-tuple ‘t’ is an ordered list of n values t =
character strings that represent valid department names.
<V1, V2 . . . Nn>, where each value Vi, 1 ≤ i . . . n, is an
A domain is thus given a name, data type, and format.
element of dom(Ai) or is a special null value.
Additional information for interpreting the values of a
3. The ith value in tuple t, which corresponds to the
domain can also be given, for example a numeric domain
attribute Ai, is referred to as t[Ai].
such as person weights should have the units of measure-
4. The following figure shows EMPLOYEE relation.
ments, such as kilograms or pounds.
Each type in a relation represents a particular
1. The relational model is often described as having the employee entity. We display the relation as a table
following three aspects: where each tuple is shown as a row and each attribute
•• Structural aspect:  The data in the database is per- corresponds to a column header, indicating a role or
ceived by the user as tables. interpretation of the values in that column. Null values
•• Integrity aspect:  Those tables has to satisfy certain represent attributes whose values are unknown or do
integrity constraints. not exist for some individual EMPLOYEE tuple.

Employee

Home Office
Name EId Phone Address Phone Age Salary

Mahesh 30-01 870-223366 Warangal NULL 35 40 k

Ramesh 30-02 040-226633 Hyderabad NULL 36 40 k

Suresh 30-03 040-663322 Kolkata 040-331123 35 42 k

Dinesh 30-04 040-772299 Bangalore 040-321643 36 40 k


4.10 | Unit 4  •  Databases

Fig: The attributes and tuples of a relation EMPLOYEE. The 3. Constraints that cannot be directly expressed in
earlier definition of a relation can be restated as follows: the schemas of the data model, and they must be
A relation r(R) is a mathematical relation of degree ‘n’ on expressed and enforced by the application programs are
the domains dom(A1), . . . , dom(An), which is a subset of the application-based constraints.
Cartesian product of the domains that define R:
r(R) C (dom(A1) × dom(A2) . . . × dom(An)) Inherent Constraint
The constraint that a relation cannot have duplicate tuples
Characteristics of Relations is an inherent constraint. Another important category of
There are certain characteristics that make a relation differ- constraints is data dependencies, which include ‘functional
ent from a file or a table. dependencies’ and ‘multivalued dependencies’. They are used
Ordering of tuples in a relation: A relation is defined mainly for testing the ‘goodness’ of the design of a relational
as a set of tuples. Tuples in a relation do not have any par- database and are utilized in a process called normalization.
ticular order. In a file, records are stored on disk in order.
This ordering indicates first, second, ith, and last records in Schema-based Constraints
the file. Similarly, when we display a relation as a table, the 1. Domain constraints
rows are displayed in a certain order. 2. Key constraints
Tuple ordering is not part of a relation definition, because 3. Constraints on nulls (Not null constraint)
a relation attempts to represent facts at a logical or abstract 4. Entity integrity constraints
level. Many logical orders can be specified on a relation. 5. Referential integrity constraints
Tuples in the EMPLOYEE relation could be logically 6. Unique constraint
ordered by values of Name or by EID or by Age or by some 7. Check constraint
other attribute. When a relation is implemented as a file or
displayed as a table, a particular ordering may be specified Domain constraints
on the records of the file or the rows of the table. Domain constraints specify that within each tuple, the value
of each attribute ‘X’ must be an atomic value from the
NULL in Tuples domain dom(X).
Each value in a tuple is an atomic value; that is, it is not The data types associated with domains include standard
divisible into components. Hence, composite and multi- numeric data types for integers
valued attributes are not allowed. This model is sometimes 1. Short integer
called the flat relational model. Multivalued attributes must 2. Integer
be represented by separate relations, and composite attrib- 3. Long integer
utes are represented only by their simple component attrib- 4. Real numbers
utes in the basic relational model. •• Float
NULLS are used to represent the values of attributes that •• Double-precision float
may be unknown or may not apply to tuple. For example,
5. Characters
some student tuples have null in their office phones because
6. Booleans
they do not have an office. In this case, the meaning behind
7. Fixed-length strings
NULL is not applicable. If a student has a NULL for home
8. Variable-length strings
phone, it means either he/she does not have a home phone
9. Date, time, time stamp
or he/she has one but we do not know it, in this case the
10. Money data types
meaning of NULL is ‘Unknown’.
Key constraints
Relational Model Constraints A relation is a set of tuples. All elements of a set are dis-
In a relational database, there will be many relations, and tinct; hence, all tuples in a relation must also be distinct.
the tuples in those relations are related in various ways. This means no two tuples can have the same combination of
There are many restrictions or constraints on the actual val- values for all their attributes.
ues in a database state.
1. There are other subsets of attributes of a relation
Constraints on database can generally be divided into
schema R with the property that no two tuples
three main categories as follows:
in any relation state ‘r’ of R should have the same
1. Constraints that are inherent in the data model, we combination of values of these attributes.
call them inherent model-based constraints.   Suppose that we denote one subset of attributes by
2. Constraints that can be directly expressed in the ‘SK’, then for two distinct tuples t1 and t2 in a relation
schemes of the data model, by specifying them in state ‘r’ of R, we have the following constraint:
the DDL (Data Definition Language). We call these
schema-based constraints. t1[SK] = t2[SK]
Chapter 1  •  ER Model and Relational Model  |  4.11

2. Any such set of attributes SK is called a super key of Another constraint on attributes specifies whether null
the relation schema R. values are permitted in tuples or not. If we want some tuples
  SK specifies a uniqueness constraint that no two to have a valid (or) non-null value, we need to use NOT
distinct tuples in any state r or R can have the same NULL constraint on that attribute.
value for SK.
3. Every relation has at least one default super key, the Referential and entity integrity constraint
set of all its attributes. A key, ‘K’ of a relation schema
The entity Integrity constraint states that no primary key
R is a super key of R with the additional property that
value can be null. If we have NULL values in the primary
removing any attributes ‘X’ from K leaves a set of
key column, we cannot identify some tuples in a relation.
attributes K’ that is not a super key of R any more.
1. Key constraints and entity Integrity constraints are
A key satisfies the following two constraints:
specified on individual relations
1. Two distinct tuples in any state of the relation cannot 2. Referential integrity constraint is specified between
have identical values for all the attributes in the key. relations and used to maintain the consistency among
2. A super key from which we cannot remove any tuples in the two relations.
attributes and still have the uniqueness constraints 3. Referential Integrity constraints states that a tuple in
mentioned in above condition is known as a minimal one relation that refers to another relation must refer
super key. to an existing tuple in that relation.
     The first condition applies to both keys and super 4. To understand the concept of Referential Integrity,
keys. The second condition is required only for keys. first we have to understand the concept of
Example:  Consider the employee relation in Page no. 9. FOREIGN KEY.
The attribute set {EId} is a key of employee because no two 5. Suppose we have two relations R1 and R2. A set of
employee tuples can have the same value for EId. attributes FK in relation schema R1 is a foreign key
Any set of attributes that include EId will form a super key. of R1 that references relation R2 if it satisfies the
1. {EId, Homephone, Name} following two rules:
2. {EId, Age, Salary} •• The attributes in FK have the same domains as the
3. {Name, EId, Address} primary key attributes PK of R2, FK will have to
refer to PK.
However, the super key {EId, Name, Age} is not a key of
•• A value of FK in a tuple t1 of the current state r1(R1)
EMPLOYEE, because removing Name or age or both from
either occurs as a value of PK for some tuple t2 in
the set leaves us with a super key. Any super key formed from
the current state r2(R2) or is null. We have t1[FK]
a single attributes is also a key. A key with multiple attributes
= t2[PK], and we say that the tuple t1 references to
must require all its attributes to have the uniqueness property.
the tuple t2. In this definition, R1 is called the ref-
A relation schema may have more than one key. In that
erencing relation and R2 is the referenced relation.
case, each of the keys is called a candidate key.
6. A foreign key can refer to its own relation. We
Example:  Employee relation has three candidate keys. can diagrammatically display referential integrity
{Name, EId, Homephone} constraints by drawing a directed Arc from each foreign
One of the candidate keys is chosen as primary key of the key to the relation it references. The arrow head may
relation. point to the primary key of the referenced relation.

Example: 
EMPLOYEE
FNAME LNAME EID DOB GENDER SALARY DNO

DEPARTMENT

DNO DNAME DLOCATION DMANAGER

DEPENDENT

EID DEPENDENT-NAME GENDER DOB RELATIONSHIP

WORKS

EID PROJ-NO HOURS


4.12 | Unit 4  •  Databases

7. Referential integrity rule: The database must not 3. It is like checking a condition before saving data into
contain any unmatched foreign key values. a column.
If ‘B’ References ‘A’, then A must exist. Example:  Create table student (RNo:INT CHECK
(Rno>0)
NOT NULL constraint Name:varchar(60)
1. NOT NULL constraint restricts a column from having Dept:varchar(4))
a NULL value. NOT NULL constraint can be applied Suppose the following tuple is inserted into student table.
to any column in a table.
1. Insert into student values <-4, ‘Bhanu’, ‘CS’>
2. We cannot give NULL values under that column
2. CHECK constraint is enforced on RNo column, the
3. NOT NULL Constraint enforces a column to contain
RNo should be greater than ‘0’, but ‘-4’ is given.
a proper value.
3. CHECK constraint is violated.
4. This constraint cannot be defined at table level.
Creating table from a table: A view is called a derived table
Example:  CREATE TABLE (or) virtual table, because the data stored in views is taken
student(RNo:INT  Name:varchar(70) NOT NULL  age:INT) from already existing tables.
Suppose a row is inserted into the following table, A view can also be defined as a logical subset of data
Insert into student values <11, NULL, 20> from one or more tables.
In the schema, we enforced NOT NULL constraint on Name Syntax:
column, means Name cannot have NULL value, when the CREATE view view-name As
above insert command is executed, the system gives, NOT SELECT column-names
NULL constraint violation. FROM table-name
WHERE condition
UNIQUE constraint
Example:  Consider the following table “sales”.
The column on which UNIQUE constraint is enforced
should not have any duplicate values. Sales
Order Previous
1. UNIQUE constraint can be enforced on any column
Order-Id Name Balance Customer
except the primary key column.
21 Order 3 3000 Ana
2. By default primary key column will not accept any
22 Order 4 1000 Adam
duplicate values that are handled by key constraint.
23 Order 5 3000 Brat
3. UNIQUE constraint can be applied at column level or
table level. 24 Order 6 2000 John
25 Order 7 2000 Ana
Example:  CREATE TABLE 26 Order 8 4000 Ana
student (RNo:INT  Name:varchar(60)  Grade:CHAR(1))
Assume that the table contains following tuples Query to create a view:
CREATE view sales-view As
Student
SELECT *
R no. Name Grade
FROM Sales
11 Sita B
WHERE customer = ‘Ana’
12 Anu A
13 Bala A 1. The data fetched from select statement will be stored
Suppose the following tuple is inserted into the student table. in an object called ‘sales-view’.
2. To display the contents stored in view, execute the
1. Insert into student values <14, ‘Anu’, ‘B’> following statement.
2. UNIQUE constraint is enforced on Name column, in
SELECT *
the student table we have ‘Anu’, and again the new
FROM Sales-view
tuple contains name ‘Anu’, this Insert command
violates the UNIQUE constraint. Removal of specific rows:
Consider the following SQL query:
CHECK constraint Delete *
This constraint is used to restrict a value of a column FROM Sales
between a range. The above query will delete all the tuples from sales.
1. When a value is inserted into particular column, To remove specific rows, we have to specify the condi-
before storing that, a check will be performed to see tion in WHERE clause.
whether the values lie within the specified range. Consider the table “sales” given in the above example.
2. If the value entered is out of range, it will not accept Remove the rows from sales table whose previous bal-
and violation happens. ance is 3000.
Chapter 1  •  ER Model and Relational Model  |  4.13

SQL query: SHIPMENTS:


Delete *
FROM Sales Supplier Part Project
Number Number Number Quantity
WHERE Previous-balance = 3000
Output: SN1 PN1 PJ1 300

SN1 PN1 PJ4 400


Order Previous
Order Id Name Balance Customer SN2 PN3 PJ1 350
22 Order 4 1000 Adam
SN2 PN3 PJ2 450
24 Order 6 2000 John
25 Order 7 2000 Ana SN2 PN3 PJ3 640
26 Order 8 4000 Ana
SN2 PN3 PJ4 320
Referential actions: Referential Integrity can be violated if SN2 PN3 PJ5 330
the value of any foreign key refers to a tuple that does not
exist in the referenced relation. SN2 PN3 PJ6 520
When certain violations occur, we need to perform some SN2 PN3 PJ7 480
alternate action. Those actions are as follows:
SN2 PN5 PJ2 460
1. ON DELETE CASCADE SN3 PN3 PJ1 440
2. ON UPDATE CASCADE
SN3 PN4 PJ2 410
3. ON DELETE SET NULL
4. ON DELETE SET DEFAULT SN4 PN6 PJ3 310

Example:  Consider the given database: SN4 PN6 PJ7 320

SN5 PN2 PJ2 340


SUPPLIERS:
SN5 PN2 PJ4 350
Supplier Supplier
Number Name Status City SN5 PN5 PJ5 360
SN1 Suma 30 Hyderabad SN5 PN5 PJ7 370
SN2 Hari 20 Chennai
SN5 PN6 PJ2 380
SN3 Anu 10 Hyderabad
SN5 PN1 PJ4 420
SN4 Mahesh 20 Bombay
SN5 Kamal 30 Delhi SN5 PN3 PJ4 440

SN5 PN4 PJ4 450


PARTS:
SN5 PN5 PJ4 400
Part Part
SN5 PN6 PJ4 410
number name Colour Weight City
PN1 X Red 13.0 Chennai
PN2 Y Green 13.5 Bombay Consider the following statement:
PN3 X Yellow 13.2 Hyderabad
PN4 Y Green 14.1 Calcutta DELETE FROM SUPPLIER
PN5 Z Red 14.3 Hyderabad WHERE SUPPLIER - NUMBER = ‘SN1’
PN6 Z Blue 14.2 Bombay
It deletes the supplier tuple for supplier ‘SN1’. The
PROJECT: database has some other tables which have ‘SN1’ tuple
Project Number Project Name City (Shipments table). The application does not delete those
PJ1 Display Chennai
suppliers, then it will find a violation, and an exception
will be raised.
PJ2 OCR Bombay
An alternate approach is possible, one that might be pref-
PJ3 RAID Chennai erable in some cases, and that is for the system to perform
PJ4 SORTER Hyderabad an appropriate ‘compensating action’ that will guarantee
PJ5 EDS Chennai that the overall result does still satisfy the constraint. In the
PJ6 Tape Bombay
example, the compensating action would be for the system
to delete the shipments for supplier SN1 “automatically”.
PJ7 Console Hyderabad
4.14 | Unit 4  •  Databases

We can achieve this effect by extending the foreign key as In general, CREATE TRIGGER specifies, among other
indicated below: things, an event, a condition, and an action.
The event is an operation on the database (“INSERT ON
CREATE TABLE SHIPMENT{.....}....... HYDERABAD - SUPPLIER” in the example)
FOREIGN KEY {SUPPLIER - NUMBER} 1. The “condition” is a Boolean expression that has to
REFERENCES evaluate to TRUE in order for the action to be executed.
SUPPLIER ON DELETE CASCADE 2. The ‘action’ is the triggered procedure (“INSERT
INTO SUPPLIERS . . .)
The specification ON DELETE CASCADE defines a 3. The event and condition together are sometimes
delete rule for this particular foreign key, and the speci- called the triggering event. The combination of all
fication CASCADE is the referential action for that three (event, condition, and action) is usually called a
delete rule. The meaning of these specifications is that a trigger.
DELETE operation on the suppliers relvar will ‘Cascade” 4. Possible events include INSERT, DELETE, UPDATE,
to delete matching tuples (if any) in the shipments relvar reaching end-of-transaction (COMMIT) reaching a
as well. specified time of day, exceeding a specified elapsed
Same procedure is applied for all the referential actions. time, violating a specified constraint, etc.
5. A database that has associated triggers is sometimes
called an active database.
Triggers
Triggers are precompiled procedures that are stored along
with the database and invoked automatically whenever Base Table Constraints
some specified event occurs. SQL-base table constraints are specified on either CERATE
Suppose we have a view called HYDERABAD - TABLE or ALTER TABLE. Each such constraint is a can-
SUPPLIER defined as follows: didate key constraint, a foreign key constraint, or a CHECK
constraint.
CREATE VIEW HYDERABAD-SUPPLIER Candidate keys:  An SQL candidate key definition takes one
AS SELECT SUPPLIER - NUMBER, SUPPLIER- of the following two forms:
NAME, STATUS
FROM SUPPLIER
WHERE CITY = ‘HYDERABAD’, PRIMARY KEY (< column name comma list>)
UNIQUE (< column name comma list>)
Normally, if the user tries to insert a row into this view, The following example illustrates base table con-
SQL will actually insert a row into the underlying base straints of all three kinds:
table SUPPLIERS with CITY value whatever the default CREATE TABLE SHIPMENTS
is for the CITY column. Assuming that default is not (SUPPLIER-NUMBER. SUPPLIER-NUMBER
Hyderabad, the net effect is that the new row will not NOT NULL, PART - NUMBER PART-NUMBER
appear in the view; therefore, let us create a triggered pro- NOT NULL, QUANTITY NOT NULL
cedure as follows: PRIMARY KEY (SUPPLIER - NUMBER,
PART NUMBER)
FOREIGN KEY (SUPPLIER-NUMBER)
CREATE TRIGGER HYDERABAD -
REFERENCES SUPPLIERS
SUPPLIER - INSERT
ON DELETE CASCADE
INSTEAD OF INSERT ON HYDERABAD
ON UPDATE CASCADE,
- SUPPLIER
FOREIGN KEY (PART-NUMBER)
REFERENCING NEW ROW AS R
REFERENCES PARTS
FOR EACH ROW
ON DELETE CASCADE
INSERT INTO SUPPLIERS (SUPPLIER -
ON UPDATE CASCADE
NUMBER, SUPPLIER - NAME, STATUS, CITY)
CHECK(QUANTITY ≤ QUANTITY (0) AND
VALUES (R. SUPPLIER - NUMBER, R.
SUPPLIER - NAME, R. STATUS, ‘HYDERABAD’); QUANTITY ≤ QUANTITY (1000));

Inserting a row into the view will now cause a row to be A check constraint of the form CHECK (< column name >
inserted into the underlying base table with CITY value IS NOT NULL) can be replaced by a simple NOT NULL
equal to Hyderabad inserted of the default value. specification in the definition of the column.
Chapter 1  •  ER Model and Relational Model  |  4.15

Exercises
Practice Problems 1  B
Directions for questions 1 to 20:  Select the correct alterna- Id Name Age
tive from the given choices. 15 Shreya 24
1. Consider the following two tables T1 and T2. Show the 25 Hari 40
output for the following operations: 98 Rohit 20
Table T1 99 Rohit 11

P Q R C
11 a 6 Id Phone Area

16 b 9 10 2200 02

26 a 7 99 2100 01

 Table T2 How many tuples does the result of the following rela-
tional algebra expression contain? Assume that the
A B C scheme of (A∪B) is the same as that of A.
11 b 7 (A∪B)⋈A.Id>40 v c.Id<15C
26 c 4 (A) 6 (B) 7
11 b 6 (C) 8 (D) 9
4. Consider the relations A, B and C given in Question 3.
What is the number of tuples present in the result of
How many tuples does the result of the following SQL
given algebraic expressions?
query contain?
(i) T1 ⋈T1.P = T2.AT2
SELECT A.Id
(A) 2 (B) 3 FROM A
(C) 4 (D) 5
WHERE A.Age>
(ii) T1 ⋈T1.Q = T2.BT2

ALL (SELECT B.Age
(A) 2 (B) 3 FROM B
(C) 4 (D) .5
WHERE B.Name = ‘Arun’)?
(iii) T1 ⋈(T1.p = T2.A AND T1.R = T2.C)T2 (A) 0 (B) 1
(A) 1 (B) 2 (C) 2 (D) 3
(C) 3 (D) .4 5. Consider a database table T containing two columns
2. Suppose R1(A, B) and R2(C, D) are two relation schemas. X and Y each of type integer. After the creation of the
Let R1 and R2 be the corresponding relation instances. B table, one record (X = 1, Y = 1) is inserted in the table.
is a foreign key that refers to C in R2. If data in R1 and Let MX and MY denote the respective maximum value
R2 satisfy referential integrity constraints, which of the of X and Y among all records in the table at any point
following is true? in time. Using MX and MY, new records are inserted in
the table 128 times with X and Y values being MX + 1,
π B ( R1 ) − π c ( R2 ) = φ
(A) 2 * MY + 1, respectively. It may be noted that each time
π C ( R2 ) − π B ( R1 ) = φ
(B) after the insertion, values of MX and MY change. What
will be the output of the following SQL query after the
π B ( R1 ) − π C ( R2 ) ≠ φ
(C) steps mentioned above are carried out?
(D) Both A and B Select y from t where x = 7;?
3. Consider the following relations: (A) 15 (B) 31
(C) 63 (D) 127
A, B and C
6. Database table by name loan records is given below:
A
Id Name Age Borrower Bank Manager Loan Amount
12 Arun 60 Ramesh Sunderajan 10000
15 Shreya 24 Suresh Ramgopal 5000
99 Rohit 11 Mahesh Sunderajan 7000
4.16 | Unit 4  •  Databases

What is the output of the following SQL Query For any arbitrary predicate P, this query is equivalent to
SELECT count (*) which relational algebra expression?
FROM((SELECT Borrower, Bank-manager Π a1 , a2 , … an (σ p R1 × R2 ×…× Rm )
(A)
FROM Loan-Records)AS S
σ a1 , a2 , … an (σ p R1 × R2 ×…× Rm )
(B)
NATURAL JOIN
(SELECT Bank-manager, Loan-Amount σ a1 , a2 , … an (∏ p R1 × R2 ×…× Rm )
(C)
FROM Loan-Records) AS T);
Π R1 , R2 , … Rm (σ p a1 × a2 ×…× ( an )
(D)
(A) 3 (B) 4
(C) 5 (D) 6 11. Consider the following relation schema pertaining to a
7. Consider the following ER diagram: student’s database:
Student (Rollno, name, address)
m1 m2 m3 P1 P2 N1 N2 Enroll (Rollno, courseno, coursename)
Where the primary keys are shown underlined. The
m R1 P R2 N number of tuples in the student and Enroll tables are
120 and 6, respectively. What are the maximum and
What is the minimum number of tables needed to rep- minimum number of tuples that can be present in
resent M, N, P, R1, R2? (student * Enroll)
(A) 2 (B) 3 Where ‘*’ denotes natural join?
(C) 4 (D) 5 (A) 6, 6 (B) 6, 120
8. Let E1 and E2 be two entities in an ER diagram with (C) 120, 6 (D) 120, 120
simple single-valued attributes. R1 and R2 are two rela- 12. A relational schema for a train reservation database is
tionships between E1 and E2, where R1 is one-to-many given below
and R2 is many-to-many. R1 and R2 do not have any
Table 4  Passenger
attributes of their own. What is the minimum number
of tables required to represent this situation in the rela- Pid P Name Age
tional model? 0 ‘Sachin’ 65
(A) 2 (B) 3 1 ‘Rahul’ 66
(C) 4 (D) 5
‘Sourav’ 67
9. The following table has two attributes A and C where A 3 ‘Anil’ 69
is the primary key and C is the foreign key referencing
A with ON DELETE CASCADE.
Table 5  Reservation
A C Pid Class Tid
2 4 0 AC 8200
3 4 1 AC 8201
4 3 2 SC 8201
5 2 5 AC 8203
7 2 1 SC 8204
9 5 3 AC 8202
6 4
What pid’s are returned by the following SQL query for
What is the set of all tuples that must be additionally the above instance of the tables?
deleted to preserve referential integrity when the tuple SELECT pid
(2, 4) is deleted?
FROM Reservation
(A) (5, 2),(7, 2) (B) (5, 2), (7, 2),(9, 5)
(C) (5, 2),(9, 5) (D) (2, 4), (7, 2) WHERE class = ‘AC’ AND
10. Consider the following SQL query EXISTS (SELECT *
SELECT DISTINCT a1, a2, a3 … an FROM passenger
FROM R1, R2 … Rm WHERE age > 65 AND
WHERE P Passenger.pid = Reservation.pid)
Chapter 1  •  ER Model and Relational Model  |  4.17

(A) 0, 1 (B) 1, 3 (A) The above query displays DA and gross for all
(C) 1, 5 (D) 0, 3 those employees whose basic is ≥ 2000
13. Given {customer} is a candidate key, [customer name, (B) The above query displays DA and gross for all em-
customer street} is another candidate key then ployees whose basic is less than 2000
(A) {customer id, customer name} is also a candidate (C) The above query displays DA as well as gross for
key. all those employees whose basic is >2000
(B) {customer id, customer street} is also a candidate (D) Above all
key. 17. Which of the following query transformations is correct?
(C) {customer id, customer name, customer street} is R1 and R2 are relations C1, C2 are selection conditions
also a candidate key. and A1 and A2 are attributes of R1
(D) None (A) σC1(σC1(R1))→σC2(σC2(R1))
Common data for questions 14 and 15: Consider the fol- (B) σC1(σA1(R1))→σA1(σC1(R1))
lowing diagram, (C) pA2(pA(R1))→pA(pA2(R1))
(D) All the above
X1 X2 X3 18. Consider the following query select distinct a1, a2, …an
from r1, r2 . . . rm where P for an arbitrary predicate P,
this query is equivalent to which of the following rela-
X
tional algebra expressions:
(A) π σ p ( r1 × r2 × ... × rm )
a1 ... an
R1
(B) π σ p ( r1 × r2 × r3 ×…. × rm )
a1 ... an
Y1 Z1
(C) σ π p ( r1 × r2 × ... × rm )
a1 ... an
Y R1 Z
(D) σ π p ( r1 × r2 ×…× rm )
Y2 Z1 a1 ... an

19. The relational algebra expression equivalent to the fol-


14. The minimum number of tables needed to represent X, lowing tuple calculus expression
Y, Z, R1, R2 is {a} a ∈ r ^ (a[A] = 10 ^ a[B] = 20) is
(A) 2 (B) 3 (A) s(A = 10 r B = 20)r
(C) 4 (D) 5 (B) s(A = 10 ) (r) ∪ s(B = 20) (r)
15. Which of the following is a correct attribute set for (C) s(A = 10 ) (r) ∩ s(B = 20) (r)
one of the tables for the correct answer to the above (D) s(A = 10 ) (r) – s(B = 20) (r)
questions? 20. Which of the following is/are wrong?
(A) {X1, X2, X3, Y1} (B) {X1, Y1, Z1, Z2} (A)  An SQL query automatically eliminates dupli-
(C) {X1, Y1, Z1} (D) {M1, Y1} cates.
16. UPDATE account SET (B) An SQL query will not work if there are no in-
dexes on the relations.
DA = basic * .2, (C) SQL permits attribute names to be repeated in the
GROSS = basic * 1.3, same relation
Where basic > 2000; (D) All the above

Practice Problems 2 2. The example of derived attribute is


Directions for questions 1 to 20:  Select the correct alterna- (A) Name if age is given as other attribute
tive from the given choices. (B) Age if date_of_birth is given as other attribute
(C) Both (A) and (B)
1. If ABCDE are the attributes of a table and ABCD is a (D) None
super key and ABC is also super key then
3. The weak entity set is represented by
(A) A B C must be candidate key
(A) box
(B) A B C cannot be super key (B) ellipse
(C) A B C cannot be candidate key (C) diamond
(D) A B C may be candidate key (D) double outlined box
4.18 | Unit 4  •  Databases

4. In entity relationship diagram double lines indicate (C) query which involves a Cartesian product and a
(A) Cardinality projection
(B) Relationship (D) None
(C) Partial participation 12. The number of entities participating in the relationship
(D) Total participation is known as
5. An edge between an entity set and a binary relationship (A) maximum cardinality (B) composite identifiers
set can have an associated minimum and maximum (C) degree (D) None
cardinality, shown in the form 1… h where 1 is the
13 A minimum cardinality of 0 specifies
minimum and h is the maximum cardinality A mini-
(A) non-participation
mum value 1 indicates: (B) partial participation
(A) total participation (B) partial participation
(C) total participation
(C) double participation (D) no participation
(D) zero participation
6. Let R be a relation schema. If we say that a subset k
14. What is not true about weak entity?
of R is a super key for R, we are restricting R, we are
(A) They do not have key attributes.
restricting consideration to relations r(R)in which no
(B) They are the examples of existence dependency.
two district tuples have the same value on all attributes
(C) Every existence dependency results in a weak entity
in K. That is if t1 and t2 are in r and t1 ≠ t2
(D) Weak entity will have always discriminator attributes
(A) t1[k] = 2t2[K] (B) t2[K] = 2t1[k]
(C) t1[k] = t2[k] (D) t1[k] ≠ t2[k] 15. Which one is the fundamental operation in the rela-
tional algebra?
7. Which one is correct?
(A) Natural join (B) Division
(A) Primary key ⊂ Super key ⊂ Candidate key
(B) Candidate key ⊂ Super key ⊂ Primary key (C) Set intersection (D) Cartesian product
(C) Primary key ⊂ Candidate key ⊂ Super key 16. For the given tables
(D) Super key ⊂ Primary key ⊂ Candidate key
A B
8. If we have relations r1(R1) and r2(R2), then r1 (r2 is a X Y Y
relation whose schema is the
a1 b1 b1
(A) concatenation (B) union
(C) intersection (D) None a2 b1 b2
a1 b2
9. Match the following:
a2 b2
I Empid 1 Multivalued
II Name 2 Derived
A ÷ B will return
III Age 3 Composite (A) a1, a2 (B) a1
IV Contact No. 4 Simple (C) a2 (D) None
(A) I – 4, II – 3, III – 2, Iv – 1 17. The number of tuples selected in the above answer is
(B) I – 3, II – 2, III – 4, Iv – 1 (A) 2 (B) 1
(C) I – 2, II – 1, III – 4, Iv – 3 (C) 0 (D) 4
(D) I – 1, II – 3, III – 2, IV – 4
Common data for questions 18 and 19: Consider the fol-
10. Match the following: lowing schema of a relational database.
I Double-lined ellipse 1 Multivalued attribute Emp (empno, name, add)
II Double line 2 Total participation Project (Pno, Prame)
III Double-lined box 3 Weak entity set Work on (empno, Pno)
IV Dashed ellipse 4 Derived attribute Part (partno, Pname, qty, size)
(A) I – 1, II – 2, III – 3, IV – 4 Use (empno, pno, partno, no)
(B) I – 2, II – 3, III – 4, IV – 1 18. ((name(emp) ( (name(emp ⋈ workon) displays
(C) I – 3, II – 4, III – 2, IV – 2 (i) The names of the employees who are not working
(D) I – 4, II – 3, III – 2, IV –1 in any project
11. The natural join is a (ii) The names of the employees who were working in
(A) binary operation that allows us to combine certain every project.
selections and a Cartesian product into one operation (A) Only (i) (B) Only (ii)
(B) unary operations that allows only Cartesian product (C) Both (A) and (B) (D) None
Chapter 1  •  ER Model and Relational Model  |  4.19

19. List the partno and names of the parts used in both the 20. The following query shows. SELECT job-status, sum
projects DBMS & MIS: (basic – salary) AVG (basic – salary) from employees
(A) spartno, pname,(part ⋈ (ppartno (spname = “DBMS”(project) ⋈ group by job – status.
use).
∩ ppartno (spname = “MIS”(project) ⋈ use)) (i) It shows job status, sum, AVG of all data
(B) (partno, pname(part ⋈ ((partno ((pname = (ii) It shows job status, Sum, AVG, with group by
“DBMS”(project ⋈ use) ((partno(spname = clause in use.
“MIS”(project) ⋈ use))) (A) only (i)
(C)  ppartno, pname(part ⋈ (spartno (spname = “DBMS”(project ⋈ (B) only (ii)
use)
( (partno ((pname = “MIS”(project) ⋈ use))) (C) both (A) and (B)
(D) None (D) None

Previous Years’ Questions


1. Let E1 and E2 be two entities in an E/R diagram, with
M1 M 2 M3 P1 P2 N1 N2
simple single-valued attributes. R1 and R2 are two
relationships between E1 and E2, where R1 is one-to-
many and R2 is many-to-many. R1 and R2 do not have M R1 M R2 N
any attributes of their own. What is the minimum
number of tables required to represent this situation 4. The minimum number of tables needed to represent
in the relational model? [2005] M, N, P, R1, R2 is? [2008]
(A) 2 (B) 3 (A) 2 (B) 3
(C) 4 (D) 5 (C) 4 (D) 5
2. The following table has two attributes A and C where 5. Which of the following is a correct attribute set for
A is the primary key and C is the foreign key referenc- one of the tables for the correct answer to the above
ing A with on-delete cascade. question?[2008]
(A) {M1, M2, M3, P1} (B) {M1, P1, N1, N2}
A C (C) {M1, P1, N1} (D) {M1, P1}
2 4 6. Consider a relational table with a single record for
3 4 each registered student with the following attributes.
4 3 1.  Registration_Num: Unique registration number
of each registered student
5 2
2. UID: Unique identity number, unique at the
7 2 national level for each citizen
9 5 3.  BankAccount_Num: Unique account number at
6 4 the bank. A student can have multiple accounts or
joint accounts. This attribute stores the primary
The set of all tuples that must be additionally deleted account number
to preserve referential integrity when the tuple (2, 4) 4. Name: Name of the student
is deleted is: [2005] 5. Hostel_Room: Room number of the hostel
(A) (3, 4) and (6, 4)
(B) (5, 2) and (7, 2) Which of the following options is incorrect? [2011]
(C) (5, 2), (7, 2) and (9, 5) (A) BankAccount_Num is a candidate key
(D) (3, 4), (4, 3) and (6, 4) (B) Registration_Num can be a primary key
(C)  UID is a candidate key if all students are from
3. Which of the following tuple relational calculus the same country
expression(s) is/are equivalent to ∀t ∈ r (P(t))? (D) If S is a super key such that S ∩ UID is NULL
I. ¬ ∃t ∈ r (P(t)) then S ∪ UID is also super key.
II. ∃t ∉ r (P(t)) 7. Given the basic ER and relational models, which of
III. ¬ ∃t ∈ r (¬P(t)) the following is incorrect?[2012]
IV. ∃t ∈ r (¬P(t)) [2008] (A) An attribute of an entity can have more than one value
(A) I only (B) II only (B) An attribute of an entity can be composite
(C) III only (D) III and IV only (C) In a row of a relational table, an attribute can
have more than one value
Common data for questions 4 and 5: Consider the fol- (D) In a row of a relational table, an attribute can
lowing ER diagram: have exactly one value or a NULL value
4.20 | Unit 4  •  Databases

8. An ER model of a database consists of entity types A set E2. Assume that E1 and E2 participate totally in
and B. These are connected by a relationship R which R and that the cardinality of E1 is greater than the
does not have its own attribute, Under which one of cardinality of E2.
the following conditions, can the relational table for R Which one of the following is true about R?[2018]
be merged with that of A?[2017]
(A) Every entity in E1 is associated with exactly one
(A) Relationship R is one-to-many and the participa-
entity in E2.
tion of A in R is total.
(B) Some entity in E1 is associated with more than
(B) Relationship R is one-to-many and the participa-
one entity in E2.
tion of A in R is partial.
(C) Every entity in E2 is associated with exactly one
(C) Relationship R is many-to-one and the participa-
entity in E1.
tion of A in R is total.
(D) Every entity in E2 is associated with at most one
(D) Relationship R is many-to-one and the participa-
entity in E1.
tion of A in R is partial.
9. In an Entity-Relationship (ER) model, suppose R is a
many-to-one relationship from entity set E1 to entity

Answer Keys
Exercises
Practice Problems 1
1. (i) B  (ii) A  (iii) A 2. A 3. B 4. D 5. D 6. D 7. B 8. B
9. B 10. A 11. A 12. B 13. D 14. A 15. A 16. C 17. B 18. B
19. C 20. D

Practice Problems 2
1. D 2. B 3. C 4. A 5. A 6. D 7. C 8. A 9. A 10. A
11. A 12. C 13. C 14. A 15. D 16. A 17. A 18. A 19. C 20. B

Previous Years’ Questions


1. B 2. C 3. D 4. B 5. A 6. A 7. C 8. C 9. A

You might also like