SlideShare a Scribd company logo
Database Design
Relational Model
Practice Exercises
Exercise 2.4
Problem
• A company database needs to store
information about employees (identified by
ssn, with salary and phone as attributes),
departments (identified by dno, with dname
and budget as attributes), and children of
employees (with name and age as attributes).
Exercise 2.4
Problem
• Employees work in departments; each
department is managed by an employee; a child
must be identified uniquely by name when the
parent (who is an employee; assume that only
one parent works for the company) is known. We
are not interested in information about a child
once the parent leaves the company.
• Draw an ER diagram that captures this
information.
Exercise 2.4
Solution
• First, we shall design the entities and
relationships.
– “Employees work in departments…”
– “…each department is managed by an
employee…”
– “…a child must be identified uniquely by name
when the parent (who is an employee; assume
that only one parent works for the company) is
known.”
Exercise 2.4
Solution
Exercise 2.4
Solution
• Now, we will design the constraints.
– “…each department is managed by an
employee…”
– “…a child must be identified uniquely by name
when the parent (who is an employee; assume
that only one parent works for the company) is
known. “
– “We are not interested in information about a
child once the parent leaves the company.”
Exercise 2.4
Solution
Exercise 2.8
Problem
• Although you always wanted to be an artist, you
ended up being an expert on databases because
you love to cook data and you somehow
confused database with data baste. Your old love
is still there, however, so you set up a database
company, ArtBase, that builds a product for art
galleries. The core of this product is a database
with a schema that captures all the information
that galleries need to maintain.
Exercise 2.8
Problem
• Galleries keep information about artists, their
names (which are unique), birthplaces, age,and
style of art. For each piece of artwork, the artist,
the year it was made, its unique title, its type of
art (e.g., painting, lithograph, sculpture,
photograph), and its price must be stored. Pieces
of artwork are also classified into groups of
various kinds, for example, portraits, still lifes,
works by Picasso, or works of the 19th century; a
given piece may belong to more than one group.
Exercise 2.8
Problem
• Each group is identified by a name (like those
just given) that describes the group. Finally,
galleries keep information about customers.
For each customer, galleries keep that person’s
unique name, address, total amount of dollars
spent in the gallery (very important!), and the
artists and groups of art that the customer
tends to like.
• Draw the ER diagram for the database.
Exercise 2.8
Solution
• Like before, we begin with the entities and
relationships.
• “…artists, their names (which are unique),
birthplaces, age, and style of art.”
• “For each piece of artwork, the artist, the year
it was made, its unique title, its type of art …
and its price must be stored.”
Exercise 2.8
Solution
• “Pieces of artwork are also classified into
groups of various kinds, … Each group is
identified by a name (like those just given)
that describes the group. “
• For each customer, galleries keep that person’s
unique name, address, total amount of dollars
spent in the gallery (very important!), and the
artists and groups of art that the customer
tends to like.
Exercise 2.8
Solution
Adding More Detail
Exercise 2.8
Solution
• Now we look at constraints.
– Although not explicitly mentioned in the problem,
we assume that each piece of artwork had to be
painted by an artist.
– We also assume that each piece of artwork was
created by exactly one artist.
Exercise 2.8
Solution
Exercise 2.8
Solution
• Suppose we had several piece of artwork with
the same title, and we told them apart by
artist?
• Example: “What is Love?” by Cheryl D, “What
is Love?” by Joe Brown, etc.
Exercise 2.8
Solution
Exercise 3.14
Problem
• Consider the scenario from Exercise 2.4,
where you designed an ER diagram for a
company database. Write SQL statements to
create the corresponding relations and
capture as many of the constraints as possible.
If you cannot capture some constraints,
explain why.
Exercise 3.14
ER Diagram from Exercise 2.4
Exercise 3.14
Solution
• First we begin with the entities “Employees”
and “Departments.
• Translating these to SQL is straightforward.
Exercise 3.14
Solution
CREATE TABLE Employees(
ssn CHAR(10),
sal INTEGER,
phone CHAR(13),
PRIMARY KEY (ssn) )
CREATE TABLE Departments (
dno INTEGER,
budget INTEGER,
dname CHAR(20),
PRIMARY KEY (dno) )
Exercise 3.14
Solution
• Next, we translate the relationships, Manages
and Dependents.
• We translate each these to a table mapping
one entity to another.
• We also use foreign constraints to make sure
every row in the relationship tables refers only
to rows that exist in the entity tables.
Exercise 3.14
Solution
CREATE TABLE Works_in(
ssn CHAR(10),
dno INTEGER,
PRIMARY KEY (ssn, dno),
FOREIGN KEY (ssn)
REFERENCES Employees,
FOREIGN KEY (dno)
REFERENCES Departments)
CREATE TABLE Manages (
ssn CHAR(10),
dno INTEGER,
PRIMARY KEY (dno),
FOREIGN KEY (ssn)
REFERENCES Employees,
FOREIGN KEY (dno)
REFERENCES Departments)
Exercise 3.14
Solution
• Why did we make dno the primary key for
Manages?
• Since each department can have at most one
manager, each dno can appear at most once in
the Manages table, making it a key for
Manages.
• Note that if we had made (ssn, dno) the key
for Manages, a department could have more
than one Manager.
Exercise 3.14
Solution
• Finally, we translate the weak entity “Child”
and its corresponding relationship
“Dependent”
Exercise 3.14
Solution
CREATE TABLE Dependents(
ssn CHAR(10),
name CHAR(10),
age INTEGER,
PRIMARY KEY (ssn, name),
FOREIGN KEY (ssn)
REFERENCES Employees,
ON DELETE CASCADE )
Exercise 3.18
Problem
• Write SQL statements to create the
corresponding relations to the ER diagram you
designed for Exercise 2.8. If your translation
cannot capture any constraints in the ER
diagram, explain why.
Exercise 3.18
ER Diagram from Exercise 2.8
Exercise 3.18
Solution
• The entities are translated similarly to Exercise
3.4. Since these are fairly simple, we shall skip
them.
• Now, we shall translate the relationships.
Exercise 3.18
Solution
CREATE TABLE Like Group (
name CHAR(20),
cust name CHAR(20),
PRIMARY KEY (name, cust_name),
FOREIGN KEY (name)
REFERENCES Group,
FOREIGN KEY (cust name)
REFERENCES Customer)
Exercise 3.18
Solution
CREATE TABLE Like Artist (
name CHAR(20),
cust name CHAR(20),
PRIMARY KEY (name, cust name),
FOREIGN KEY (name) REFERENCES Artist,
FOREIGN KEY (cust name) REFERENCES Customer)
Exercise 3.18
Solution
CREATE TABLE Artwork Paints(
title CHAR(20),
artist name CHAR(20),
type CHAR(20),
price INTEGER,
year INTEGER,
PRIMARY KEY (title),
FOREIGN KEY (artist name)
REFERENCES Artist)
Exercise 3.18
Solution
CREATE TABLE Classify (
title CHAR(20),
name CHAR(20),
PRIMARY KEY (title, name),
FOREIGN KEY (title) REFERENCES Artwork_Paints,
FOREIGN KEY (name) REFERENCES Group )
Exercise 3.8
Problem
• Answer each of the following questions
briefly. The questions are based on the
following relational schema:
– Emp(eid: integer, ename: string, age: integer,
salary: real)
– Works(eid: integer, did: integer, pcttime: integer)
– Dept(did: integer, dname: string, budget: real,
managerid: integer)
Exercise 3.8
Problem
Emp(eid: integer, ename: string, age: integer, salary: real)
Works(eid: integer, did: integer, pcttime: integer)
Dept(did: integer, dname: string, budget: real, managerid: integer
1. Give an example of a foreign key constraint
that involves the Dept relation. What are the
options for enforcing this constraint when a
user attempts to delete a Dept tuple?
Exercise 3.8
Solution for (1)
An example of a foreign constraint that
involves Dept is:
CREATE TABLE Works (
eid INTEGER NOT NULL ,
did INTEGER NOT NULL ,
pcttime INTEGER,
PRIMARY KEY (eid, did),
UNIQUE (eid),
FOREIGN KEY (did) REFERENCES Dept )
Exercise 3.8
Solution for (1)
Furthermore, when a user attempts to delete
a tuple from Dept, we can
– also delete all Works tuples that refer to it.
– disallow the deletion of the Dept tuple if some
Works tuple refers to it.
– for every Works tuple that refers to it, set the did
field to the did of some (existing) ’default’
department.
– for every Works tuple that refers to it, set the did
field to null.
Exercise 3.8
Problem
Emp(eid: integer, ename: string, age: integer, salary: real)
Works(eid: integer, did: integer, pcttime: integer)
Dept(did: integer, dname: string, budget: real, managerid: integer
2. Write the SQL statements required to create
the preceding relations, including
appropriate versions of all primary and
foreign key integrity constraints.
Exercise 3.8
Solution for (2)
Emp(eid: integer, ename: string, age: integer, salary: real)
Works(eid: integer, did: integer, pcttime: integer)
CREATE TABLE Emp (
eid INTEGER,
ename CHAR(10),
age INTEGER,
salary REAL,
PRIMARY KEY (eid) )
CREATE TABLE Works (
eid INTEGER,
did INTEGER,
pcttime INTEGER,
PRIMARY KEY (eid, did),
FOREIGN KEY (did) REFERENCES Dept,
FOREIGN KEY (eid) REFERENCES Emp,
ON DELETE CASCADE)
Exercise 3.8
Solution for (2)
Dept(did: integer, dname: string, budget: real, managerid: integer
CREATE TABLE Dept (
did INTEGER,
budget REAL,
managerid INTEGER ,
PRIMARY KEY (did),
FOREIGN KEY (managerid) REFERENCES Emp,
ON DELETE SET NULL)
Exercise 3.8
Problem
Emp(eid: integer, ename: string, age: integer, salary: real)
Works(eid: integer, did: integer, pcttime: integer)
Dept(did: integer, dname: string, budget: real, managerid: integer
3. Define the Dept relation in SQL so that every
department is guaranteed to have a manager.
CREATE TABLE Dept (
did INTEGER,
budget REAL,
managerid INTEGER NOT NULL ,
PRIMARY KEY (did),
FOREIGN KEY (managerid) REFERENCES Emp)
Example of a Solution for (3)
Exercise 3.8
Problem
Emp(eid: integer, ename: string, age: integer, salary: real)
Works(eid: integer, did: integer, pcttime: integer)
Dept(did: integer, dname: string, budget: real, managerid: integer
4. Write an SQL statement to add John Doe as
an employee with eid = 101, age = 32 and
salary = 15, 000.
INSERT
INTO Emp (eid, ename, age, salary)
VALUES (101, ’John Doe’, 32, 15000)
Solution for (4)
Exercise 3.8
Problem
Emp(eid: integer, ename: string, age: integer, salary: real)
Works(eid: integer, did: integer, pcttime: integer)
Dept(did: integer, dname: string, budget: real, managerid: integer
5. Write an SQL statement to give every
employee a 10 percent raise.
UPDATE Emp E
SET E.salary = E.salary * 1.10
Solution for (5)
Exercise 3.8
Problem
Emp(eid: integer, ename: string, age: integer, salary: real)
Works(eid: integer, did: integer, pcttime: integer)
Dept(did: integer, dname: string, budget: real, managerid: integer
6. Write an Write an SQL statement to delete
the Toy department. Given the referential
integrity constraints you chose for this
schema, explain what happens when this
statement is executed.
Exercise 3.8
Solution for (6)
DELETE
FROM Dept D
WHERE D.dname = ’Toy’
Since the action to take on deletion was not
specified, the database takes no action by default
That is, it rejects the deletion.
CREATE TABLE Works (
…
FOREIGN KEY (did) REFERENCES Dept,
…)
These are the example integrity constraints that
affect Dept.
Exercise 3.8
Solution for (6)
• What other actions can the system take on
deleting a Dept tuple? What are the pros and
cons of each action?
– On delete set null
– On delete set default
– On delete cascade
This is the end of the lecture!
I hope you enjoyed it.

More Related Content

What's hot

Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Normalization in DBMS
Hitesh Mohapatra
 
Relational model
Relational modelRelational model
Relational model
Dabbal Singh Mahara
 
EER modeling
EER modelingEER modeling
EER modeling
Dabbal Singh Mahara
 
Database Normalization
Database NormalizationDatabase Normalization
Database Normalization
Arun Sharma
 
Dbms 10: Conversion of ER model to Relational Model
Dbms 10: Conversion of ER model to Relational ModelDbms 10: Conversion of ER model to Relational Model
Dbms 10: Conversion of ER model to Relational Model
Amiya9439793168
 
Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Normalization in DBMS
Prateek Parimal
 
Normalization in a Database
Normalization in a DatabaseNormalization in a Database
Normalization in a Database
Bishrul Haq
 
2 database system concepts and architecture
2 database system concepts and architecture2 database system concepts and architecture
2 database system concepts and architectureKumar
 
Entity Relationship Model
Entity Relationship ModelEntity Relationship Model
Entity Relationship ModelSlideshare
 
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NFDatabase Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Oum Saokosal
 
Relational Algebra & Calculus
Relational Algebra & CalculusRelational Algebra & Calculus
Relational Algebra & Calculus
Abdullah Khosa
 
Data models
Data modelsData models
Data models
Usman Tariq
 
Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)
Oum Saokosal
 
ER model to Relational model mapping
ER model to Relational model mappingER model to Relational model mapping
ER model to Relational model mappingShubham Saini
 
Er & eer to relational mapping
Er & eer to relational mappingEr & eer to relational mapping
Er & eer to relational mappingsaurabhshertukde
 
Normalization
NormalizationNormalization
Normalization
meet darji
 
Data modeling using the entity relationship model
Data modeling using the entity relationship modelData modeling using the entity relationship model
Data modeling using the entity relationship modelJafar Nesargi
 
SQL DDL
SQL DDLSQL DDL
SQL DDL
Vikas Gupta
 

What's hot (20)

Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Normalization in DBMS
 
Relational model
Relational modelRelational model
Relational model
 
EER modeling
EER modelingEER modeling
EER modeling
 
Database Normalization
Database NormalizationDatabase Normalization
Database Normalization
 
Entity relationship modelling
Entity relationship modellingEntity relationship modelling
Entity relationship modelling
 
Dbms 10: Conversion of ER model to Relational Model
Dbms 10: Conversion of ER model to Relational ModelDbms 10: Conversion of ER model to Relational Model
Dbms 10: Conversion of ER model to Relational Model
 
Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Normalization in DBMS
 
Normalization in a Database
Normalization in a DatabaseNormalization in a Database
Normalization in a Database
 
2 database system concepts and architecture
2 database system concepts and architecture2 database system concepts and architecture
2 database system concepts and architecture
 
Entity Relationship Model
Entity Relationship ModelEntity Relationship Model
Entity Relationship Model
 
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NFDatabase Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
 
Relational Algebra & Calculus
Relational Algebra & CalculusRelational Algebra & Calculus
Relational Algebra & Calculus
 
Data models
Data modelsData models
Data models
 
Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)
 
ER model to Relational model mapping
ER model to Relational model mappingER model to Relational model mapping
ER model to Relational model mapping
 
Er & eer to relational mapping
Er & eer to relational mappingEr & eer to relational mapping
Er & eer to relational mapping
 
Databases: Normalisation
Databases: NormalisationDatabases: Normalisation
Databases: Normalisation
 
Normalization
NormalizationNormalization
Normalization
 
Data modeling using the entity relationship model
Data modeling using the entity relationship modelData modeling using the entity relationship model
Data modeling using the entity relationship model
 
SQL DDL
SQL DDLSQL DDL
SQL DDL
 

Viewers also liked

What is software engineering
What is software engineeringWhat is software engineering
What is software engineering
Jennifer Polack
 
Introduction To Software Engineering
Introduction To Software EngineeringIntroduction To Software Engineering
Introduction To Software Engineering
Leyla Bonilla
 
Catalogued and student workers database(use cases diagram)
Catalogued and student workers database(use cases diagram)Catalogued and student workers database(use cases diagram)
Catalogued and student workers database(use cases diagram)
Jennifer Polack
 
Introduction to software engineering
Introduction to software engineeringIntroduction to software engineering
Introduction to software engineering
Shrayas Suryakumar
 
Unit 1 importance ofsoftengg_b.tech iii year
Unit 1  importance ofsoftengg_b.tech iii yearUnit 1  importance ofsoftengg_b.tech iii year
Unit 1 importance ofsoftengg_b.tech iii year
Preeti Mishra
 
Agile software process
Agile software processAgile software process
Agile software process
Jennifer Polack
 
Software process
Software processSoftware process
Software process
Jennifer Polack
 
software engineering
software engineeringsoftware engineering
software engineering
Azad public school
 
Lecture 01 Introduction to Software Engineering
Lecture 01 Introduction to Software EngineeringLecture 01 Introduction to Software Engineering
Lecture 01 Introduction to Software Engineering
Achmad Solichin
 
Database design
Database designDatabase design
Database design
Jennifer Polack
 
Introduction to linux ppt
Introduction to linux pptIntroduction to linux ppt
Introduction to linux ppt
Omi Vichare
 
CSS Grid Layout for Topconf, Linz
CSS Grid Layout for Topconf, LinzCSS Grid Layout for Topconf, Linz
CSS Grid Layout for Topconf, Linz
Rachel Andrew
 
Linux.ppt
Linux.ppt Linux.ppt
Linux.ppt
onu9
 
Sass Code Reviews - How one code review changed my life #SassConf2015
Sass Code Reviews - How one code review changed my life #SassConf2015Sass Code Reviews - How one code review changed my life #SassConf2015
Sass Code Reviews - How one code review changed my life #SassConf2015
Stacy Kvernmo
 

Viewers also liked (15)

What is software engineering
What is software engineeringWhat is software engineering
What is software engineering
 
Introduction To Software Engineering
Introduction To Software EngineeringIntroduction To Software Engineering
Introduction To Software Engineering
 
Catalogued and student workers database(use cases diagram)
Catalogued and student workers database(use cases diagram)Catalogued and student workers database(use cases diagram)
Catalogued and student workers database(use cases diagram)
 
Introduction to software engineering
Introduction to software engineeringIntroduction to software engineering
Introduction to software engineering
 
Chapter 01
Chapter 01Chapter 01
Chapter 01
 
Unit 1 importance ofsoftengg_b.tech iii year
Unit 1  importance ofsoftengg_b.tech iii yearUnit 1  importance ofsoftengg_b.tech iii year
Unit 1 importance ofsoftengg_b.tech iii year
 
Agile software process
Agile software processAgile software process
Agile software process
 
Software process
Software processSoftware process
Software process
 
software engineering
software engineeringsoftware engineering
software engineering
 
Lecture 01 Introduction to Software Engineering
Lecture 01 Introduction to Software EngineeringLecture 01 Introduction to Software Engineering
Lecture 01 Introduction to Software Engineering
 
Database design
Database designDatabase design
Database design
 
Introduction to linux ppt
Introduction to linux pptIntroduction to linux ppt
Introduction to linux ppt
 
CSS Grid Layout for Topconf, Linz
CSS Grid Layout for Topconf, LinzCSS Grid Layout for Topconf, Linz
CSS Grid Layout for Topconf, Linz
 
Linux.ppt
Linux.ppt Linux.ppt
Linux.ppt
 
Sass Code Reviews - How one code review changed my life #SassConf2015
Sass Code Reviews - How one code review changed my life #SassConf2015Sass Code Reviews - How one code review changed my life #SassConf2015
Sass Code Reviews - How one code review changed my life #SassConf2015
 

Similar to Erd examples

Database Assignment
Database AssignmentDatabase Assignment
Database Assignment
Jayed Imran
 
Cis336 i lab 1 of 7
Cis336 i lab 1 of 7Cis336 i lab 1 of 7
Cis336 i lab 1 of 7helpido9
 
LEARNING PLAN IN MATH 9 Q1W1
LEARNING PLAN IN MATH 9 Q1W1LEARNING PLAN IN MATH 9 Q1W1
LEARNING PLAN IN MATH 9 Q1W1
Erwin Hilario
 
Division algorithms (2)
Division algorithms (2)Division algorithms (2)
Division algorithms (2)
Deepa Vanu
 
For this Applied Knowledge Assessment, you will use the concepts.docx
For this Applied Knowledge Assessment, you will use the concepts.docxFor this Applied Knowledge Assessment, you will use the concepts.docx
For this Applied Knowledge Assessment, you will use the concepts.docx
AKHIL969626
 
33.value10.00 pointsGeppetto and Lewis decide that they.docx
33.value10.00 pointsGeppetto and Lewis decide that they.docx33.value10.00 pointsGeppetto and Lewis decide that they.docx
33.value10.00 pointsGeppetto and Lewis decide that they.docx
tamicawaysmith
 
Uses & Abuses of Mocks & Stubs
Uses & Abuses of Mocks & StubsUses & Abuses of Mocks & Stubs
Uses & Abuses of Mocks & StubsPatchSpace Ltd
 
Midterm
MidtermMidterm
Conquering the TEAS Part 3: Math
Conquering the TEAS Part 3: MathConquering the TEAS Part 3: Math
Conquering the TEAS Part 3: Math
Lynn Bahena
 
DataWeave 2.0 - MuleSoft CONNECT 2019
DataWeave 2.0 - MuleSoft CONNECT 2019DataWeave 2.0 - MuleSoft CONNECT 2019
DataWeave 2.0 - MuleSoft CONNECT 2019
Sabrina Marechal
 
Data structures & problem solving unit 1 ppt
Data structures & problem solving unit 1 pptData structures & problem solving unit 1 ppt
Data structures & problem solving unit 1 ppt
aviban
 
DIRECTIONS READ THE FOLLOWING STUDENT POST AND RESPOND EVALUATE I.docx
DIRECTIONS READ THE FOLLOWING STUDENT POST AND RESPOND EVALUATE I.docxDIRECTIONS READ THE FOLLOWING STUDENT POST AND RESPOND EVALUATE I.docx
DIRECTIONS READ THE FOLLOWING STUDENT POST AND RESPOND EVALUATE I.docx
lynettearnold46882
 
03 laboratory exercise 1 - WORKING WITH CTE
03 laboratory exercise 1 - WORKING WITH CTE03 laboratory exercise 1 - WORKING WITH CTE
03 laboratory exercise 1 - WORKING WITH CTE
Anne Lee
 
03 laboratory exercise 1
03 laboratory exercise 103 laboratory exercise 1
03 laboratory exercise 1
Anne Lee
 
Solving dynamics problems with matlab
Solving dynamics problems with matlabSolving dynamics problems with matlab
Solving dynamics problems with matlab
Sérgio Castilho
 
Bba 3274 qm week 8 linear programming
Bba 3274 qm week 8 linear programmingBba 3274 qm week 8 linear programming
Bba 3274 qm week 8 linear programming
Stephen Ong
 
lec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.pptlec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.ppt
Mard Geer
 
lec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.pptlec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.ppt
SourabhPal46
 
1 Excel Basics & Diff Error Prop
1 Excel Basics & Diff Error Prop1 Excel Basics & Diff Error Prop
1 Excel Basics & Diff Error PropBrucePhebus
 

Similar to Erd examples (20)

Database Assignment
Database AssignmentDatabase Assignment
Database Assignment
 
Cis336 i lab 1 of 7
Cis336 i lab 1 of 7Cis336 i lab 1 of 7
Cis336 i lab 1 of 7
 
LEARNING PLAN IN MATH 9 Q1W1
LEARNING PLAN IN MATH 9 Q1W1LEARNING PLAN IN MATH 9 Q1W1
LEARNING PLAN IN MATH 9 Q1W1
 
Division algorithms (2)
Division algorithms (2)Division algorithms (2)
Division algorithms (2)
 
For this Applied Knowledge Assessment, you will use the concepts.docx
For this Applied Knowledge Assessment, you will use the concepts.docxFor this Applied Knowledge Assessment, you will use the concepts.docx
For this Applied Knowledge Assessment, you will use the concepts.docx
 
33.value10.00 pointsGeppetto and Lewis decide that they.docx
33.value10.00 pointsGeppetto and Lewis decide that they.docx33.value10.00 pointsGeppetto and Lewis decide that they.docx
33.value10.00 pointsGeppetto and Lewis decide that they.docx
 
Uses & Abuses of Mocks & Stubs
Uses & Abuses of Mocks & StubsUses & Abuses of Mocks & Stubs
Uses & Abuses of Mocks & Stubs
 
Midterm
MidtermMidterm
Midterm
 
Conquering the TEAS Part 3: Math
Conquering the TEAS Part 3: MathConquering the TEAS Part 3: Math
Conquering the TEAS Part 3: Math
 
DataWeave 2.0 - MuleSoft CONNECT 2019
DataWeave 2.0 - MuleSoft CONNECT 2019DataWeave 2.0 - MuleSoft CONNECT 2019
DataWeave 2.0 - MuleSoft CONNECT 2019
 
Module 2 topic 1 notes
Module 2 topic 1 notesModule 2 topic 1 notes
Module 2 topic 1 notes
 
Data structures & problem solving unit 1 ppt
Data structures & problem solving unit 1 pptData structures & problem solving unit 1 ppt
Data structures & problem solving unit 1 ppt
 
DIRECTIONS READ THE FOLLOWING STUDENT POST AND RESPOND EVALUATE I.docx
DIRECTIONS READ THE FOLLOWING STUDENT POST AND RESPOND EVALUATE I.docxDIRECTIONS READ THE FOLLOWING STUDENT POST AND RESPOND EVALUATE I.docx
DIRECTIONS READ THE FOLLOWING STUDENT POST AND RESPOND EVALUATE I.docx
 
03 laboratory exercise 1 - WORKING WITH CTE
03 laboratory exercise 1 - WORKING WITH CTE03 laboratory exercise 1 - WORKING WITH CTE
03 laboratory exercise 1 - WORKING WITH CTE
 
03 laboratory exercise 1
03 laboratory exercise 103 laboratory exercise 1
03 laboratory exercise 1
 
Solving dynamics problems with matlab
Solving dynamics problems with matlabSolving dynamics problems with matlab
Solving dynamics problems with matlab
 
Bba 3274 qm week 8 linear programming
Bba 3274 qm week 8 linear programmingBba 3274 qm week 8 linear programming
Bba 3274 qm week 8 linear programming
 
lec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.pptlec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.ppt
 
lec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.pptlec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.ppt
 
1 Excel Basics & Diff Error Prop
1 Excel Basics & Diff Error Prop1 Excel Basics & Diff Error Prop
1 Excel Basics & Diff Error Prop
 

More from Jennifer Polack

Trainer use cases
Trainer use casesTrainer use cases
Trainer use cases
Jennifer Polack
 
Umw training program
Umw training programUmw training program
Umw training program
Jennifer Polack
 
Classroom scheduler update
Classroom scheduler updateClassroom scheduler update
Classroom scheduler update
Jennifer Polack
 
Temperature data analyzer requirements
Temperature data analyzer requirementsTemperature data analyzer requirements
Temperature data analyzer requirements
Jennifer Polack
 
Training Programming Description- Morning Section
Training Programming Description- Morning SectionTraining Programming Description- Morning Section
Training Programming Description- Morning Section
Jennifer Polack
 
Training Programming Description- Afternoon Section
Training Programming Description- Afternoon SectionTraining Programming Description- Afternoon Section
Training Programming Description- Afternoon Section
Jennifer Polack
 
Cataloged and student workers database
Cataloged and student workers databaseCataloged and student workers database
Cataloged and student workers database
Jennifer Polack
 
Temperature Analyzer Project
Temperature Analyzer ProjectTemperature Analyzer Project
Temperature Analyzer Project
Jennifer Polack
 
System Modelling
System ModellingSystem Modelling
System Modelling
Jennifer Polack
 
Requirements engineering
Requirements engineeringRequirements engineering
Requirements engineering
Jennifer Polack
 
Chapter 11
Chapter 11Chapter 11
Chapter 11
Jennifer Polack
 
Chapter 10
Chapter 10Chapter 10
Chapter 10
Jennifer Polack
 
Chapter 9
Chapter 9Chapter 9
Chapter 9
Jennifer Polack
 
Ccsc 2015 panel
Ccsc 2015 panelCcsc 2015 panel
Ccsc 2015 panel
Jennifer Polack
 
Chapter 8
Chapter 8Chapter 8
Chapter 8
Jennifer Polack
 
Chapter 6
Chapter 6Chapter 6
Chapter 6
Jennifer Polack
 
Ch04
Ch04Ch04
Chapter 2 group quiz
Chapter 2 group quizChapter 2 group quiz
Chapter 2 group quiz
Jennifer Polack
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
Jennifer Polack
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
Jennifer Polack
 

More from Jennifer Polack (20)

Trainer use cases
Trainer use casesTrainer use cases
Trainer use cases
 
Umw training program
Umw training programUmw training program
Umw training program
 
Classroom scheduler update
Classroom scheduler updateClassroom scheduler update
Classroom scheduler update
 
Temperature data analyzer requirements
Temperature data analyzer requirementsTemperature data analyzer requirements
Temperature data analyzer requirements
 
Training Programming Description- Morning Section
Training Programming Description- Morning SectionTraining Programming Description- Morning Section
Training Programming Description- Morning Section
 
Training Programming Description- Afternoon Section
Training Programming Description- Afternoon SectionTraining Programming Description- Afternoon Section
Training Programming Description- Afternoon Section
 
Cataloged and student workers database
Cataloged and student workers databaseCataloged and student workers database
Cataloged and student workers database
 
Temperature Analyzer Project
Temperature Analyzer ProjectTemperature Analyzer Project
Temperature Analyzer Project
 
System Modelling
System ModellingSystem Modelling
System Modelling
 
Requirements engineering
Requirements engineeringRequirements engineering
Requirements engineering
 
Chapter 11
Chapter 11Chapter 11
Chapter 11
 
Chapter 10
Chapter 10Chapter 10
Chapter 10
 
Chapter 9
Chapter 9Chapter 9
Chapter 9
 
Ccsc 2015 panel
Ccsc 2015 panelCcsc 2015 panel
Ccsc 2015 panel
 
Chapter 8
Chapter 8Chapter 8
Chapter 8
 
Chapter 6
Chapter 6Chapter 6
Chapter 6
 
Ch04
Ch04Ch04
Ch04
 
Chapter 2 group quiz
Chapter 2 group quizChapter 2 group quiz
Chapter 2 group quiz
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 

Recently uploaded

BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 

Recently uploaded (20)

BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 

Erd examples

  • 2. Exercise 2.4 Problem • A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments (identified by dno, with dname and budget as attributes), and children of employees (with name and age as attributes).
  • 3. Exercise 2.4 Problem • Employees work in departments; each department is managed by an employee; a child must be identified uniquely by name when the parent (who is an employee; assume that only one parent works for the company) is known. We are not interested in information about a child once the parent leaves the company. • Draw an ER diagram that captures this information.
  • 4. Exercise 2.4 Solution • First, we shall design the entities and relationships. – “Employees work in departments…” – “…each department is managed by an employee…” – “…a child must be identified uniquely by name when the parent (who is an employee; assume that only one parent works for the company) is known.”
  • 6. Exercise 2.4 Solution • Now, we will design the constraints. – “…each department is managed by an employee…” – “…a child must be identified uniquely by name when the parent (who is an employee; assume that only one parent works for the company) is known. “ – “We are not interested in information about a child once the parent leaves the company.”
  • 8. Exercise 2.8 Problem • Although you always wanted to be an artist, you ended up being an expert on databases because you love to cook data and you somehow confused database with data baste. Your old love is still there, however, so you set up a database company, ArtBase, that builds a product for art galleries. The core of this product is a database with a schema that captures all the information that galleries need to maintain.
  • 9. Exercise 2.8 Problem • Galleries keep information about artists, their names (which are unique), birthplaces, age,and style of art. For each piece of artwork, the artist, the year it was made, its unique title, its type of art (e.g., painting, lithograph, sculpture, photograph), and its price must be stored. Pieces of artwork are also classified into groups of various kinds, for example, portraits, still lifes, works by Picasso, or works of the 19th century; a given piece may belong to more than one group.
  • 10. Exercise 2.8 Problem • Each group is identified by a name (like those just given) that describes the group. Finally, galleries keep information about customers. For each customer, galleries keep that person’s unique name, address, total amount of dollars spent in the gallery (very important!), and the artists and groups of art that the customer tends to like. • Draw the ER diagram for the database.
  • 11. Exercise 2.8 Solution • Like before, we begin with the entities and relationships. • “…artists, their names (which are unique), birthplaces, age, and style of art.” • “For each piece of artwork, the artist, the year it was made, its unique title, its type of art … and its price must be stored.”
  • 12. Exercise 2.8 Solution • “Pieces of artwork are also classified into groups of various kinds, … Each group is identified by a name (like those just given) that describes the group. “ • For each customer, galleries keep that person’s unique name, address, total amount of dollars spent in the gallery (very important!), and the artists and groups of art that the customer tends to like.
  • 15. Exercise 2.8 Solution • Now we look at constraints. – Although not explicitly mentioned in the problem, we assume that each piece of artwork had to be painted by an artist. – We also assume that each piece of artwork was created by exactly one artist.
  • 17. Exercise 2.8 Solution • Suppose we had several piece of artwork with the same title, and we told them apart by artist? • Example: “What is Love?” by Cheryl D, “What is Love?” by Joe Brown, etc.
  • 19. Exercise 3.14 Problem • Consider the scenario from Exercise 2.4, where you designed an ER diagram for a company database. Write SQL statements to create the corresponding relations and capture as many of the constraints as possible. If you cannot capture some constraints, explain why.
  • 20. Exercise 3.14 ER Diagram from Exercise 2.4
  • 21. Exercise 3.14 Solution • First we begin with the entities “Employees” and “Departments. • Translating these to SQL is straightforward.
  • 22. Exercise 3.14 Solution CREATE TABLE Employees( ssn CHAR(10), sal INTEGER, phone CHAR(13), PRIMARY KEY (ssn) ) CREATE TABLE Departments ( dno INTEGER, budget INTEGER, dname CHAR(20), PRIMARY KEY (dno) )
  • 23. Exercise 3.14 Solution • Next, we translate the relationships, Manages and Dependents. • We translate each these to a table mapping one entity to another. • We also use foreign constraints to make sure every row in the relationship tables refers only to rows that exist in the entity tables.
  • 24. Exercise 3.14 Solution CREATE TABLE Works_in( ssn CHAR(10), dno INTEGER, PRIMARY KEY (ssn, dno), FOREIGN KEY (ssn) REFERENCES Employees, FOREIGN KEY (dno) REFERENCES Departments) CREATE TABLE Manages ( ssn CHAR(10), dno INTEGER, PRIMARY KEY (dno), FOREIGN KEY (ssn) REFERENCES Employees, FOREIGN KEY (dno) REFERENCES Departments)
  • 25. Exercise 3.14 Solution • Why did we make dno the primary key for Manages? • Since each department can have at most one manager, each dno can appear at most once in the Manages table, making it a key for Manages. • Note that if we had made (ssn, dno) the key for Manages, a department could have more than one Manager.
  • 26. Exercise 3.14 Solution • Finally, we translate the weak entity “Child” and its corresponding relationship “Dependent”
  • 27. Exercise 3.14 Solution CREATE TABLE Dependents( ssn CHAR(10), name CHAR(10), age INTEGER, PRIMARY KEY (ssn, name), FOREIGN KEY (ssn) REFERENCES Employees, ON DELETE CASCADE )
  • 28. Exercise 3.18 Problem • Write SQL statements to create the corresponding relations to the ER diagram you designed for Exercise 2.8. If your translation cannot capture any constraints in the ER diagram, explain why.
  • 29. Exercise 3.18 ER Diagram from Exercise 2.8
  • 30. Exercise 3.18 Solution • The entities are translated similarly to Exercise 3.4. Since these are fairly simple, we shall skip them. • Now, we shall translate the relationships.
  • 31. Exercise 3.18 Solution CREATE TABLE Like Group ( name CHAR(20), cust name CHAR(20), PRIMARY KEY (name, cust_name), FOREIGN KEY (name) REFERENCES Group, FOREIGN KEY (cust name) REFERENCES Customer)
  • 32. Exercise 3.18 Solution CREATE TABLE Like Artist ( name CHAR(20), cust name CHAR(20), PRIMARY KEY (name, cust name), FOREIGN KEY (name) REFERENCES Artist, FOREIGN KEY (cust name) REFERENCES Customer)
  • 33. Exercise 3.18 Solution CREATE TABLE Artwork Paints( title CHAR(20), artist name CHAR(20), type CHAR(20), price INTEGER, year INTEGER, PRIMARY KEY (title), FOREIGN KEY (artist name) REFERENCES Artist)
  • 34. Exercise 3.18 Solution CREATE TABLE Classify ( title CHAR(20), name CHAR(20), PRIMARY KEY (title, name), FOREIGN KEY (title) REFERENCES Artwork_Paints, FOREIGN KEY (name) REFERENCES Group )
  • 35. Exercise 3.8 Problem • Answer each of the following questions briefly. The questions are based on the following relational schema: – Emp(eid: integer, ename: string, age: integer, salary: real) – Works(eid: integer, did: integer, pcttime: integer) – Dept(did: integer, dname: string, budget: real, managerid: integer)
  • 36. Exercise 3.8 Problem Emp(eid: integer, ename: string, age: integer, salary: real) Works(eid: integer, did: integer, pcttime: integer) Dept(did: integer, dname: string, budget: real, managerid: integer 1. Give an example of a foreign key constraint that involves the Dept relation. What are the options for enforcing this constraint when a user attempts to delete a Dept tuple?
  • 37. Exercise 3.8 Solution for (1) An example of a foreign constraint that involves Dept is: CREATE TABLE Works ( eid INTEGER NOT NULL , did INTEGER NOT NULL , pcttime INTEGER, PRIMARY KEY (eid, did), UNIQUE (eid), FOREIGN KEY (did) REFERENCES Dept )
  • 38. Exercise 3.8 Solution for (1) Furthermore, when a user attempts to delete a tuple from Dept, we can – also delete all Works tuples that refer to it. – disallow the deletion of the Dept tuple if some Works tuple refers to it. – for every Works tuple that refers to it, set the did field to the did of some (existing) ’default’ department. – for every Works tuple that refers to it, set the did field to null.
  • 39. Exercise 3.8 Problem Emp(eid: integer, ename: string, age: integer, salary: real) Works(eid: integer, did: integer, pcttime: integer) Dept(did: integer, dname: string, budget: real, managerid: integer 2. Write the SQL statements required to create the preceding relations, including appropriate versions of all primary and foreign key integrity constraints.
  • 40. Exercise 3.8 Solution for (2) Emp(eid: integer, ename: string, age: integer, salary: real) Works(eid: integer, did: integer, pcttime: integer) CREATE TABLE Emp ( eid INTEGER, ename CHAR(10), age INTEGER, salary REAL, PRIMARY KEY (eid) ) CREATE TABLE Works ( eid INTEGER, did INTEGER, pcttime INTEGER, PRIMARY KEY (eid, did), FOREIGN KEY (did) REFERENCES Dept, FOREIGN KEY (eid) REFERENCES Emp, ON DELETE CASCADE)
  • 41. Exercise 3.8 Solution for (2) Dept(did: integer, dname: string, budget: real, managerid: integer CREATE TABLE Dept ( did INTEGER, budget REAL, managerid INTEGER , PRIMARY KEY (did), FOREIGN KEY (managerid) REFERENCES Emp, ON DELETE SET NULL)
  • 42. Exercise 3.8 Problem Emp(eid: integer, ename: string, age: integer, salary: real) Works(eid: integer, did: integer, pcttime: integer) Dept(did: integer, dname: string, budget: real, managerid: integer 3. Define the Dept relation in SQL so that every department is guaranteed to have a manager. CREATE TABLE Dept ( did INTEGER, budget REAL, managerid INTEGER NOT NULL , PRIMARY KEY (did), FOREIGN KEY (managerid) REFERENCES Emp) Example of a Solution for (3)
  • 43. Exercise 3.8 Problem Emp(eid: integer, ename: string, age: integer, salary: real) Works(eid: integer, did: integer, pcttime: integer) Dept(did: integer, dname: string, budget: real, managerid: integer 4. Write an SQL statement to add John Doe as an employee with eid = 101, age = 32 and salary = 15, 000. INSERT INTO Emp (eid, ename, age, salary) VALUES (101, ’John Doe’, 32, 15000) Solution for (4)
  • 44. Exercise 3.8 Problem Emp(eid: integer, ename: string, age: integer, salary: real) Works(eid: integer, did: integer, pcttime: integer) Dept(did: integer, dname: string, budget: real, managerid: integer 5. Write an SQL statement to give every employee a 10 percent raise. UPDATE Emp E SET E.salary = E.salary * 1.10 Solution for (5)
  • 45. Exercise 3.8 Problem Emp(eid: integer, ename: string, age: integer, salary: real) Works(eid: integer, did: integer, pcttime: integer) Dept(did: integer, dname: string, budget: real, managerid: integer 6. Write an Write an SQL statement to delete the Toy department. Given the referential integrity constraints you chose for this schema, explain what happens when this statement is executed.
  • 46. Exercise 3.8 Solution for (6) DELETE FROM Dept D WHERE D.dname = ’Toy’ Since the action to take on deletion was not specified, the database takes no action by default That is, it rejects the deletion. CREATE TABLE Works ( … FOREIGN KEY (did) REFERENCES Dept, …) These are the example integrity constraints that affect Dept.
  • 47. Exercise 3.8 Solution for (6) • What other actions can the system take on deleting a Dept tuple? What are the pros and cons of each action? – On delete set null – On delete set default – On delete cascade
  • 48. This is the end of the lecture! I hope you enjoyed it.