data modeling yong choi school of business csub. part # 2 2 database collection of data in...
Post on 21-Dec-2015
218 views
TRANSCRIPT
2
Part # 2
Database
Collection of data in electronic format– A digital library of organization
Managed by one set of software that provides access to all the data No data redundancy, data inconsistency,
poor security, application-data dependency...
3
Part # 2Database Management System (DBMS)
Database software Act as an interface between
application and physical data files Support centralization of data Independent of specific computer
programs small (MS Access), large/popular
(Oracle)
5
Part # 2
Relational Database Model In the relational data model the database
is represented as a group of related tables.
The relational data model was introduced in 1970 by E. F. Codd of IBM published a paper in CACM entitled "A Relational Model of Data for Large Shared Data Banks".
It is currently the most popular model. The mathematical simplicity and ease of visualization of the relational data model have contributed to its success.
6
Part # 2
Relational Database
A schematic diagram of a relational database (a) and a sample part of a relational database showing different tables (b)
7
Part # 2
Relational database and keys A relational database is a collection of
tables that are related to one another based on a common field.
A field, or a collection of fields, is designated as the primary key. The primary key uniquely identifies a record
in the table. When the primary key of one table is
represented in a second table to form a relationship, it is called a foreign key.
8
Part # 2
Primary Key Unique identifier
– Last name vs. SS# Prevent confusion Cost of PK
– SS# vs. finger print– Entity Integrity Rule
Any primary key is allowed to accept null values.
9
Part # 2
Foreign Key
An attribute in one table whose values must either match the primary key in another table or be null.
The database must not contain any unmatched foreign key values.
10
Part # 2Foreign Keys
Student ID
Last Name
First Name
Dorm
2144 Arnold Betty Smith
3122 Taylor John Jones
3843 Simmons Lisa Smith
9844 Macy Bill
2837 Leath Heather Smith
2293 Wrench Tim Jones
Dorm Residence Director
Smith Andrea Fernandez
Jones Daniel Abidjan
Primary Key
Primary Key
Foreign KeyDuplicated from primary key of Major entity(not unique)
12
Part # 2Relating tables using a common field
The primary key in the Employer table (EmployerID) is the common field that relates this table to the Position table.
PositionID is the primary key in the Position table. The EmployerID field is a foreign key in this table.
Primary keys can only have one occurrence in a table. Foreign keys may have multiple occurrences.
13
Part # 2Why Conceptual Data Modeling is Important?
Effective Communication Tool
User involvement
Independence from a particular
DBMS
Documentation
14
Part # 2
Entity Relationship diagram (ERD) Entity Relationship diagram (ERD)
ERD is commonly used to: Translate different views of data among
managers, users, and programmers to fit into a common framework.
Define data processing and constraint requirements to help us meet the different views.
Help implement the database. Developed by Peter Chen (1976).
17
Part # 2Basic Entity Relationship Diagram (ERD) Elements
Entity : a collection of people, places, objects, events, concepts of interest (a table) Entity instance – a member of the Entity : a
person, a place, an object … (a row in a table) Attribute - property or characteristic of
interest of an entity (a field in a table) Relationship – association between entities
(corresponds to primary key-foreign key equivalencies in related tables)
18
Part # 2
Entity
What should be an Entity: An object that will have many instances in the
database An object that will be composed of multiple
attributes An object that we are trying to model
What should NOT be an Entity: A user of the database system An output of the database system (e.g. a report)
19
Part # 2
Inappropriate entities
System userSystem user System outputSystem output
Appropriate entities
Entity …
20
Part # 2
Entity Instance
Entity instance: a single occurrence of an entity.
Student ID
Last Name
First Name
2144 Arnold Betty
3122 Taylor John
3843 Simmons
Lisa
9844 Macy Bill
2837 Leath Heather
2293 Wrench Tim
instance
entity
21
Part # 2
“describe the entity’s characteristics” Attributes are represented by an
Ellipse/Oval connected to the entity with a line by Chen’s notation.
Each oval contains the name of the attribute it represents.
Entity: EmployeeAttributes: Employee-Name, Extension, Date-Of-
Hire, Job-Skill-Code
AttributesAttributes
23
Part # 2
Classes of attributes
Simple Attribute Composite Attribute Derived Attributes Single-valued Multi-valued Attribute
24
Part # 2
How to find entities and attributes??
Entity: a collection of people, places, objects, events, concepts of interest look for nouns Usually, a proper noun is not a good
candidate…. Attribute: property or characteristic of
interest of an entity look for attribute descriptive words
25
Part # 2
“attributes that uniquely identify entity instances” Uniquely identify every instance of the
entity Composite identifiers are identifiers that
consist of two or more attributes
Entity: Employee
Identifier: Social-Security-Number
(unique) Identifier(unique) Identifier
26
Part # 2
Entities???
ANG Laboratory has several chemists who work on one or more projects. Chemists also may use certain kinds of equipment on each project. The organization would like to store the chemist’s employee identification number, his/her name, up to three phone numbers, his/her project identification number and the date on which the project started. Every piece of equipment, the chemist uses, has a serial number and a cost. Also the organization would like to store the date the chemist was assigned to the project and the date an equipment item was assigned to a particular chemist working on a particular project. A chemist must be assigned at least to one project and one equipment item. Any given equipment item need not be assigned, and a given project need not be assigned either a chemist or an equipment item.
28
Part # 2
Attributes???
ANG Laboratory has several chemists who work on one or more projects. Chemists also may use certain kinds of equipment on each project. The organization would like to store the chemist’s employee identification number, his/her name, up to three phone numbers, his/her project identification number and the date on which the project started. Every piece of equipment, the chemist uses, has a serial number and a cost. Also the organization would like to store the date the chemist was assigned to the project and the date an equipment item was assigned to a particular chemist working on a particular project. A chemist must be assigned at least to one project and one equipment item. Any given equipment item need not be assigned, and a given project need not be assigned either a chemist or an equipment item.
29
Part # 2
Entities & Attributes
Project
Proj#Start-Date
Chemist
Phone#Emp#
EquipmentSerial#
cost
How many attributes do you (as a entity of our school database) have? – name your attributes
30
Part # 2
Example 1: find entities
A department hires many employee. A employee is employed by one department.
A manager manages one department. A department is managed by one manager.
A person must have only one DNA pattern and that pattern must be applied to only one person.
31
Part # 2
Example 2: find entities There are several departments in School of
Business and Public Administration at CSUB. Each department belongs to one school. A department has many professors, but a professor may belong to more than one department. Similarly, courses may be offered by several departments and a department must have at least one course. A professor may teach more than one student, and a student may have more than one professor.
32
Part # 2Example 4: Find all entities, attributes, and (unique) identifier
The FANTASTIC video rental company has several branches throughout the USA. The data held on each branch is the branch address made up of street, city, state, and zip code, and the telephone number. Each branch is given a branch number, which is unique throughout the company. Each branch is allocated staff, which includes a Manager. The Manager is responsible for the day-today running of a given branch. The data held on a member of staff is his or her name, position, and salary. Each member of staff is given a staff number, which is unique throughout the company. Each branch has a stock of videos. The data held on a video is the catalog number, video number, title, category, daily rental, cost, status, and the names of the main actors, and the director. The catalog number uniquely identifies each video.
33
Part # 2Example 4: Find all entities, attributes, and (unique) identifier (con’t)
A customer must first register as a member of a local branch before renting a video tape from any branches. The data held on a member is the first and last name, address, and the date that the member registered at a branch. Each member is given a member number, which is unique throughout all branches of the company. Once registered, a member is free to rent videos, up to maximum of ten at any one time. The data held on each video rented is the rental number, the full name and number of the member, the video number, title, and daily rental, and the dates the video is rented out and date returned. The rental number is unique throughout the company.
34
Part # 2
Relationships
Association between entities (by lines) Any connected entities are called participants Operate in both directions
Relationship between Student and Curriculum A student is enrolled in many curriculums. Each curriculum is being studied by many students.
35
Part # 2
Relationships ???
ANG Laboratory has several chemists who work on one or more projects. Chemists also may use certain kinds of equipment on each project. The organization would like to store the chemist’s employee identification number, his/her name, up to three phone numbers, his/her project identification number and the date on which the project started. Every piece of equipment, the chemist uses, has a serial number and a cost. Also the organization would like to store the date the chemist was assigned to the project and the date an equipment item was assigned to a particular chemist working on a particular project. A chemist must be assigned at least to one project and one equipment item. Any given equipment item need not be assigned, and a given project need not be assigned either a chemist or an equipment item.
36
Part # 2Entities/Relationships& their Attributes
Chemist
Phone#
Project
Proj#Start-Date
Equipment
Works-On
Uses
Date-Assigned
Emp#
Serial#
cost
Assign-Date
37
Part # 2
Steps for creating an ERD Develop draft business rules
Using interviews and documents Identify the entities (look for nouns) Identify the attributes (look for attribute descriptive
words) identify draft business rules
Identify the relationships (look for verb or verb phrases between entities)
Identify cardinalities (look for participation related words and phrases such as zero, none, a, one, several, many…..)
Optional (look for auxiliary verbs such as may, might, can and based upon own judgment..)
Set business rules
38
Part # 2
Cardinality of Relationship One – to – One (1:1)
Each instance in the relationship will have exactly one related member on the other side
One – to – Many (1:M) A instance on one side of the relationship can have many
related members on the other side, but a member on the other side will have a maximum of one related instance
Many – to – Many (M:N) Instances on both sides of the relationship can have many
related instances on the other side
40
Part # 2
Example of 1:1 relationship A one-to-one (1:1) relationship is when at most
one instance of a entity A is associated with one instance of entity B.
Each employee has a one’s own office. Cardinality toward the Office entity
Each office is occupied by one employee. Cardinality toward the Employee entity
41
Part # 2
1:1 relationship
A person must have one and only one DNA pattern and that pattern must apply to one and only one person.
43
Part # 2
Example of 1:M relationship A one-to-many (1:N) relationships is when for
one instance of entity A, there are zero, one, or many instances of entity B, but for one instance of entity B, there is only one instance of entity A.
Each employee has many offices. Cardinality toward the Office entity
Each office is occupied by one employee. Cardinality toward the Employee entity
44
Part # 2
1:M relationshipEach department hires many employees, and each employee is hired by one department.
EMPLOYEEDEPARTMTHIRES
IS_HIRED_BY
46
Part # 2
Example of M:N relationship A many-to-many (M:N) relationship, sometimes
called non-specific, is when for one instance of entity A, there are zero, one, or many instances of entity B and for one instance of entity B there are zero, one, or many instances of entity A.
A employee has multiple offices. Cardinality toward the Office entity
A office must be occupied by many employee. Cardinality toward the Employee entity
47
Part # 2
M:N relationshipEach student takes many classes, and each class is taken by many students.
** This is not a desirable relationship.**
STUDENTCLASSTAKE
IS_TAKEN_BY
48
Part # 2
Complete ER Diagram
Chemist
Phone#
Project
Proj#Start-Date
Equipment
Works-On
Uses
Date-Assigned
N1
N1
Emp#
Serial#
cost
Assign-Date
49
Part # 2Cardinality NotationsCardinality Interpretation
Minimum Instances
Maximum Instances
Graphic Notation
Exactly one
Zero or one
One or many
Zero or many
1
1
0
0
1
1
Many (>1)
Many (>1)
50
Part # 2
Steps for creating an ERD Develop draft business rules
Using interviews and documents Identify the entities (look for nouns) Identify the attributes (look for attribute descriptive
words) identify draft business rules
Identify the relationships (look for verb or verb phrases between entities)
Identify cardinalities (look for participation related words and phrases such as zero, none, a, one, several, many…..)
Optional (look for auxiliary verbs such as may, might, can and based upon own judgment..)
Set business rules