Week 10
Week 10
WEEK 10:
DATABASE AND ENTITY-
RELATIONSHIP DIAGRAM (CONT.)
Qianran (Jenny) Jin
CUHK Business School
1
Assignment 2
2
Outline
3
Recap: Data Hierarchy
4
Recap: Database Concepts
Entity
– A generalized class of people, places, or things (objects) for
which data is collected, stored, and maintained.
Attributes (fields)
– A characteristic of an entity.
Keys
– Primary key (PK): a field or set of fields that uniquely identifies
the record. E.g. social security name, HKID number, student ID.
– Foreign key (FK): A field in a table, which is, in turn, a primary
key in another table.
5
Recap: Entity-Relationship Diagram
Entity
Attributes
Relationships
– One-to-one
– One-to-many
– Many-to-many
6
Steps in ERD Modeling
7
ERD Modeling Example
8
ERD Modeling Example
When the professor teaches, he/she may teach more than one
course
– For each course, we know the course ID, course name, time, location
9
ERD Modeling Example
10
ERD Modeling Example
11
Exercise #1
12
Exercise #2
13
ERD Modeling: Many-to-many Relationships
14
ERD Modeling: Many-to-many Relationships
15
ERD Modeling: Many-to-many Relationships
16
ERD and Database Design
17
ERD and Database Design
21
Exercise #5
You are hired by a Hollywood company to create a database
that can store actors/actresses' information and the movies they
have played.
The company wants to keep track of actors information,
which includes their name, age, gender, and actor ID. The
company also wants to store the information of each movie,
which is described as the movie's IMDB number, the year it was
released, director, and the company that produced this movie.
Each actor/actress can play in multiple movies. However, if
they just debuted, they might not have played in any movie yet.
For each movie, it has multiple actors/actresses.
Draw an Entity-Relationship Diagram
22
Outline
23
LibreOffice Base
24
Prepare Database in LibreOffice Base
25
Prepare Database in LibreOffice Base
26
Student Program ERD
27
Make a table
Create a Table
– Click [Tables] under [Database]
– Click [Create Table in Design View]
Add fields in Table
– Fill [Field Name] and select [Field Type] appropriately
– For primary key, right click on field and choose [Primary Key]
– You will see a key icon next to PK
28
Set Primary Key (PK)
30
Field Properties
31
Save a Table
32
Add/View Records in Table
Add/edit/delete records
33
Student Program ERD
Foreign Key field should have the same field type as the
connected Primary Key in the other table
34
Make a Relationship
Create a relationship
– Click [Tools] menu, and then click [Relationships]
– Add all the necessary tables to create relationships
35
Make a Relationship
36
Database Consistency
https://documentation.libreoffice.org/assets/Uploads/Documen
tation/en/GS5.1/HTML/GS5108-GettingStartedWithBase.html
38