Download as pdf or txt
Download as pdf or txt
You are on page 1of 75

Bank of Questions 2

1. Describe the two approaches to converting an UNF table to 1NF


relation(s).

2. Describe the concept of transitive dependency and describe how this


concept relates to 3NF. Provide an example to illustrate your answer.

3. Define the following terms

a. Serial schedule
b. Nonserial schedule
c. non-serial,
d. serializable
e. schedules
f. lost updates
g. uncommitted data
h. Transaction
i. ACID properties ( Atomicity- Consistency - Isolation - Durability
j. Partially committed
k. Aborted
l. Committed
m. Terminated
n. Serial execution
o. Conflict of operations
p. Conflict serializability
4. transfer the following table to BCNF
1. Consider money is transferred from (1)account-A to account-B and (2)
account-B to account-A. Which of the following ? form a transaction
a) Only 1
b) Only 2
c) Both 1 and 2 individually
d) Either 1 or 2
2. Identify the characteristics of transactions .
a) Atomicity
b) Durability
c) Isolation
d) All of the mentioned
3. Which of the following has “all-or-none” property?
a) Atomicity
b) Durability
c) Isolation
d) All of the
4. The database system must take special actions to ensure that
transactions operate .
a) Atomicity
b) Durability
c) Isolation
d) All of the mentioned
5. The property of a transaction that persists all the crashes is
a) Atomicity
b) Durability
c) Isolation
d) All of the mentioned
6. states that only valid data will be written to the database ……………….
a) Consistency
b) Atomicity
c) Durability
d) Isolation
7. A transaction may not always complete its execution successfully. Such
a transaction is termed
a) Aborted
b) Terminated
c) Closed
d) All of the mentioned
8. second transaction until the first one is completed
a) Consistency
b) Atomicity
c) Durability
d) Isolation
9. If a transaction is performed in a database and committed, the changes
are taken to the. previous state of transaction by
a) Flashback
b) Rollback
c) Both Flashback and Rollback
d) Cannot be done
10. When the transaction finishes the final statement, the transaction enters
into
a) Active state
b) Committed state
c) Partially committed state
d) Abort state
11. Which of the following is an atomic sequence of database actions?
a) Transaction
b) Concurrency
c) Relations
d) All of the mentioned
12. means that data used during the execution of a transaction cannot be
used by a _______ second transaction until the first one is completed
a) Serializability
b) Atomicity
c) Isolation
d) Time stamping
13. Which of the following is not a state in transaction?
a) Active
b) Terminated
c) Aborted
d) Partially committed
14. In the __________ normal form, a composite attribute is converted to
individual attributes .
a) First
b) Second
c) Third
d) Fourth
15. Functional Dependencies are the types of constraints that are based on .
a) Key
b) Key revisited
c) Superset key
d) None of the mentioned
16. Which is a bottom-up approach to database design that design by
examining the relationship between attributes
a) Functional dependency
b) Database modeling
c) Normalization
d) Decomposition
Bank of Questions
Database Management system
No Question Answer
all the following are Databases Properties except
a) Persistence
1 b) Sharing d) Hashing
c) Interrelated
d) Hashing
Relations produced from an E-R model will always be in …………
a) 1 NF
2 b) 2 NF c) 3 NF
c) 3 NF
a) BCNF
The natural join is equal to: d)
a) Cartesian Product Combination
3 b) Combination of Union and Cartesian product of projection
c) Combination of selection and Cartesian product and Cartesian
d) Combination of projection and Cartesian product product
Given the basic ER and relational models, which of the following is c) In a row of
INCORRECT? a relational
a) An attribute of an entity can has more than one value table, an
b) An attribute of an entity can be composite attribute can
4
c) In a row of a relational table, an attribute can have more than one have more
value than one
d) In a row of a relational table, an attribute can have exactly one value
value or a NULL value
d) None of
A logical schema
these
a) Is the entire database
b) Is a standard way of organizing information into a accessible
5
part
c) Describe how data is actually stored on disk
d) None of these

d) All the
The result of the UNION operation between R1 and R2 is a relation
tuples of R1
that includes ………. ?
and R2
a) All the tuples of R1
6 which have
b) All the tuples of R2
common
c) All the tuples of R1 and R2
columns
d) All the tuples of R1 and R2 which have common columns
A function Dependency is a relationship between or among
a) Table
7 b) Rows d) Attributes
c) Relations
d) Attributes
In the relational model, cardinality is termed as:
a) A number of tuples
a) A number
8 b) A number of attributes
of tuples
c) A number of tables
d) A number of constraints
Which of the following statement is not correct? d) Candidate
a) Non-key attributes are attributes other than candidate key key which
attributes are not
9 b) Non-prime Attributes are attributes other than Primary attribute selected for
c) Super Key is a superset of Candidate key primary key
d) Candidate key which are not selected for primary key are are known as
known as Foreign key. Foreign key
Which database level is closest to the users?
a) External
10 b) Internal a) External
c) Physical
d) Conceptual
In case of entity integrity, the primary key may be…..…….
a) Not Null
11 b) Null a) Not Null
c) Both Null & not Null
d) Any value
Which of the following is TRUE?
c) Every
a) Every relation in 3NF is also in BCNF
relation in
b) A relation R is in 3NF if every non-prime attribute of R is fully
12 BCNF is
functionally dependent on every key of R
also in
c) Every relation in BCNF is also in 3NF
3NF
d) No relation can be in both BCNF and 3NF
d) independe
The conceptual model is ……..….. nt of both
a) dependent on hardware hardware
13 b) dependent on software and
c) dependent on both hardware and software software
d) independent of both hardware and software.
Which key is used to relate two different table?
a) Primary key
d) Both a
14 b) Foreign key
and b
c) Candidate key
d) Both a and b
The Systems Development Life Cycle (SDLC) consist of
a) Planning
d) All of
15 b) Analysis
these
c) Implementation
d) All of these
…………… is a special type of integrity constraint that relates two
relations & maintains consistency across the relations
b) Referential
a) Entity Integrity Constraints
16 Integrity
b) Referential Integrity Constraints
Constraints
c) Domain Integrity Constraints
d) Domain Constraints
DBMS helps achieve
a) Data independence d) both (a)
17 b) Centralized control of data and (b)
c) Neither (a) nor (b)
d) both (a) and (b)
A set of possible data values is called
a) Attribute
18 b) Degree d) Domain
c) Tuple
d) Domain
a) that there
must not
Second Normal form requires ………….
be any
a) that there must not be any partial dependency of any column on
partial
primary key
dependen
19 b) that every non-prime attribute of table must be dependent on
cy of any
primary key
column
c) that each column must have a unique value
on
d) None of the above
primary
key
The Database System Environment consists of
a) Hardware
20 b) DBMS software b) a and b
c) a and b
d) None of these
In a relation
a) Ordering of rows is unimportant c) a and b
21 b) No two rows are identical both are
c) a and b both are true true
d) None of these.
................... are defined as the set of fields from which primary key
can be selected.
a) Super Key b) Candidate
22
b) Candidate key key
c) Secondary Key
d) Composite Key
In the relational modes, cardinality is termed as
a) Number of tuples
a) Number
23 a) Number of attributes
of tuples
b) Number of tables
b) Number of constraints
Database is collection of………….
a) None of these
c) Data
25 b) Programs
c) Data
d) Information
The attribute name could be structured as an attribute consisting of
first name, middle initial, and last name. This type of attribute is
called
b) Composite
26 a) Simple attribute
attribute
b) Composite attribute
c) Multivalued attribute
d) Derived attribute
The attribute AGE is calculated from DATE_OF_BIRTH. The
attribute AGE is
a) Single valued
28 d) Derived
b) Multi valued
c) Composite
d) Derived
Not applicable condition can be represented in relation entry as
a) NA
b) 0
29 c) NULL
c) NULL
d) Blank Space
Which of the following can be a multivalued attribute?
a) Phone number a) Phone
30 b) Name number
c) Date of birth
d) All of the mentioned
An entity in A is associated with at most one entity in B, and an
entity in B is associated with at most one entity in A. This is called
as
b) One-to-
31 a) One-to-many
one
b) One-to-one
c) Many-to-many
d) Many-to-one
An entity in A is associated with at most one entity in B. An entity
in B, however, can be associated with any number (zero or more) of
entities in A.
d) Many-to-
32 a) One-to-many
one
b) One-to-one
c) Many-to-many
d) Many-to-one
DBMS stands for…………...
d) Database
a) Database Basic Management System
Managem
33 b) None of these
ent
c) Database Administrator System
System
d) Database Management System
A relational database developer refers to a record as
a) a criteria
34 b) a relation c) a tuple
c) a tuple
d) an attribute
A file manipulation command that extracts some of the records from
a file is called
a) Select a) Select
35
b) Project
c) Join
d) Product
Which of the following is not basic element of a part of ER
modeling?
a) Entities d) Primary
36
b) Attributes key
c) Relationships
d) Primary key
a) column
containing
Foreign key is:
the
a) Column containing the primary key of another table
primary
37 b) Used to define data types
key of
c) Used to define null status
another
d) All of the above are above correct
table.

In ER Diagram, relationship is represented using?


a) Diamond
38 b) Rectangle a) Diamond
c) Eclipse
d) Double rectangle
Which of the following operation is used if we are interested in only
certain columns of a table?
a) Projection
39 a) Projection
b) Selection
c) Union
d) Join
In E-R Diagram derived attribute is represented by
a) Ellipse
b) Dashed
40 b) Dashed ellipse
ellipse
c) Rectangle
d) Triangle
Which normal form is considered adequate for relational database
design?
a) 2 NF
41 b) 3 NF
b) 3 NF
c) 4 NF
d) BCNF
DBMS Functions
a) Security management a) Security
42 b) DBMS software managem
c) Data model ent
All of these
Sources of Business Rules
d)
a) DESIGNER Data base
Departme
43 b) Admin
nt
c) Data
managers
d) Department managers
………….. produces the relation that has attributes of R1 and R2
a) Cartesian product
a) Cartesian
44 b) Difference
product
c) Intersection
d) Product
Which of the following is not the feature of DBMS?
a) Query language
Data
45 b) Update
dictionary
c) Data dictionary
Backup & recovery
DBMS is a collection of ………… that enables user to create and
maintain a database.
d) Keys c) Program
46
e) Translators
f) Program
D) Language Activity
In the relational modes, cardinality is termed as
a) Number of tuples
Number of
47 b) Number of attributes
tuples
c) Number of tables
d) Number of constraints
Which of the following operation is used if we are interested in only
certain columns of a table?
a) Projection
48 Projection
b) Selection
c) Union
d) Join
DBLC is stand for Database Life Cycle
49 a) TRUE a) TRUE
b) FALSE
Conceptual Data Model This model contains more detail than the
conceptual ER model, without regard to how information will be
50 physically implemented in the database. b) FALSE
a) TRUE
b) FALSE
Normalization Process for evaluating and correcting table structures
to minimize data redundancies
51 a) TRUE
a) TRUE
b) FALSE
Physical Design used to translate conceptual design into internal
model for a selected database management system
52 b) FALSE
a) TRUE
b) FALSE
Connectivity Used to describe the relationship classification
Cardinality
53 a) TRUE
a) TRUE
b) FALSE
Cardinality is the minimum number of times an instance in one
entity can be associated with an instance in the related entity, on the
other hand Ordinality, refers to the maximum number of times an
54 b) FALSE
instance in one entity can relate to instances of another entity.
a) TRUE
b) FALSE
A table is in 3NF if it is in 2NF and there are no transitive
dependencies
55 a) TRUE
a) TRUE
b) FALSE
Recursive Relationships Naturally found within a binary
relationship
56 b) FALSE
a) TRUE
b) FALSE
foreign key a super-key without redundancies
57 a) TRUE b) FALSE
b) FALSE
Conceptual design is Data modeling used to create an abstract
database structure that represents real-world objects in the most
a) TRUE
58 realistic way possible
a) TRUE
b) FALSE
composite key Control data redundancies by using common
attributes shared by tables
59 a) FALSE
a) TRUE
b) FALSE
Join allows us to combine information from two or more
Tables a) TRUE
60
a) TRUE
b) FALSE
The Conversion to third Normal Form done through identify all key
61 components and identify the dependent attributes b) FALSE
a) TRUE b) FALSE
Natural Join Links tables by selecting only rows with common
values in their common attributes
62 a) TRUE
a) TRUE
b) FALSE
DBLC is stand for Database file Cycle
63 a) TRUE b) FALSE
b) FALSE
Conversion to second Normal Form Remove the Dependent
Attributes from Transitive Dependencies
64 b) FALSE
a) TRUE
b) FALSE
multivalued attributes, you should not implement them in the
relational DBMS
65 a) TRUE
a) TRUE
b) FALSE
Data redundancy led to data inconsistence which mean conflicting
and Different versions of the same data appear in different location.
66 a) TRUE
a) TRUE
b) FALSE
A relation in a relational database has certain properties
Its name must be unique in the database each row cannot be
67 duplicated. a) TRUE
a) TRUE
b) FALSE
A database is basically a groups of data) stored on the computers
68 a) TRUE a) TRUE
b) FALSE
Provides for data collection, storage, and retrieval Composed of
people, hardware, software, database(s), application programs, and
69 procedures a) TRUE
a) TRUE
b) FALSE
multivalued attributes, you should not implement them in the
relational DBMS a) TRUE
70
a) TRUE
b) FALSE
1. Give examples (other than those described in your notes) for each of the
following:
• Derived attribute
• Multi-valued attribute
• Composite attribute
• Weak entity type

• Unary relationship
• Ternary relationship
Draw an E-R diagram for each of the following situations (if you believe that you
need to make additional assumptions, clearly state them for each situation):
a. A company has a number of employees. The attributes of EMPLOYEE include
Employee-ID (identifier), Name, Address, and Birth date. The company also has
several projects. Attributes of PROJECT include Project-ID (identifier), Project-
Name, and Start - Date. Each employee may be assigned to one or more projects,
or may not be assigned to a project. A project must have at least one employee
assigned, and may have any number of employees assigned. An employee's
billing rate may vary by project, and the company wishes to record the applicable
billing rate (Billing-Rate) for each employee when assigned to a particular
project.
b. A university has a large number of courses in its catalog. Attributes of COURSE
include Course-Number (identifier), Course Name, and Units. Each course may
have one or more different courses as prerequisites, or may have no
prerequisites. Similarly, a particular course may be a prerequisite for any number
of courses, or may not be prerequisite for any other course.
c. A college course may have one or more scheduled sections, or may not have a
scheduled section. Attributes of COURSE include Course ID, Course Name, and
Units. Attributes of SECTION include Section-Number and Semester-ID.
Semester-ID is composed of two parts: Semester, and Year. Section-Number is
an integer (such as "1" or "2") that distinguishes one section from another for
the same course but does not uniquely identify a section.
d. The entity type STUDENT has the following attributes: Student-Name, Address,
Phone, Age, Activity, and No-of-Years. Activity represents some campus-based
student activity, while No-of-Years represents the number of years the student
has engaged in this activity. A given student may engage in more than one
activity Draw an F-R diagram for this situation.
Introduction to Databases

PWSP CLASS
DATABASE MANAGEMENT

INSTRUCTOR: SANJAY GOEL


FEBRUARY 26-27, 2008

3/4/2007 Sanjay Goel, School of Business, University at Albany 1


E-R DIAGRAMS

3/4/2007 Sanjay Goel, School of Business, University at Albany 47


ER-Diagrams
Definition
• They provide a way to pictorially depict the entities, attributes
and relationships.
– These are also called semantic networks.
• There are three elements of the ER-Diagram
– Entities are represented by labeled rectangles. The label is the name of
the entity.
– Attributes are represented by oval boxes and contain the name of the
entity
– Relationships are represented by a diamond connected to the two entities
using solid lines
(cardinality of many is represented by an infinity sign, cardinality of 1 is
represented by a 1)
– Weak entities are represented by a rectangle curved at the corners and the
relationship triangle curved at the corners

3/4/2007 Sanjay Goel, School of Business, University at Albany 48


ER-Diagrams
Book Database
• Among book authors there are people who are not
primary authors but are contributors.
– e.g. illustrators, indexers etc.
– Each has a different level based on the contribution
• A separate entity can be used to represent contributors
– Attributes: Level and Type.
• Let us now define the relationships.
– A Book is written by authors
– A Book is published by a publisher
– A Contributor is an author
• Once this semantic model is created we need to create a
relational database with this semantic model.
3/4/2007 Sanjay Goel, School of Business, University at Albany 49
E-R Diagrams
Book Database
Title AuName

ISBN Price AuID AuPhone

Books M Written By
N Authors
N 1
Published By Is A

1 1
Publishers Contributor

PubID PubPhone ConID ConLevel

PubName ConType

3/4/2007 Sanjay Goel, School of Business, University at Albany 50


E-R Diagrams
Interior Designer
An interior designers who specializes in home kitchen designs offers a variety
of seminars at home shows, kitchen and appliance stores, and other public
locations. The seminars are free; she offers them as a way of building her
customer base. She earns revenue by selling books and videos and instructs
people on kitchen design. She also offers custom-design consulting services.
Her business is in selling products to the attendees at her seminars. She would
like to develop a database to keep track of customers, the seminars that they
have attended, and the purchases that they have made.
Please determine the entities, attributes and relationships that should exist in
the database and draw an E-R diagram.
(Source: Database Concepts by Kroenke)

3/4/2007 Sanjay Goel, School of Business, University at Albany 51


E-R Diagrams
Interior Designer
Date CustName

Time SeminarID CustID CustPhone


CustAddr
Location Seminar M Attended By
N Customer
1 M CustEmail
Title
Buys
Requests

N N
ConRate Consulting ProdQty Product ProdPrice

ConID ConType ProdID ProdType

ConHours ProdName

3/4/2007 Sanjay Goel, School of Business, University at Albany 52


E-R Diagrams
Interior Designer
Attendance
CustName
SeminarID CustID
Time CustPhone
CustID
SeminarID
M N CustAddr
Date Seminar Attended By Customer
Location 1 M CustEmail

Title Requests
Buys CustID
N N ProdID
Purchase
Date
Quantity
ConRate Consulting ProdQty Product

ConID ConType ProdID ProdType

ConHours ProdName ProdType


3/4/2007 Sanjay Goel, School of Business, University at Albany 53
E-R Diagrams
Supplier
• An organization purchases items from a number of suppliers. It keeps track of
the items purchased from each supplier, and it also keeps a record of
suppliers' addresses. Items are identified by ITEM-TYPE and have a
DESCRIPTION. There may be more than one such address for each
supplier, and the price charged by each supplier for each item is stored.
Suppliers are identified by SUPPLIER-ID.

3/4/2007 Sanjay Goel, School of Business, University at Albany 54


E-R Diagrams
Supplier (Base)

SupStreet ProdName

SupCity SupPhone ProdID ProdDesc

SupZip Address Items ProdType


N M
Has

1
SupID Supplier N Supplies

SupName SupPhone

3/4/2007 Sanjay Goel, School of Business, University at Albany 55


E-R Diagrams
Supplier (Expanded)
SupStreet

SupCity SupPhone

SupZip

Address

N
Has ProdType

SupPhone ProdName
1
N M
SupID Supplier Supplies Items ProdDesc

SupName ProdID
Purchase

SupID ProdID Date Quantity

3/4/2007 Sanjay Goel, School of Business, University at Albany 56


E-R Diagrams
Hospital
• A hospital stores data about patients, their admission and discharge from
departments and their treatments, For each patient, we know the name,
address, sex, social security number, and insurance code (if existing). For each
department, we know the department's name, its location, the name of the
doctor who heads it, the number of beds available, and the number of beds
occupied. Each patient gets admitted at a given date and discharged at a given
date. Each patient goes through multiple treatments during hospitalization; for
each treatment, we store its name, duration, and the possible reactions to it
that the patient may have.

3/4/2007 Sanjay Goel, School of Business, University at Albany 57


E-R Diagrams
Hospital
Date Time

ssn Admission

fname
PatientSSN DepartmentId id
lname

location
1 M N
Patients Admitted To Departments
M name
sex M 1

PatientSSN N head
Insurance
Pat/Treatment Get Occupy has A
TreatmentID name
N
id
duration N N N

Treatments Occupancy Beds type


1

Description

id

3/4/2007 Sanjay Goel, School of Business, University at Albany 58


E-R Diagrams
Building
1. Each building in an organization has a different BUILDING-NAME and a
BUILDING-ADDRESS. The meeting rooms in each building have their
own ROOM-NO in the building, and each room has a specified
SEATING-CAPACITY. Rooms are available for hire for meetings, and
each hire period must start on the hour. The hour and LENGTH-OF-USE
are recorded. Each hire is made by a group in the organization, and groups
are identified by a GROUP-NO and have a CONTACT-PHONE. The
equipment required for each hire period also are recorded. Each facility has
an EQUIP-NO and a DESCRIPTION.

3/4/2007 Sanjay Goel, School of Business, University at Albany 59


E-R Diagrams
Building
Number Description

Equipment
1
N

N EquipmentNo
Get Rental
starttime length N MeetingId
Date MeetingId

M
number Meeting 1

name
GroupNumber RoomId id
ContactPhone
Capacity
1 M N
Group Rents Room
id
M 1
head
Get has A

id
N
Building type

3/4/2007 Sanjay Goel, School of Business, University at Albany 60


E-R Diagrams
Projects
1. A company has a number of employees. The attributes of EMPLOYEE
include Employee_ID (identifier), Name, Address, and Birthdate. The
company also has several projects. Attributes of PROJECT include
Project_ID (identifier), Project_Name , and Start-date. An employee’s
billing rate may vary by project and the company wishes to record the
applicable billing rate (Billing_Rate) for each employee when assigned to a
particular project.

3/4/2007 Sanjay Goel, School of Business, University at Albany 61


E-R Diagrams
Projects

ProjectId EmployeeID BillingRate hours

1
Assignment

id StartDate EndDate

id
name
M N
Employee Rents Project Name
Address
StartDate
DateOfBirth

3/4/2007 Sanjay Goel, School of Business, University at Albany 62


E-R Diagrams
Chemists
1. A laboratory has several chemists who work on one or more projects. Chemists
also may use certain kinds of equipment on each project. Attributes of CHEMIST
include Employee_ID (identifier), Name, and Phone_No. Attributes of PROJECT
include Project_ID (identifier) and Start_Date. Attributes of EQUIPMENT include
Serial_No and Cost. The organization wishes to record Assign_Date, that is, the
date when a given equipment item was assigned to a particular chemist working on
a specified project. A chemist must be assigned to at least one project and one
equipment item. A given equipment item need not be assigned, and a given project
need not be assigned either a chemist or an equipment item.

3/4/2007 Sanjay Goel, School of Business, University at Albany 63


E-R Diagrams
Chemists

ProjectId EmployeeID StartDate EndDate

1
Project/Chemist

id
id
name
M N
Chemist Works on Project Name
Address M N
StartDate
Phone

Assigned to

N
Equipment

SerialNo Cost
3/4/2007 Sanjay Goel, School of Business, University at Albany 64
E-R Diagrams
Video Rental Store
• You were hired by Blockywood Video to design a database for their video rental system. Luckily, you have
had some experience renting videos (every Saturday night!) and you know that the video store needs to be
able to information about customers, movies, and distributors.
• A movie title (e.g. Lord Voldemort of the Rings) has an ID number generated by the store. In addition,
there is a title, release date, rating (G, PG-13, etc.), and price category (a newly released movie tends to be
more expensive). Other movie related information saved is the director, producer, principal actor, and
principal actress.
• Jane Doe is a customer and to rent movies, she is the owner of a Blockywood Video card which is scanned
every time she makes a purchase. To obtain a card the owner needs to be above 18 (checked during
application). The account associated with the card has a specific ID number (generated by the store), as
well as the owner name (Jane Doe), her address, phone number, credit card information (optional), and
amount credited/debited to the account. Additionally, she has both her husband (John Doe) and her son
Jimmy Doe listed as other authorized users on the account and a rating for Jimmy of PG-13, which means
that the video rental store is not allowed to let him have access to a higher rating video. Her husband also
owns a Blockywood Video card in which Jane and Jimmy are listed as authorized users.
• Distributors have organizational names, an address, representative, and phone number. Videos are
purchased from distributors on a specific date for a specific price. There can be multiple videos with the
same movie title. Videos are also given a unique id number.
• The video rental system allows for a video rental history, which maintains the video rented, rental date, card
that it was rented with, return date, and amount paid. This information helps the recommendation of new
videos and to maintain accounts. The video rental system should also be able to specify the maximum
number of videos a customer can rent and the amount of time a movie can be late until the account is
frozen.
3/4/2007 Sanjay Goel, School of Business, University at Albany 65
Price Date
E-R Diagrams
Credit/Debit Amount AccountId MovieId
Video Rental Store
CreditCardNumber
Rental
N N
MaxMoviesAllowed

1 1
PrimaryMemberId
Account Admitted By Video Is of a
N M N
AccountId
M 1
VideoId Type
FreezeLimit
PriceCategory
MemberId MovieId Director
Get N
Membership
PrincipalActor
AccountId Title

N N 1
PrincipalActress
1 Producer
Member

ReleaseDate Rating
name MemberId

Movie MovieId
MovieId 1
rating M
N
Type
Invoice Sold By
Assumptions:
1. Multiple distributors can sell same movie Number N
2. Each member can be many accounts and the same account
N
can have many members 1
Distributor phone
3. Video rental store does not track the origin of a specific video Price
from the distributor
4. Media type was added as additional attribute to the video name RepName
(VHS or DVD)

3/4/2007 Sanjay Goel, School of Business, University at Albany 66


Address
E-R Diagrams
Real Estate Firm
• Prepare an E-R diagram for a real estate firm that lists property for sale. Please
indicate primary key and foreign keys as well as relationships. The following
describes this organization:
• The firm has a number of sales offices in several states. Attributes of sales office
include Office_Number (identifier) and Location.
• Each sales office is assigned one or more employees. Attributes of employee
include Employee_ID (identifier) and Employee_Name. An employee must be
assigned to only one sales office.
• For each sales office, there is always one employee assigned to manage that office.
An employee may manage only the sales office to which he or she is assigned.
• The firm lists property for sale. Attributes of property include Property_ID
(identifier) and Location.
• Each unit of property must be listed with one (and only one) of the sales offices. A
sales office may have any number of properties listed, or may have no properties
listed.
• Each unit of property has one or more owners. Attributes of owners are Owner_ID
(identifier) and Owner_Name. An owner may own one or more units of property.
An attribute of the relationship between property and owner is Percent_Owned.
• Note: Components of Location include Address, City, State, and Zip_Code &
Components of the name include f_name and l_name
3/4/2007 Sanjay Goel, School of Business, University at Albany 67
E-R Diagrams
Real Estate Firm
Office_Number

Zip_Code
Address

City State

Employee_Id
1

8
Assigned To SalesOffice Lists
1
Office_Number 8

8
Property_ID
ManagerID
8

City
1
8

8
Employee_Lname
1 Address
Employee Manages Property
Employee_Fname State
1

8
Office_Number
Zip_Code

8
Employee_Id
Owner_Id

8
Owner Owns Property_ID
Owner_Lname
8

Percent_Owned

3/4/2007 Owner_Id
Sanjay Owner_Fname
Goel, School of Business, University at Albany 68
E-R Diagrams
Concerts
• After completing a course in database management, you have been asked to
develop an E-R diagram for a symphony orchestra. The symphony orchestra
has the following characteristics
• A concert season schedules one or more concerts. A particular concert is
scheduled for only one concert season.
• A concert includes the performance of one or more compositions. A
composition may be performed at one or more concerts, or may not be
performed.
• For each concert there is one conductor. A conductor may conduct any
number of concerts, or may not conduct any concerts.
• Each composition may require one or more soloists, or may not require a
soloist. A soloist may perform one or more compositions at a given concert,
or may not perform any composition. The symphony orchestra wishes to
record the date when a soloist last performed a given composition.
• Some other attributes of interest are the names and contact information of the
soloist, composer and the location of the concert. The following entities are
evident from the above discussion, i.e. ConcertSeason, Concert, Composition,
Conductor, Soloist. Based on the above observations define what the
appropriate relationships and attributes in the schema and construct an E-R
diagram.
3/4/2007 Sanjay Goel, School of Business, University at Albany 69
E-R Diagrams
Concerts location date
time
1 time
ConcertSeason Schedules
duration
N
N
Concert Conducts
season 1
N
N
1 lname
concert/composition Includes
SoloId Conductor
N
N
fname
1
Composition phone email
1
N
N ComId
Played
soloist/composition By
N
N
lname
1
Soloist
fname
phone email
SoloId
3/4/2007 Sanjay Goel, School of Business, University at Albany 70
E-R Diagrams
Quick Oil
• Design the database and show an E-R Diagram for the case below. For
many-to-many entities, show the additional tables that you would create.

• Quick Oil Company is in the business of changing engine oil for its
customers. In addition to changing oil, the company also performs
other services such as changing wipers, light bulbs etc. There are several
technicians assigned to a car as it comes in for an oil change. They
maintain the name, address, social security number, phone, and
email address of the customer. In addition, the services that the
customers purchase at different times are tracked. For each service, they
store the name of the service, the cost of the service, description of
the service, and number of hours of labor for the service. They
maintain employee information including name, phone, social
security number, address, date-of-birth, date-of-hire, and their
hourly salary in the database. They also sell parts and the name,
manufacturer, cost, weight and number of items of each part is stored.
A list of parts is maintained in the database and customers that bought
each part are tracked.
3/4/2007 Sanjay Goel, School of Business, University at Albany 71
E-R Diagrams Count

Quick Oil name


Manufacturer Parts
Cost M

Weight
PartName
Date EmployeeSSN Buys Part/Customers
SSN
labor name CustomerSSN
name N
M
Description Service Work N Customer
Cost street

city SSN

state Name

zip email
N phone
1 Employee name
street
phone
city
SSN
state
DateOfBirth
zip
DateOfHire

Salary

3/4/2007 Sanjay Goel, School of Business, University at Albany 72


E-R Diagrams
Student Interviews
The School of Business would like to help its MBA students with placement in various companies
and firms. To facilitate this, they need to design a database with the primary purpose of scheduling
interviews and facilitating searches by students and companies that are looking for candidates. The
database should have information about students, job openings, companies, interviewers,
interviews, and conference rooms for interviews. Students have a lot of information that needs to
be processed. This includes a first name, last name, student id number, social security number,
concentration, and expected graduation date. Companies post job openings that students can apply
for. The job posting date is recorded as well as the deadline of the posting. Also included is the title
of the position, base salary, minimum requirements, and description. Students apply for open
positions in companies and the date and time of each application is recorded. Students should also
be able to see the status of their application (whether there will be a follow-up interview and
whether they were turned down for the position). Interviews can be facilitated by the University or
because of job openings and need to have a date, time, and conference room location. Multiple
students can be interviewed at the same time and multiple interviewers can participate in a student
interview. Companies send employees who interview students. An employee has an employee id,
room #, telephone #, fax #, and position title. The company keeps track of which employees
interviewed which students as well as the result of the interview (if it resulted in a job offer and/or
hiring). A company has an identifier, name, main contact #, and main fax number. A company
from the Business School reserves conference rooms and the company needs to specify the
resources needed (e.g. computer, projector, etc.). There are multiple conference rooms and multiple
instances of the same resource (e.g. there may be three projectors). The School should be able to
track which company hired which students as well as how many students came from which
concentration. In addition, such statistics as the average salary for the jobs per year should be
available. Students should also be able to track their job offers.

3/4/2007 Sanjay Goel, School of Business, University at Albany 73


E-R Diagrams
Student Interviews Capacity

Conference Room CR_Location

1
CR_Id
Interviewer_Id
Street
Held In
Interviewer_Lname Interviewer_Fname Interview_Date
State Interviewer_Id Interview_Id
Posting_Id

8
Interview_Id
Zip_Code
8

8
Assigned CR_Id
Interviewer Interview
1 To 1
8

8
City Interview_Time
8

Student_Id
Interviewer_Id
Address Interview_Duration
Works
Conducted
For
For
State Company_Id std_lname std_fname

std_id Phone
8

Zip_Code
1 1 Posts 1
8

8
Email

8
Company Posts Job_Posting Student
For
8

8
City
Major
Job_Description Salary_Range City
Address Name
Posting_Id Street
Posting_ID
Zip_Code
Email Posting_Title
Street Student_Id State
3/4/2007 Sanjay Goel, School of Business, University at AlbanyApply_Date 74
Phone Posting_Date Posting_Time
Company_Id Apply_Time
E-R Diagrams
Handy Man
With a busy work life, home owners have difficulty in finding
help for chores around the house and garden. Different jobs
require different skills, such as, carpentry, plumbing, electrical
wiring, etc. Several people have these skills and spare time to
work on projects but are unable to find places for part time
employment. This business entails connecting people who have
jobs with workers willing to work on those jobs in their spare
time. The workers should be able to list their contact information
and skills. The employers should be able to list the jobs and the
skills required for each job. The business model of the company is
to get an enrollment fee for joining the network for both the
home owners and the workers. Please design a database and
create an E-R Diagram for the database

3/4/2007 Sanjay Goel, School of Business, University at Albany 75


E-R Diagrams
Handy Man
Job/Skill Skill Worker/Skill WorkerID

fname

lname
workerid Grade

semester city
memberId 1
1
N N
Job Accepts Worker street
1 1 zip
memberid
Provides N phone
N Takes
Gets Acceptance
firstname
email
lastname 1 Salary
JobID gender
Home Owner WorkerID
Homephone

email

workphone

3/4/2007 Sanjay Goel, School of Business, University at Albany 76


E-R Diagrams
Course Offerings
There are several courses on the books at a university which are offered from time to
time. Students enroll for these courses. We assume there are no pre-requisites for the
courses. Please create an E-R Diagram for the database. Assume reasonable attributes
for the different entities and also write any assumptions that you make.

3/4/2007 Sanjay Goel, School of Business, University at Albany 77


E-R Diagrams
Course Offerings
semester

Section CourseId Grade

semester
StudentId

Enrollment CourseID

section
studentid
semester
firstname
M N
Student Take Offering year
lastname
N time
DateOfBirth

Results in daysofweek

room

1
CourseID
Course
CreditHours

description
3/4/2007 Sanjay Goel, School of Business, University at Albany 78
E-R Diagrams
Conference Center Bookings
Instructions: Draw an entity relationship diagram for the case, stating any
assumptions you deem necessary.
Case: A conference centre takes bookings from clients who wish to hold
courses or conferences at the centre. When clients make bookings they specify
how many people are included in the booking, and of these, how many will be
resident during the booking, and how many will require catered or non-catered
accommodation at the centre. The centre contains a number of facilities which
may be required by clients making bookings as follows:
A. There are 400 bedrooms for clients who will be resident during the Course
or conference.
B. A maximum of 250 catered people can be handled at any one time.
C. Six main lecture theatres providing seating for 200 people.
D. Twenty seminar rooms each able to accommodate 25 people.
E. Video conference facilities. The video conference facilities consist of four
separate video conference networks. Each video conference network has a
large screen based in one of the main lecture theatres, along with 3 satellite
screens each of which is based in one of the seminar rooms.

3/4/2007 Sanjay Goel, School of Business, University at Albany 79


E-R Diagrams
Conference Center Bookings
The London and Ireland Shipping Company PLC (LISC) was founded in 1852 and owns a fleet of cargo ships.
The company had historically run passenger liners, but recent policy decisions involved the sale of all passenger-
carrying vessels. The company currently has 14 vessels, including one oil tanker and one tugboat operating out of
Liverpool. Most of the vessels are registered in Liberia for tax reasons.
Each ship has one or more holds divided into spaces. The holds are defined by steel bulkheads and the spaces
are defined by shelf racks or other physical dividers. Sister ships, built by the same shipbuilders and to the same
designs have similar names, such as Pride of Ireland, Queen of Ireland, Song of Ireland and Warrior of Ireland. Sister ships
also have identical cargo storage facilities.
LISC issues contracts to agents for one or more manifests (lists of cargo items to be shipped). LISC's charges for
cargo carried are based on the number of spaces the cargo requires for storage. The types of cargo typically
carried by LISC include grain, coal and ores (carried only in ships equipped with bulk cargo holds). They also
transport sacked grain, heavy cases, containers (which may be carried on deck), pallets and so on.
Cargo items may take up less than one space in a hold, or one or more spaces, depending on the size of the item.
A space may therefore contain several small cargo items.
The ships owned by LISC are kept as busy and as full as possible, in order to maximise the profits that each
vessel makes and minimise running & operating costs. LISC's ships ply most of the seas of the world, but tend to
operate mainly in the Mediterranean, the North and Mid Atlantic and the Indian Ocean. Different ships require
different crew complements.
LISC intends to create a computer based information system that will be able to perform the following tasks:
– Record the voyages of each ship with the start and end ports.
– Record the cargo held by a ship on each voyage
– Keep records of their employees and the ships they are assigned to
– Producing invoices for agents and customers
– Keep a record of customers' payments on invoices
– Analyse the efficiency of use of cargo space and of percentage wasted cargo space for ships voyages

3/4/2007 Sanjay Goel, School of Business, University at Albany 80


Databases
Translating ERD to Database
• Each entity becomes a new table
• Each attribute becomes a column of the table
• Relationships
– One to many relationship: Add the key from the many side of the
relationship to the one side of the relationship
e.g. add the publisher id to the book entity
The pubID is called a foreign key because this is a key to a foreign entity
– One to one relationship: Add the primary key of one entity to the other
entity
– Many to many relationship: We can not add the foreign key of each to
the other considering these as two one to many relationships. This leads
to duplicated rows.
– To implement a many-to-many relationship add an artificial entity to
break the many-to-many relationship into two one-to-many relationships.
3/4/2007 Sanjay Goel, School of Business, University at Albany 81
Databases
Integrity
• Referential Integrity: Each value of foreign key must have a
matching value in the referenced key.
– Otherwise we will have a dangling reference
e.g. If there was no publisher matching PubID then we have a problem.
• Violations can occur in two ways
– We add a new entry in the books table with no corresponding publisher
in the publisher table
– We delete an entry in the referenced table without deleting the
corresponding entry in the referencing table
• Two ways to ensure Integrity
– Cascading updates: If a referenced key is changed then all matching
entries in the foreign key are automatically updated
– Cascading deletions: If a value of the referenced table is deleted by
deleting a row then all rows in the referencing table that refer to the
deleted key value will also be deleted.
3/4/2007 Sanjay Goel, School of Business, University at Albany 82
Quiz (1)
Model A
1. Discuss the capabilities that should be provided by a DBMS.
2. Give examples for each of the following:
a) Derived attribute
b) Ternary relationship
3. Draw an E-R diagram with all required cardinalities (if you believe
that you need to make additional assumptions, clearly state them
for each situation):
A professor wants to implement an online grade book to keep track
of and display student grades for several courses. Courses can
generally be differentiated by department, course number,
semester, and year, and knowing the course title can be useful. For
each class, the grade is determined by grades on various categories,
including tests, quizzes, homework, labs, projects, etc. The
percentages of the categories should add to 100%. The number of
assignments from each category is unspecified, and can change at
any time.
Model B
1. Discuss the main characteristics of the database approach and how
it differs from traditional file systems.
2. Give examples for each of the following:
a. Composite attribute
b. Weak entity type
3. Draw an E-R diagram with all required cardinalities (if you believe
that you need to make additional assumptions, clearly state them
for each situation):
A college course may have one or more scheduled sections, or may
not have a scheduled section. Attributes of COURSE include Course
ID, Course Name, and Units. Attributes of SECTION include
Section-Number and Semester-ID. Semester-ID is composed of two
parts: Semester, and Year. Section-Number is an integer (such as "1"
or "2") that distinguishes one section from another for the same
course but does not uniquely identify a section.
Model C
1. What is a data model? Discuss the main types of data model.
2. Give examples for each of the following:
a. Unary relationship
b. Multi-valued attribute
3. Draw an E-R diagram with all required cardinalities. for each of the
following situations (if you believe that you need to make additional
assumptions, clearly state them for each situation):
A company has a number of employees. The attributes of
EMPLOYEE include Employee-ID (identifier), Name, Address, and
Birth date. The company also has several projects. Attributes of
PROJECT include Project-ID (identifier), Project-Name, and Start -
Date. Each employee may be assigned to one or more projects, or may
not be assigned to a project. A project must have at least one
employee assigned, and may have any number of employees assigned.
An employee's billing rate may vary by project, and the company
wishes to record the applicable billing rate (Billing-Rate) for each
employee when assigned to a particular project.
Relational Algebra

Index
• Review of Relational Algebra
o Set Theoretic Operations
o Union, Intersection and Difference
o Union Compatible Relations
o Cartesian Product
o Selection and Projection
Selection Operator
Selection Examples
Projection Operator
Projection Examples
Combining Selection and Projection
o Aggregate Functions
o Join Operations
Join Examples
Natural Join
Outer Join
o Outer Union

Review of Relational Algebra


Hoffer, Prescott
Elmasri/Navathe Kroenke Connolly/Begg Rob/Coronel
& McFadden
(3rd) ed. (7th ed.) (3rd Ed.) (5th ed)
(6th ed.)

Chapter 7 Chapter 8 Chapter 4 N/A N/A

• Recall, the Relational Model consists of the elements: relations, which are made
up of attributes.
• A relation is a set of attributes with values for each attribute such that:
1. Each attribute value must be a single value only (atomic).
2. All values for a given attribute must be of the same type (or domain).
3. Each attribute name must be unique.
4. The order of attributes is insignificant
5. No two rows (tuples) in a relation can be identical.
6. The order of the rows (tuples) is insignificant.
• Relational Algebra is a collection of operations on Relations.
• Relations are operands and the result of an operation is another relation.
• Two main collections of relational operators:
1. Set theory operations:
Union, Intersection, Difference and Cartesian product.
2. Specific Relational Operations:
Selection, Projection, Join, Division

Set Theoretic Operations


Consider the following relations R and S
R
First Last Age
Bill Smith 22
Sally Green 28
Mary Keen 23
Tony Jones 32
S
First Last Age
Forrest Gump 36
Sally Green 28
DonJuan DeMarco 27

• Union: R S
Result: Relation with tuples from R and S with duplicates removed.
• Difference: R - S
Result: Relation with tuples from R but not from S
• Intersection: R S
Result: Relation with tuples that appear in both R and S.

R S

First Last Age


Bill Smith 22
Sally Green 28
Mary Keen 23
Tony Jones 32
Forrest Gump 36
DonJuan DeMarco 27

R-S

First Last Age


Bill Smith 22
Mary Keen 23
Tony Jones 32

R S

First Last Age


Sally Green 28

Union Compatible Relations


• Attributes of relations need not be identical to perform union, intersection and
difference operations.
• However, they must have the same number of attributes or arity and the domains
for corresponding attributes must be identical.
• Domain is the datatype and size of an attribute.
• The degree of relation R is the number of attributes it contains.
• Definition: Two relations R and S are union compatible if and only if they have
the same degree and the domains of the corresponding attributes are the same.
• Some additional properties:
o Union, Intersection and difference operators may only be applied to Union
Compatible relations.
o Union and Intersection are commutative operations
R S=S R
R S=S R
o Difference operation is NOT commutative.
R - S not equal S - R
o The resulting relations may not have meaningful names for the attributes.
Convention is to use the attribute names from the first relation.

Exercises

• Assume relation T
fName lName Score
William Smith 44
Sally Green 28
Mary Kontrary 27

• Compute R T
Compute R T
Show that R - T is not equal to T - R

Cartesian Product
• Produce all combinations of tuples from two relations.

First Last Age


Bill Smith 22
Mary Keen 23
Tony Jones 32

Dinner Dessert
Steak Ice Cream
Lobster Cheesecake

RXS

First Last Age Dinner Dessert


Bill Smith 22 Steak Ice Cream
Bill Smith 22 Lobster Cheesecake
Mary Keen 23 Steak Ice Cream
Mary Keen 23 Lobster Cheesecake
Tony Jones 32 Steak Ice Cream
Tony Jones 32 Lobster Cheesecake
Selection Operator

• Selection and Projection are unary operators.


• The selection operator is sigma:
• The selection operation acts like a filter on a relation by returning only a certain
number of tuples.
• The resulting relation will have the same degree as the original relation.
• The resulting relation may have fewer tuples than the original relation.
• The tuples to be returned are dependent on a condition that is part of the selection
operator.
• C (R) Returns only those tuples in R that satisfy condition C
• A condition C can be made up of any combination of comparison or logical
operators that operate on the attributes of R.
o Comparison operators:
o Logical operators:
• Use the Truth tables (memorize these) for logical expressions:

T F T F
T F
T T F T T T
F T
F F F F T F

Selection Examples

Assume the following relation EMP has the following tuples:


Name Office Dept Rank

Smith 400 CS Assistant

Jones 220 Econ Adjunct

Green 160 Econ Assistant

Brown 420 CS Associate

Smith 500 Fin Associate

• Select only those Employees in the CS department:


Dept = 'CS' (EMP)
Result:
Name Office Dept Rank

Smith 400 CS Assistant

Brown 420 CS Associate

• Select only those Employees with last name Smith who are assistant professors:
Name = 'Smith' Rank = 'Assistant' (EMP)
Result:

Name Office Dept Rank

Smith 400 CS Assistant

• Select only those Employees who are either Assistant Professors or in the
Economics department:
Rank = 'Assistant' Dept = 'Econ' (EMP)
Result:

Name Office Dept Rank

Smith 400 CS Assistant

Jones 220 Econ Adjunct

Green 160 Econ Assistant

• Select only those Employees who are not in the CS department or Adjuncts:
(Rank = 'Adjunct' Dept = 'CS') (EMP)
Result:

Name Office Dept Rank

Green 160 Econ Assistant

Smith 500 Fin Associate

Exercises

• Evaluate the following expressions:


1. (Rank = 'Adjunct' Dept = 'CS') (EMP)
2. Rank = 'Associate' ( Dept = 'CS' EMP )
3. Dept = 'CS' ( Rank = 'Associate' EMP )
4. Rank = 'Associate' Dept = 'CS' (EMP)
5. Age > 26 (R S)

For this expression, use R and S from the Set Theoretic Operations section
above.

• Do expressions 2, 3 and 4 above all evaluate ot the same thing?

Projection Operator

• Projection is also a Unary operator.


• The Projection operator is pi:
• Projection limits the attributes that will be returned from the original relation.
• The general syntax is: attributes R
Where attributes is the list of attributes to be displayed and R is the relation.
• The resulting relation will have the same number of tuples as the original relation
(unless there are duplicate tuples produced).
• The degree of the resulting relation may be equal to or less than that of the
original relation.

Projection Examples

Assume the same EMP relation above is used.

• Project only the names and departments of the employees:


name, dept (EMP)
Results:

Name Dept

Smith CS

Jones Econ

Green Econ

Brown CS

Smith Fin

Combining Selection and Projection

• The selection and projection operators can be combined to perform both


operations.
• Show the names of all employees working in the CS department:
name ( Dept = 'CS' (EMP) )
Results:

Name

Smith

Brown

• Show the name and rank of those Employees who are not in the CS department or
Adjuncts:
name, rank ( (Rank = 'Adjunct' Dept = 'CS') (EMP) )
Result:

Name Rank

Green Assistant

Smith Associate

Exercises

• Evaluate the following expressions:


1. name, rank ( (Rank = 'Adjunct' Dept = 'CS') (EMP) )
2. fname, age ( Age > 22 (R S) )

For this expression, use R and S from the Set Theoretic Operations section
above.

3. office > 300 ( name, rank (EMP))

Aggregate Functions

• We can also apply Aggregate functions to attributes and tuples:


o SUM
o MINIMUM
o MAXIMUM
o AVERAGE, MEAN, MEDIAN
o COUNT
• Aggregate functions are sometimes written using the Projection operator or the
Script F character: as in the Elmasri/Navathe book.

Aggregate Function Examples

Assume the relation EMP has the following tuples:


Name Office Dept Salary

Smith 400 CS 45000

Jones 220 Econ 35000

Green 160 Econ 50000

Brown 420 CS 65000

Smith 500 Fin 60000

• Find the minimum Salary: MIN (salary) (EMP)


Results:

MIN(salary)

35000

• Find the average Salary: AVG (salary) (EMP)


Results:

AVG(salary)

51000

• Count the number of employees in the CS department: COUNT (name) ( Dept = 'CS'
(EMP) )
Results:

COUNT(name)

• Find the total payroll for the Economics department: SUM (salary) ( Dept = 'Econ'
(EMP) )
Results:
SUM(salary)

85000

Join Operation
• Join operations bring together two relations and combine their attributes and
tuples in a specific fashion.

• The generic join operator (called the Theta Join is:


• It takes as arguments the attributes from the two relations that are to be joined.
• For example assume we have the EMP relation as above and a separate DEPART
relation with (Dept, MainOffice, Phone) :
EMP EMP.Dept = DEPART.Dept DEPART

• The join condition can be


• When the join condition operator is = then we call this an Equijoin
• Note that the attributes in common are repeated.

Join Examples

Assume we have the EMP relation from above and the


DEPART relation: EMP Relation:
Dept MainOffice Phone Name Office Dept Salary

CS 404 555-1212 Smith 400 CS 45000

Econ 200 555-1234 Jones 220 Econ 35000

Fin 501 555-4321 Green 160 Econ 50000

Hist 100 555-9876 Brown 420 CS 65000

Smith 500 Fin 60000

• Find all information on every employee including their department info:


EMP emp.Dept = depart.Dept DEPART
Results:

Name Office EMP.Dept Salary DEPART.Dept MainOffice Phone

Smith 400 CS 45000 CS 404 555-


1212

555-
Jones 220 Econ 35000 Econ 200
1234

555-
Green 160 Econ 50000 Econ 200
1234

555-
Brown 420 CS 65000 CS 404
1212

555-
Smith 500 Fin 60000 Fin 501
4321

• Find all information on every employee including their department info where the
employee works in an office numbered less than the department main office:
EMP (emp.office < depart.mainoffice) (emp.dept = depart.dept) DEPART
Results:

Name Office EMP.Dept Salary DEPART.Dept MainOffice Phone

Smith 400 CS 45000 CS 404 555-1212

Green 160 Econ 50000 Econ 200 555-1234

Smith 500 Fin 60000 Fin 501 555-4321

Natural Join

• Notice in the generic (Theta) join operation, any attributes in common (such as
dept above) are repeated.
• The Natural Join operation removes these duplicate attributes.
• The natural join operator is: *
• We can also assume using * that the join condition will be = on the two attributes
in common.
• Example: EMP * DEPART
Results:

Name Office Dept Salary MainOffice Phone

Smith 400 CS 45000 404 555-1212

Jones 220 Econ 35000 200 555-1234

Green 160 Econ 50000 200 555-1234


Brown 420 CS 65000 404 555-1212

Smith 500 Fin 60000 501 555-4321

Outer Join

• In the Join operations so far, only those tuples from both relations that satisfy the
join condition are included in the output relation.
• The Outer join includes other tuples as well according to a few rules.
• Three types of outer joins:
1. Left Outer Join includes all tuples in the left hand relation and
includes only those matching tuples from the right hand relation.
2. Right Outer Join includes all tuples in the right hand relation and
includes ony those matching tuples from the left hand relation.
3. Full Outer Join includes all tuples in the left hand relation and from
the right hand relation.
• Examples:

Assume we have two relations: PEOPLE and MENU:

PEOPLE: MENU:
Name Age Food Food Day

Alice 21 Hamburger Pizza Monday

Bill 24 Pizza Hamburger Tuesday

Carl 23 Beer Chicken Wednesday

Dina 19 Shrimp Pasta Thursday

Tacos Friday

• PEOPLE people.food = menu.food MENU

Name Age people.Food menu.Food Day

Alice 21 Hamburger Hamburger Tuesday

Bill 24 Pizza Pizza Monday

Carl 23 Beer NULL NULL


Dina 19 Shrimp NULL NULL

• PEOPLE people.food = menu.food MENU

Name Age people.Food menu.Food Day

Bill 24 Pizza Pizza Monday

Alice 21 Hamburger Hamburger Tuesday

NULL NULL NULL Chicken Wednesday

NULL NULL NULL Pasta Thursday

NULL NULL NULL Tacos Friday

• PEOPLE people.food = menu.food MENU

Name Age people.Food menu.Food Day

Alice 21 Hamburger Hamburger Tuesday

Bill 24 Pizza Pizza Monday

Carl 23 Beer NULL NULL

Dina 19 Shrimp NULL NULL

NULL NULL NULL Chicken Wednesday

NULL NULL NULL Pasta Thursday

NULL NULL NULL Tacos Friday

Outer Union
• The Outer Union operation is applied to partially union compatible relations.
• Operator is: *
• Example: PEOPLE * MENU

Name Age Food Day

Alice 21 Hamburger NULL


Bill 24 Pizza NULL

Carl 23 Beer NULL

Dina 19 Shrimp NULL

NULL NULL Hamburger Monday

NULL NULL Pizza Tuesday

NULL NULL Chicken Wednesday

NULL NULL Pasta Thursday

NULL NULL Tacos Friday

You might also like