Week 10

You might also like

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

DSME2051.

BUSINESS INFORMATION SYSTEMS

WEEK 10:
DATABASE AND ENTITY-
RELATIONSHIP DIAGRAM (CONT.)
Qianran (Jenny) Jin
CUHK Business School

1
Assignment 2

Deadline: March 31, 2022, 11:59PM


– Late submission is not allowed
100 points in total, accounts for 7.5% of the final grade
(individual assignment)
Email TA if you have any questions. Please indicate your
section number in the email subject
– mickey@baf.cuhk.edu.hk

2
Outline

Entity-Relationship Diagram (cont.)


LibreOffice Base

3
Recap: Data Hierarchy

A field is typically a name, number, or combination of


characters that describes an aspect of a business object or
activity.
A collection of related data fields is a record.
A table is a collection of related records.
Database is a collection of related data files or table
containing data

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

Identify and diagram all entities


Add primary key attributes
Add all other attributes
Identify and diagram all relationships
Include all cardinalities

7
ERD Modeling Example

A professor may or may not teach in the current semester


When the professor teaches, he/she may teach more than one
course
Co-teaching (a course taught by more than one professor) is
not allowed

8
ERD Modeling Example

A professor may or may not teach in the current semester


– We know each professor’s staff ID, name and the department

When the professor teaches, he/she may teach more than one
course
– For each course, we know the course ID, course name, time, location

Co-teaching (a course taught by more than one professor) is


not allowed

9
ERD Modeling Example

A professor may or may not teach in the current semester


When the professor teaches, he/she may teach more than one
course
Co-teaching (a course taught by more than one professor) is
not allowed

10
ERD Modeling Example

A professor may or may not teach in the current semester


When the professor teaches, he/she may teach more than one
course
Co-teaching (a course taught by more than one professor) is
not allowed

11
Exercise #1

Professor can apply for a parking permit on campus.


– We know each professor’s staff ID, name and the department
Only one permit is allowed for each professor.
– For each permit, we know the permit #, its location

12
Exercise #2

Professor can apply for a parking permit on campus.


Professor can apply for as many permits as they want.

13
ERD Modeling: Many-to-many Relationships

Professor can apply for a parking permit on campus.


Professor can apply for as many permits as they want.
Each permit can be shared by multiple professors.

14
ERD Modeling: Many-to-many Relationships

Relational database does not support many-to-many!


We have to use junction/bridge tables, so that we have two
one-to-many relationships.

15
ERD Modeling: Many-to-many Relationships

16
ERD and Database Design

Once we have ER diagram, we know how records/data will be


stored in database.

Staff ID Name Department


1111 Jenny Jin DSME
2222 Lin Zhou DSME
3332 Andy Wong Marketing

17
ERD and Database Design

Once we have ER diagram, we know how records/data will be


stored in database.

Course ID Course Name Course Time Course Place Staff ID


DSME2051A Business Thu 9:30am Online 1111
Information
Systems
DSME2051C Business Wed 2:30pm Online 1111
Information
Systems
DSME2051D Business Tue 2:30pm Online 1111
Information
Systems
18
ERD and Database Design

Staff ID Name Department


1111 Jenny Jin DSME
2222 Lin Zhou DSME
3332 Andy Wong Marketing

Course ID Course Name Course Time Course Place Staff ID


DSME2051A Business Information Systems Thu 9:30am Online 1111
DSME2051C Business Information Systems Wed 2:30pm Online 1111
DSME2051D Business Information Systems Tue 2:30pm Online 1111
19
Exercise #3

We would like to manage the data about students and the


professors of an academic program offered by a university. Each
student is identified by a unique identifier, a first name, last name
and age.
Each student is enrolled in a program. Each program has a
unique identifier, name and a duration (number of years) and is
handled by one professor. One professor handles more than one
program. Each professor is identified by an ID, first name, last
name and the subject he/she teaches.

Draw an Entity-Relationship Diagram


20
Exercise #4

A company has a number of employees. The attributes of


EMPLOYEE include “Employee ID”, “Name”, “Address”, and
“Birthdate”. The company also has several projects. Attributes of
PROJECT include “Project ID”, “Project Name”, and “Start Date”.
Each employee may be assigned to any number of projects,
including to none. A project must have at least one employee
assigned, and may have any number of employees assigned.

Draw an Entity-Relationship Diagram

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

Entity-Relationship Diagram (cont.)


LibreOffice Base

23
LibreOffice Base

LibreOffice Base is a database management systems with a


graphical user interface, similar to Microsoft Access
Advantage
– Due to graphical interface, easy for beginners
– Appropriate to understand the basic concepts of database
– Cross-platform (available on Windows, Mac, Linux)
– Free and open source (MS Access is costly if you don’t have
subscription)

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)

PK should be a unique field (or a combination of fields) that


distinguishes each record from others
– PK prevents duplicate records
– Every table should have PK
ID field is usually used as PK
A set of fields can be used together as PK
– E.g. Name and Age together can be used as PK
– How-to
• Select multiple fields (by pressing “Ctrl” and clicking “left mouse
button together)
• Right-click on it and choose [Primary Key]
29
Field Properties

Set properties of each field appropriately

Field Type Role Example Field


Number Numeric values Size, quantity, ID
Double Number containing decimals Satisfaction Rate
Text 0~255 characters Name, Address
Date/Time Dates and times Order Date
Yes/No “Yes” or “No” Student

30
Field Properties

You can set some field to show predefined format


– Dollar sign $, percentage sign %
How-to
– Click on […] next to [Format example]
– Choose an appropriate format

31
Save a Table

Save your table by clicking “Save” button on top


You will be able to see your tables listed under [Tables]
– Right-click a table and choose “Edit” to edit field properties
– Double-click a table to add new records

32
Add/View Records in Table

Add/edit/delete records

View records in Table


Select a table and choose “Document” under option

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

– Drag a Foreign Key field to a Primary Key field on another table


(e.g. drag Program ID in Student table to Program ID in Student
table)
– Check whether relationship cardinality (max cardinality) appears
correctly
• “1” for “one”
• “n” for “many”

36
Database Consistency

Restrictions to enforce consistency of database


– On one-side table, if Program ID is linked to many-side table
• Cannot delete a record
• Cannot change Program ID value
• That is, you cannot delete a program if the program has students.
You have to delete all the programs first.
– On many-side table, if Program ID does not exist in one-side
table
• Cannot add a record with non-existing Program ID
• Cannot change Program ID into non-existing Program ID
• That is, you cannot make a student record with a non-existing
Program ID
37
More Reference on LibreOffice Base

https://documentation.libreoffice.org/assets/Uploads/Documen
tation/en/GS5.1/HTML/GS5108-GettingStartedWithBase.html

38

You might also like