4. relational database design objective: to learn how to design a database system. two phases:...
TRANSCRIPT
4. Relational Database Design
Objective: To learn how to design a database
system.
Two phases: Logical database design – logical structures. Physical database design -- implementation.
4. Relational Database Design
Logical database design
To design a database such that the structure of the database is the same as the structure of the real world.
--- Natural Structure of database
4.1 Logical Database Design
Two concepts: Types and occurrences
A logical database design pays attention to the describe of interesting things, rather than the actual occurrences of those things.
entities, attributes and relationships.
Three components are involved to represent the information in database.
4.1 Logical Database Design
Entities, attributes and relationships
Entities: what kind of information is interesting?
Products;Customers;Suppliers;Sales order.
Entities
Entity: a thing, which exists independently, and contains facts that are of interest to us.
4.1 Logical Database Design
Entities, attributes and relationships
Attribute: feature or characteristic of the entity.
Entity identity: each entity must have attributes that provide a unique name or key for it.
Relationships: cross-references between entities.
4.1 Logical Database Design
Entities, attributes and relationships
How to represent a entity? – using attributes.
Customer:NameAddressTelephoneFax
Attributes
4.1 Logical Database Design
How to represent the relationship between customers and products? – using relations/tables
Sales_orders:Customer_NoOrder_dateProduct_NoNumber
Relationship: a new table
Entities, attributes and relationships
4.1 Logical Database Design
Product, Customer, Sales_orders are entity.What is their difference?
A Entity can be used to represent:
Objects
Events/activity
Relationship
In RDBMS, an entity is represented by a relation (table), which includes a set of attributes.
4.2 Information gathering
Logical database design is performed based on information about the organization by
a) observing the organization working;b) talking to experts;c) inspecting documents;
These activities will result in a document description of the organization, possibly in the form of a set of descriptions.
4.2 Information gathering
Example: description of a new employee
A new employee is allocated an employee number and
is assigned to a department. We record details of
the new employee including the number and name
of his/her department, his/her name, NI_number,
home address and telephone number, and also the
number of the employee who has been put in
charge of the new employee and the manager of
the department.
4.3 Data analysis and design
Two steps for Logical database design: Data analysis
Data design.
Data analysis produces a conceptual models/structures of the organization’s data.
Data design implements the logical data structure.
Descriptof Org.
DataAnalysis
DataDesign
Capture Data Model
LogicalData Strut
4.3.1 Data analysis
Task: to determine the structures of data.
Conceptual data model: data and their relationship.
Example:Relationship between customer, sales order and product:
Customer Sales Order Product
4.3.1 Data analysis
Methods: two kinds of data analysis methods:
Bottom-up analysis: from particular to general.
Top-down analysis: from general to particular.
4.3.2 Bottom-up method
Bottom-up analysis: work from attributes to the entities and relationships.
--- data aggregation or synthesis.
Four Steps:1.Identify data items;2.Identify relationship between data items;3.Identify entities;4.Combination of data models.
4.3.2 Bottom-up method
Example: to manage the information of employees:
1. Identify the data items Employee_number; NI_number; Dept_Name; Employee_name; Home_address.
4.3.2 Bottom-up method
2. Identify relationship between data items
1) Which attributes are related to other attributes.
2) What type of relationship: one-to-one, many-to-many, zero-to-zero; zero-or-one-to-many. NOTE: consider how X is related to Y, and
also how Y is related to X, at the same time.
4.3.2 Bottom-up method
2. Identify relationship between data items
Example:Department --- ManagerCustomer --- Sales
OrderSupplier --- PartSchool --- Child
one-one
one-many
*** zero/one-many
many-many
What are the relationships between them?
4.3.2 Bottom-up method
***Work-in
manager
Employee_Number
Employee_Number
NI_Number
Telephone_Number
Employee_Name
Home_address
Employee_Number***In-charge-of
Department_Name
Department_Name
Employee_Number
Employee_Number
Employee_Number
Employee_Number
Employee_Number
4.3.2 Bottom-up method
Department_name
Manager Works-in
Employee_NumberTel_No
Employee_Name
NI_Number
Home_addressIn-charge-of
4.3.2 Bottom-up method
3. Identify entitiesEntities are derived from the above attributes and
relationships.1) In a many-to-one relationship: The values of ‘many’ attributes determine a
value of of the ‘one’ attribute. -- the the ‘many’ side determines the name of
entity, -- the ‘one’ values represent facts about the
entities, are thus considered as attributes.
4.3.2 Bottom-up method
Employee_Number Employee_Name
Home_address
Entity Attributes
Employee Employee_Number Key
Employee_Name
Home_Address
4.3.2 Bottom-up method
2) In a zero/one-many relationship: the ‘many’ side determines the name of a entity, and
the values of the ‘zero/one’ side determines the names of other entities.
Department_Name Employee_No
In-charge-of
******
Entity Attribute
Department Department_Name key
Employee Employee_Number key
Employee_Name
Home_Address
3. Identify entities
4.3.2 Bottom-up method
3) Many-many relationships identify three entities.1)Two ‘many’ attributes each identify an entity;2)The relationship itself is considered to be an
association entity.
Employee_Number
Telephone_Number
Tel-Directory
Entity Attribute
Department Department_Name key
Employee Employee_Number key
Employee_Name
Home_Address
Telephone Telephone_Extension key
Tele-Directory Employee_Number Key
Telephone_Extension
4.3.2 Bottom-up method
4) One-One relationships identify one or two entities.
Employee_Number Department_Name
Entities Attributes
Department Department_Name key
Employee Employee_Number key Employee_Name
Home_Address
Telephone Telephone_Extension key
Tele-Directory Employee_Number Key
Telephone_Extension
4.3.2 Bottom-up method
4. Combine the data models The above analysis may be performed for a
number of descriptions of the organization.
The data models so generated must be then combined to form a single conceptual data model, i.e. models may be merged where they include the same entity types.
In the end, after identifying the entities, attributes and their relationship, a conceptual model is produced, as shown in the diagram pp.176.
4.3.3 Top-down method
It works:
1) from the real world,
2) to the things or objects that are of interest within the real world, --- entities
3) to the relationship between those objects and to the properties of those objects.
--- attributes and relationships.
4.3.3 Top-down method
Step 1: Identify entities An entity is a thing that has independent existence
and about which we wish to represent information. We can deduce the existence of entities by
reasoning about activities and the data.
Distinguish entities from attributes: An entity has an existence of its won; Attributes exists only as a property of an entity. Examples:
Employee, NI_Number, Employee_Name.
4.3.3 Top-down method
A property of an entity: must be uniquely identifiable.
Example: A new employee is allocated an employee
number and is assigned to a department. We
record the details of the new employee, including
the number and name of the employee’s
department, the employee’s name, NI number,
home address, and their telephone number, also
their manager, and the department’s manager.
4.3.3 Top-down method
Employee;Department;Telephone_No;Employee’s manager;Department Name;Department Number;Departmental Manager;Employee’s name, Employee’s number, Employee’s NI_No, Employee’s home address.
Employee;Department;Telephone_No
4.3.3 Top-down method
Step 2: Identify relationships between entities
A relationship is implied by ‘has….’, ‘requires a number of …..’ or ‘is a part of ….. ‘These phrase references one entity in describing another.
Employee --- assigned to --- department
Employee ---- contacted by --- telephone no
Employee -- in-charge-of --- employee
Employee – is manager of --- department
4.3.3 Top-down method
Step 2: Identify relationships between entities:
employee
In-charge-of
Tele_No
Contacted_by
department
Assigned_to
Manager
4.3.3 Top-down method
Step 2: Identify relationships between entities:Consider the type of relationship
employee
In-charge-of
Tele_No
Contacted_by
department
Assigned_to
Manager
*** ***
4.3.3 Top-down method
Step 3: Identify entity attributesEntity Attribute
Employee Number NI Number Name, Home address
Department Name Number Manager
Telephone Extension Users
Step 4: Combine any separate models
Employee;Department;Telephone_No;Employee’s manager;Department Name;Department Number;Departmental Manager;Employee’s name, Employee’s number, Employee’s NI_No, Employee’s home address.
4.4 Functional Analysis
Some entities and attributes may not become apparent during data analysis.
Missing relationships can result in what called connection traps.
Functional analysis focuses on the analysis of:
The validity of the data model; The completeness of the data analysis; Redundancy.
4.5 Data Design
Data Design: the second phase of logical
database design is to represent the natural
structure recorded in the conceptual data
model using a number of relations/tables.
4.5 Data Design
The following is the conceptual data model
employee
Response_to
Tele_No
Contacted_by
department
Assigned_to
Manager
***
Employee: Number, name,
NI_no, Home_Add
Department: Name, Number
Telephone: Tele_No
4.5 Data Design
Task of Data Design: Transform the conceptual data model into a relational database.
Rule 1: Entities:Each entity becomes a relation/table;Each property becomes an attribute in the relation;A primary key is selected.
Employee (Employee_No, name, NI_no, Home_Add)Department (No, Name)Telephone (Tele_No)
4.5 Data Design
Rule 2: One-to-many relationsThe primary key of the one relation is used
as a foreign key in the many relation:
Employee (Employee_No, name, NI_no, Home_Add, Manager_No)
Department (No, Name)Telephone (Tele_No)
Employee Employee
4.5 Data Design
Rule 3: Many-to-many relationsIt can be resolved as two one-to-many
relationships, and the above rules then apply.
Employee (Employee_No, name, NI_no, Home_Add, Manager_No)
Department (No, Name)Telephone (Tele_No) Emp_Tele (Employee_No, Tele_NO)
Employee Telephone
Employee Emp_Tele Telephone
4.5 Data Design
Rule 4: Zero/One-to-many relationsIt can be represented by a separate relation, in
the same way that many-to-many relation are.
Employee (Employee_No, name, NI_no, Home_Add, Manager_No)
Department (No, Name)Telephone (Tele_No) Emp_Tele (Employee_No, Tele_NO)Dept_Emp (Department_No, Employee_NO)
Department Employee***
4.6 Summary
Logical database design is to determine a natural structure for a database.
Identifying the natural structure is called data analysis, which produces conceptual data model.
Two data analysis methods: Top-down and bottom-up;
Functional analysis is the analysis of the activities and the related information;
Data design is to determine the logical database structure.