ER Model and Relational Model: Learning Objectives
ER Model and Relational Model: Learning Objectives
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
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
S 1. e 1.
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
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:
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
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
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
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.
Employee
Home Office
Name EId Phone Address Phone Age Salary
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
DEPENDENT
WORKS
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
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
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
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