This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Simple to understand Easy to use Simple to understand. Easy to use.
Powerful nonprocedural (what, not how) language toaccess data.
Uniform access to all data.
Rigorous database design principles
5
Rigorous database design principles.
Access paths by matching data values, not by following fixed links.
Relation A 2-dimensional table of values with these properties: No duplicate rows Rows can be in any order
Terminology
y Columns are uniquely named by Attributes Each cell contains only one value
Employee Job Manager
Jack Secretary Jill
Jill Executive Bozo
Bozo Director
6
The special value is NULL which implies that there is nocorresponding value for that cell. This may mean the value does notapply or that it is unavailable. Entire rows of NULLs are notallowed.
A Relational Schema is a named set of attributes. This refers to the structure only of a relation. It is derived from the traditional set notation displayed below
Terminology:Relation Schema
EMPLOYEE = { Employee, Job, Manager }
This is usually written in the modified version for database purposes:
EMPLOYEE( Employee, Job, Manager ) referring to the Table
9
EMPLOYEEEmployee Job Manager
An Integrity Constraint is a condition that prescribes whatvalues are allowable in a relation. This permits the restriction of the
type of value that can be placed in a particular cell. Eg. only numbers for telephone numbers
Terminology:Integrity Constraint and Domain Constraint
numbers for telephone numbers
The Domain Constraint is a condition on the allowable values for an attribute.
For example, If we change the table so that the Employee Bozo does not have a manager then Job+Manager cannot be a key.
Employee Job Manager Salary
Jack Secretary Bozo 25,000
K J ll 25 000
13
Kim Secretary Jill 25,000
Jill Executive Bozo 40,000
Bozo Director 50,000
Lulu Clerk Jill 30,000
A primary key is a special preassigned key that can always be used to uniquely identify tuples. We have to choose a Primary Key for every Relation. We must consider all of the Candidate Keys and choose between them
Terminology:Key Constraint
all of the Candidate Keys and choose between them. Employee is a primary key for EMPLOYEE is usually
written as:EMPLOYEE( Employee, Job, Manager, Salary )
A Relational Database Schema a set of Relation Schemas, together with a set of Integrity Constraints.
For example the Relations that you have been looking at
Terminology:Relational Database Schema
For example the Relations that you have been looking atwith the headings
EMPLOYEE
JOB
are usually written as
Employee Job Manager Salary
Job Salary
17
are usually written asEMPLOYEE(Employee, Job, Manager)
JOB(Job, Salary)
Notice how the Primary Keys are underlined
This constraint says that –All the values in one column should also appear in another column.Look at the table below. Every entry in the Job column of the Employeetable must appear in the Job column of the Job table
Terminology :Referential Integrity Constraint
table must appear in the Job column of the Job table
Referential Integrity constraints can easily be represented by arrows FK PK. The arrow points from the Foreign Key to the matching Primary Key
EMPLOYEE(Employee, Job, Manager) JOB(Job, Salary)
A relational database schema with referential integrity constraints canalso be represented by a network diagram. A Referential IntegrityConstraint is notated as an arrow labeled by the foreign key. You mustalways write the label of the Foreign Key on the arrow. Sometimes thes tt ib t h s diff t titl s i diff t t bl s
g y y
28
same attribute has different titles in different tables.
EMPLOYEE JOBJob
Manager Network DiagramNotice here, the label is Manager and not Employee.
Once you have produced your Schema and identified the Primary andForeign Keys you can create the Network Diagram.The Network Diagramshows each of the tables with their links. Each of the Tables (Relations)are represented in a rectangle as shown. They are then connected byarrows that show the FKs pointing to the PKs, The arrow head pointstowards the PK, while the FK name written is the same as the attribute ofth t bl th t h th FK i it
A relational database is based on the relational data model.It is one or more Relations(Tables) that are Related to each other
A relation is a table composed of rows (tuples) and columns, satisfying 5 properties• No duplicate rows• Rows can be in any order• Columns are uniquely named by Attributes• Each cell contains only one value• No null rows.
34
Constraints are central to the correct modeling of business information. Here we have seen them limit the set up of your tables: Referential Constraint
The Network Diagram is used to navigate complex database structures. It is a compact way to show the relationships between Relations (Tables)
Make reasonable assumptions about the meaning of attribute and relations, identify the primary and foreign keys and draw a network diagram showing the relations and foreign keys.
AA FUNCTIONAL DEPENDENCY DIAGRAM is a way ofrepresenting the structure of information needed tosupport a business or organization
It can easily be converted into a design for a relational
43
database to support the operations of the business.
Data Analysis and Database Design Using Functional Dependency Diagrams
1 Th f D l i i FDD 1. The steps of Data Analysis in FDD are1.1 Look for Data Elements1.2 Look for Functional Dependencies1.3 Represent Functional Dependencies in a
diagram1 4 Eli i R d d F i l
44
1.4 Eliminate Redundant Functional Dependencies
2. Data Design, after we have our final version of the FDD2.1 Apply the Synthesis Algorithm
diagramsTo start the process of constructing our FDD we do the following:
We must Understand the data We Examine forms, reports,data entry and output screens
etc… We Examine sample data
To start the process of constructing our FDD we do the following:
45
We consider Enterprise (business) rules We examine narrative descriptions and conduct interviews. We apply our Experiences/Practice and that of others
Enterprise RulesWhat are Enterprise / Business Rules?An enterprise rule (in the context of data analysis) is astatement made by the enterprise (organisation, company,ff h ) h h d officer in charge etc.) which constrains data in some way.
Functional dependencies are the most important type ofconstraint on data and are often expressed in the form ofenterprise rules.
e.g
46
No two employees may have the same employee number.An order is made by only one customer
An employee can belong to only one department at a time.
We often refer to Data Elements during the FDD process A data element is a elementary piece of recorded A data element is a elementary piece of recorded
information Every data element has a unique name. A data element is either a
Label, e.g PersonName, Address,
47
gBulidingCode, or
Measurement, e.g. Height, Age, Date A data element must take values that can be written
down.
Functional Dependency Diagrams
Using the Method ofDecomposition
Universal Relation
1NF
TablesONF
Sample DataEliminateRepeating
Groups
Attribute& Functional
Dependencies
Given theProblem
Functional
OR, here is the same process using the FDD approach
Here are some examplesP N h l ff ll G E d PersonName has values Jeff, Jill, Gio, Enid
Address has values 1 John St, 25 Rocky Road Height has values 171cm, 195cm Age has values 21,52,93,2 Date has values 20th May 1947, 2nd March 1997 JobName has values Manager Secretary Clerk
49
JobName has values Manager, Secretary, Clerk Manager might not be a data element, but
ManagerName could be. It could be a value of another data element e.g. JobName
Drawing FDDs Data Elements
Start drawing the Functional Dependency Diagram byrepresenting the Data Elements. A Data Element isrepresented by its name placed in a box: D t El trepresented by its name placed in a box:Every data element must have a unique name in thefunctional dependency diagram.A data element cannot be composed of other data
elements i.e.it cannot be broken down into smaller components
Data Element
50
m mpA Data Element is also known as an ATTRIBUTE,
because it generally describes a property of some thing which we will later call an ENTITY
A functional Dependency is a relationship between Attributes.
A B
Drawing FDDs –Using Elements
It is shown as an arrow e.g A B
It means that for every value of A, there is only one value for B It reads “A determines B”.
A is called a determinant attribute
51
A is called a determinant attribute.
B is called the dependent attribute.
Data Element ExamplesHere are some examples of finding the Data Elements on a typical formSurname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
they work for.Department Name Accounting Department Name Salesp gEmployee Number 11
231
pEmployee Number 45
27
In this example the tables are representing some interesting data f th b sin ss W s th t Empl s ith th ID n mb s 11 2
Enterprise Rule: “Each employee works on only one department”
55
of the business. We see that Employees with the ID numbers 11,2 and 31 all work in the Accounting Dept and that Employees with the ID numbers 45 and 27 work in the Sales Dept.
Do you think that you could draw an FDD to represent this? Have a go and then check your answers
FDD AnswersEmployees and the departments
they work for.Department Name AccountingE l N b 11
Department Name SalesEmployee Number 45Employee Number 11
231
Employee Number 4527
Employee# DeptName
Data elements of interest are Employee# and DeptName”
for each subject.We can see that there is only one and only one student name for
h t d t b th h th i ht b th
Student # StudentName
each student number, even though there might be more than one student with the same name. So….
But the subject grade for any student cannot be determined by the subject name or the student# by itself. A student can have many grades depending on the subject How can we cater for
61
many grades depending on the subject. How can we cater for this?
FDDs AnswerResults obtained by each student
for each subject.
We need to combine the two Elements to say that there is
Student StudentName
We need to combine the two Elements to say that there is one and only one grade for a student doing a particular subject. Here then is the complete diagram
Order Part# CustomerName AddressOrder Part# CustomerName Address454 12 David Smith 1 John St, Hawthorn454 23 David Smith 1 John St, Hawthorn455 32 Emily Jones 45 Grattan St, Parkville455 49 Emily Jones 45 Grattan St, Parkville455 54 Emily Jones 45 Grattan St, Parkville456 12 Mary Ho 44 Park St Hawthorn
63
456 12 Mary Ho 44 Park St, Hawthorn456 54 Mary Ho 44 Park St, Hawthorn
Validating functional dependenciesUsing simple data and populating the table, check there is only one value of the
dependent.
FDDs Examples“Orders is uniquely identified by its names”
“Customers are uniquely identified by their names”
“A customer has only one address”
“An order belongs to only one customer”
“A part may be ordered only once one each order”
Order Parts Ordered CustomerName Address454 23, 12 David Smith 1 John St, Hawthorn
64
Order CustomerName
455 54, 49, 32 Emily Jones 45 Grattan St, Parkville456 54, 12 Mary Ho 44 Park St, Hawthorn
Database DesignLet’s look at the process of converting the FDD into a schema. We have a 12 step process to do so, that has an iterative component to it (loop).
67
iterative component to it (loop).The 12 steps are outlined in the next series of slides.
Functional Dependency Diagram Preparation
1 R t h d t l t b1. Represent each data element as a box.2. Represent each functional dependency by an arrow.3. Eliminate augmented dependencies.4. Eliminate transitive dependencies.5. Eliminate pseudo-transitive dependencies.
B thi t i t ti tt ib t h ld h b
68
By this stage, intersecting attributes should have been eliminated.
7. Follow it back to its source, and write down the name of the source.
S8. Follow all arrows from the source data item,
and write down the names of their destinations.
S
A
69
S, A, B, C
S is now the key of a 3NF relation (S , A, B, C).
S
A
BC
S
A
B
Synthesis Algorithm: Deriving 3NF Schema
9. Mark all the arrows just processed.
C
U1 U2 U3
10. If there are any unmarked arrows in the diagram, go back to step 6.
11. Finally, determine the Universal Key. Any attribute which is notdetermined by any other attribute (ie. has no arrow going into it) is part ofthe Universal Key.
70
U1 U2 U3
12. If the universal key is not already contained in any of the above relations, make it into a relation. The universal key is the key of the new relation.
We will now work from a given set of forms to produce an FDD then use the 12 steps to produce the Schema. The forms that p p ffollow show the time spent by a particular employee on a particular project. They contain details of the employee along with details of the project. In addition they also state the hours that the employee has spent on any one project to date. This is important to the FDD. Notice also that the employee can have many previous titles and have a number of skills. This also has to be dealt with in the FDD and then later after we h d th nth i t hni t t th S h m H
71
have used the synthesis technique to create the Schema. Have a good look at the forms on the next 2 slides and try to develop the FDD yourself.
EMPLOYEE ______________________________________________________________________________________________________________NAME E_NUMBER DEPARTMENT LOCATION CURRENT TITLE PRIOR_TITLESSKILLS
Research analyst Investments ______________________________________________________________________________________________________________PROJECTS______________________________________________________________________________________________________________NAME TIME_SPENT P_NUMBER MANAGER ACTUAL_COST EXPECTED_COST ______________________________________________________________________________________________________________Resolve bad debts 35 26713 Kanter 2000 1500______________________________________________________________________________________________________________
72
We say that this table is in “zero normal form” (0NF)This is because the cells have multiple values, eg. Prior titles and Skills. The next slide shows forms that demonstrate that an employee can work on many projects.
EMPLOYEE __________________________________________________________________________________________________________NAME E_NUMBER DEPARTMENT LOCATION CURRENT TITLE PRIOR_TITLES
________________________________________________________________________________________________________________EMPLOYEE _________________________________________________________________________________________________________NAME E_NUMBER DEPARTMENT LOCATION CURRENT TITLE PRIOR_TITLES
Let us just consider the section of the FDD that looks at the project number as the determinant
EXPECTED_COST
ACTUAL_COST
MANAGER_NUM
PROJECT_NAME
P_NUMBER
looks at the project number as the determinant
75
By using the synthesis method we can choose an arrow, trace it back to the source, and gather together all of the attributes that the source points to. Try this and see if you can create the schema for this table.
Personnel Database FD Diagram - Synthesis
Again, if we choose another arrow that has not been chosen before and follow it back to the determinant we find DEPARTMENT NAME is d t min nt G th in ll f th DEPARTMENT_NAME is a determinant. Gathering all of the attributes that it points to we only have the location attribute. Hence this is a simple table consisting of DEPARTMENT_NAME as the Primary key and LOCATION as the only other attribute.
76
LOCATIONDEPARTMENT_NAME
So the tableDEPT(DEPARTMENT_NAME, LOCATION) is created
Likewise for the section of the FDD based around the E_NUMBER, creating the following table for the Employees details.
77
DE MEN _N ME
EMPLOYEE (EMPLOYEE_NAME, E_NUMBER, DEPARTMENT, CURRENT TITLE )
Personnel Database FD Diagram - Synthesis
Here we have a slightly more complicated one. The Time spent on the project is dependent on both the Project number and the Employee name as it is the time spent by a particular employee on a particular
TIME_SPENTP_NUMBER
name, as it is the time spent by a particular employee on a particular project. This is demonstrated by the boxing of both the above attributes together pointing to the TIME_SPENT
78
E_NUMBER
Try to create the Assignment table for this part of the FDD.When you think you have it have a look at ours and see if you are right.
The main difference here is that when choosing the arrow to follow back to the determinant we find that we have 2. This is OK, we just have to make sure that in the table both of them are the primary Key. We have a Composite Primary Key consisting P_NUMBER and E_NUMBER. When we
79
ASSIGNMENT (E_NUMBER, P_NUMBER, TIME_SPENT)
then gather up all of the attributes that they point to together we get TIME_SPENT. Hence the table is written as
See the composite primary key
Personnel Database FD Diagram - Universal Key
Now, the last part of the synthesis is often forgotten. We must collect up all of the attributes that do not have arrows pointing into them and place
P_NUMBERPRIOR TITLE
them in the one table called the Universal Key. Every attribute collected then becomes part of the composite Primary Key. In this case we have the following attributes inside the box below. Notice how Skill is there, as it sits by itself. Nothing is its determinant.
We now have to take care of the multi-valued areas such as skills and prior titles Our FDD synthesis takes care of everything up to that prior titles. Our FDD synthesis takes care of everything up to that. It converts the FDD to what we call “Third normal Form”. We know that an individual can have many skills and many Prior Titles. They can also work on many Projects. Knowing the Employee number will not tell us one and only one value of the Skills that they have. We show this on the extended FDD with a double arrow notation.The notation for such a relationship is shown here where E_NUMBER is a determinant for many values of skill. Consequently the resulting representation shown on the next slide can be constructed, giving rise
85
p , g gto the splitting of the UK to form three more relations
project number (P_Number). This is then the Primary Key. If you then gather all of the attributes that P_Number points to and place them in the brackets you get the table Project with P_Number as the primary Key.
In a Functional Dependency Diagram any group of attributes can be related in only one wayattributes can be related in only one way. For example, a pair of attributes can be related
by an FD or not. Sometimes data can be related in more one way.
For example, a department can have an employee as its head or as a member.
The member relationship is represented in the
91
The member relationship is represented in the FDD:
But the head relationship is represented in the FDD:
E_NUMBER DEPARTMENT_NAME
DEPARTMENT_NAME E_NUMBER
Role Splitting In Functional Dependency Diagrams
W c n ch s t split th E NUMBER tt ibut int E NUMBER nd We can choose to split the E_NUMBER attribute into E_NUMBER andHOD.
But the foreign key constraint that a Head of Department is an Employee is lost on the FDD.
Role Splitting In FDDs Alternatively, we can choose to split the
DEPARTMENT_NAME attribute into EMPLOYING_DEPT andHEADED_DEPT.B h f k h E l But the foreign key constraint that an Employing Department must be a Headed Department is again lost on the FDD.
E_NUMBER EMPLOYING_DEPT
FDD
S nth sis
93
HEADED_DEPT ISA
EMPLOYEE DEPTNetworkD
EMPLOYING_DEPT
E_NUMBER
Synthesis
Role Splitting Example
Consider this example. We have the Employee p p ywith many Skills, Prior Titles, as before but we also have equipment that belongs to a particular employee, such as a computer and a fax. An employee can have many different pieces of equipment. It is worthwhile recognizing them on the diagram and then decomposing them into
By using the ER technique we have the following advantages:
Data Analysis from the User's Point of View Models the Real World I d d t f T h l
99
Independent of Technology Able to be validated in user terms
Entity Relationship Data Model Features
Th l l f sin this t p f m d llin is th t it The real value of using this type of modelling is that it considers the design in context to the environment where it comes from. We have these Entities that have there own identifying attributes, real things and real people. They can be observed in the environment. ERM has the following features:
Populations of Real World objects represented by Entities Objects have Natural Identity
100
Objects have Natural Identity Entities have Attributes which have values Entities related by Relationships Constraints Subtypes
Let’s consider these two instances. Here we have both Jack and Jill, aged 56 and 23 respectively. By themselves they exist as people in their environment. In this case we consider them to be two customers. If we wish to model them and all of the possible customers that we have
101
Entity InstancesObjects
pwe need to create an Entity Class for all possibilities.
Occurrences versus Entities56 28Jack Ackov Jill Hill Customer# CustName
CUSTOMER
Entity OccurrencesEntity InstancesObjectsThese are the Tuples of
Entity ClassesEntity TypesEntity SetsThis will convert to the schema
Here we have Jack and Jill placing orders for particular items of stock. They appear to order different amounts of
3
12
41
each. For instance Jack orders 3 bikes. Each item being ordered also has a Stock#, Price and Description. These are individual instances of the process so we need to be able to represent any
ibilit f thi i
103BikeCup of Tea Pussy Cat23 156 234150 25
possibility of this in our model. See how we do this on the next page.
5628
Jack AckovJill Hill
CUSTOMER
Customer# CustName
ORDERS Quantity
312
4 1
104
ITEM
Stock# DescPriceBike Cup of Tea Pussy Cat23 156 234150 25
Entities are classes of objects about which we wish to store information Entities are classes of objects about which we wish to store information. Examples are:
An entity is Existence Independent if an instance can exist in isolation.For example, CUSTOMER is existence independent of ORDER,
but ORDER is existence dependent on CUSTOMER. The ORDER is by a particular customer for a/many particular item(s)
An entity is identified if each instance can be uniquely distinguished by itsattributes (or relationships).For example, CUSTOMER is identified by Customer#, PERSON
is id tifi d b N Add ss D B ORDER is id tifi d b
107
is identified by Name+Address+DoB, ORDER is identified by Customer#+Date+Time.
STRONG ENTITIES
An entity is STRONG if it can be identified by its (own) immediateattributes. Otherwise it is weak.For example, CUSTOMER and PERSON are strong entities, but
ORDER is weak because it requires an attribute of another entity to identify it. ORDER would be strong if it had an Order#.
1 Entitiesrelevant nounsmany instancesmany instanceshave properties (attributes or relationships) identifiable by properties
2 Strong Entities independent existence identifiable by own single-valued attributes
•3 Attributes
111
3 Attributes–printable names, measurements–domain of values–no properties–dependent existence
A worked example finding strong Entities
A customer is identified by a customer#. A customer has a
name and an address. A customer may order quantities customer may order quantities of many items. An item may
be ordered by many customers. An item is
identified by a stock#. An item has a description and a price. A stock item may have
many colours. Any item
Here we have a scenario. Try to firstly identify all of the strong entities followed and all of the attributes. Can you also identify a weak entity? Are there any attributes that you have missed?
112
Narrative
ordered by a customer on the same day is part of the same
Let us take and place it around the nouns. These lead us to what we will consider to be A customer is identified by a the strong entities. If we then place the around items that we think would be the attributes, we can see if if any of the identified Entities are strong. You will notice that the item has a description, price, colour and stock # and a
t h t
A customer is identified by a customer#. A customer has a
name and an address. A customer may order quantities of
many items. An item may be ordered by many customers. An item is identified by a stock#.
An item has a description and a
113
customer has a customer number, name, and address. These a Existence Independent Entities, and hence they must be strong.
Narrative
price. A stock item may have many colours. Any item ordered by a customer on the same day is
part of the same order
Worked Example ContinuedWe have our Entities and the attributes displayed before us. Customer and Item are strong entities as they are Existence Independent. What about Order?
O d t b
Conceptual Schema
CUSTOMER ITEM
Address Customer# Date
Order cannot be identified completely by any of its own attributes. It is dependent on the attributes of the other 2 entities to be identified. An order is made up of a
114
Description
Price
Quantity Stock#
Customer Name
ORDERColour
An order is made up of a customer ordering an item. We need the customer# and the item# to identify the order
We now attach the attributes that belong to each of the Strong Entities. Notice that there are some left that belong to neither Customer or Item We will look at this later
Conceptual Schema
ITEMCUSTOMERCustomer#
Price
AddressCustName
Stock#
Desc
Colour
Customer or Item. We will look at this later.
115
CustName
DateQty
Both Customer and Item have what we call a Natural Identity
Another Example of the Difference Between Weak and Strong Entities
H is n th x mpl f mm n n th t Here is another example of a common occurrence that demonstrates the difference between a strong entity and a weak entity
A strong entity is identified by its own attributes.Bidders make purchases of goods at the auction.
BIDDER and a GOOD have independent existence, hence are strong, but PURCHASE requires attributes of
d
116
BIDDER and GOOD. The Purchase is the identified by the Bibbers name and the Goods description. These are 2 attributes that belong to both the Bidder and the Good respectively.
A relationship must be relevant. It should indicatea structural, persistent (extending over time)p ( g )association between entities.Students enrol in units selected from the
handbook. A relationship should not usually indicate a
procedural event (one that occurs momentarily,then is forgotten.).
119
th n s forgott n.).Students read about units selected from the
handbook.
Relationships and the Worked Example.
We can now deal with the order. The order is a relationship between the Customer and the Item. It is for a set Quantity on a given Date.
Entity Relationship Analysis 2We will now concentrate on the following areas of good ERMCardinality and Participation ConstraintsCardinality and Participation ConstraintsExpanding to Weak EntitiesIdentifying Weak EntitiesDerived Attributes and RelationshipsTernary Relationships
Step4. Determine constraints: Cardinality(How many participate
To complete this we “fix a single instance at one end and ask how many (one or many) are involved at the other end”.L k t th l ti ship h th C st m O d s
ORDERS
Look at the relationship where the Customer Orders an Item. Consider a single Customer. Can they order many items at the one time? Yes We have seen this. So we position a crows foot (<) at the point where the line touches the Entity Item. We then ask if an Item can be ordered by many Customers? Yes So agin we place a crows foot at the Customers end.
123
CUSTOMER ITEM
From left to right-A Cust can order many Items
From right to left- An Item can be ordered by many Cust
Step4. Determine constraints: Cardinality.
Again to complete this task we “Fix a single instance at one end and ask how
( ) l d h CUSTOMERmany (one or many) are involved at the other end”.All of the Customers live in a City. A Customer can only live in one City(unless they are politicians) In this case we must place a single straight line (|) at the intersection of the relationship line and the Entity City. However,
LIVES IN
124
a city can have many Customers. We show this by placing crows foot (>) at the end near the Customer
Step4. The Resulting ER with the Cardinality Constraints in Place
CUSTOMER ITEMORDERS
CUSTOMER ITEMMany CUSTOMERs
can ORDER anITEM.
Many ITEMs can be
ORDERed by a
CUSTOMER.LIVES INMany CUSTOMERs
can LIVE IN aCITY.
{Colour}
An ITEM can have many
125
CITYA CUSTOMER can
LIVE IN only one CITY.
manyColours.
Step4.Determine constraints: Participation.
Again, we “Fix a single instance at one end and ask if any must (might or must) be involved at the other end”.We ask “Does the Customer have to order an Item? Well We ask Does the Customer have to order an Item? Well, some would say that they do not they are not Customers! But we know that we must be able to recognise our Customers even though at present they do not have an order with us. So, in this case they do not have to place an order. This is then not mandatory, and we show it by placing the O beside the cardinality constraint. An Item does not have to be on an order as well, so it also gets the O notation.
This is also the case for the Customer living in th Cit D s th st m h t li in
CUSTOMER
LIVES IN
in the City. Does the customer have to live in the City? In this case Yes, as we class all areas as being within a City. Hence we place the “|” symbol beside the cardinality constraint next to the Entity City. The next one is difficult. Does a City have to have a Customer living in it. You might think No here, but are you prepared to record all of
127CITY
LIVES IN, y p p fthe cities in the world just to make sure? Common sense tells us that we have to make this mandatory so we only keep a record of the cities where our Customers live.
Step4. The Resulting ER with the Participation Constraints in Place
ORDERSCUSTOMER ITEM
An ITEM might be ordered by a CUSTOMER. A CUSTOMER might
order a ITEM.LIVES INA CITY must have a CUSTOMER LIVing
Step5. Attach remaining attributes to entities and relationships.
In the previous lectures we looked at a worked problem with a Customer ordering an Item. Here we were able to identify Entities from the narration. N t ls list d th tt ib t s hi h h l d s id tif th St E titi s Next we also listed the attributes which helped us identify the Strong Entities. We noticed that there were some Attributes, Qty and Date, left that could not be attached to any of the strong entities. They, in fact, belong to the Relationship that was associated with the two Entities.
Customer# Stock#
131
ITEMCUSTOMERCustomer#
Price
AddressCustName
DescColour
DateQty
ORDERS
Step5. Attach remaining attributes to entities and relationships.
The quantity attribute cannot be attached to the Customer, as the Customer will order different quantities of various items at any time. It cannot also be attached to the Item. It must therefore be attached to the relationship between them, being th d This is ls th sit ti f th
132
the order. This is also the situation for the Date that the order was placed.
Step5. Attach remaining attributes to entities and relationships.
Conceptual Schema
ITEMCUSTOMER
Customer#Price
Add
Stock#
DescDateQty
ORDERS
133
AddressCustName {Colour}
DateQty
Step6.Expand multi-valued attributes, domain sharing attributes and binary
relationship attributes.
Once we have identified the Strong Entities, Relationships and attached all Attributes to either the Relationships and attached all Attributes to either the Strong Entities or Relationships, we are required to expand the diagram as much as possible to permit us to complete the process. This requires us to move in 2 directions. We must first look at all of the binary relationships to see what the cardinality constraints are between them. If they are “many-to-many” they
134
y y y ymust be carefully considered and expanded where appropriate.
We then must look at what we call Multi-valued Attributes and Domain Sharing Attributes. The process is shown on the following diagram.
Step6In the worked example we have a Many-to-Many relationship with 2 attributes . When we have a Many-to-Many relationship with attached attributes we are required to create an Associative Entity that bridges the 2 Entities.
Between Customer and Item we create the Weak (Associative) Entity called Order. We have to redo the constraints. A customer can place many orders or none. An order can come from only one customer, and must be from a customer. An order is for many
Customer# Stock#
MAKES
Associative Entity
, f f yitems and must be for at least one item, and an item can be on many orders but does not have to appear on an order. These have all been placed in the diagram shown below in their correct position.
137
ITEMCUSTOMERPrice
AddressCustName
Desc
DateQty
ORDERMAKES FOR
Step6
We have also noticed that an item can come in many colours. This is a multi-valued attribute. We can show this in our extended diagram by having a relationship between the Item and the Colour, where colour is the only attribute of the entity In this case we are also saying that the
ITEMCUSTOMER
Customer#
Price
Stock#
DORDER
MAKES FOR
Associative Entity
the only attribute of the entity. In this case we are also saying that the colour of the item is optional (IE natural if requested) and that the only colours to be recorded are those that are used.
Managers supervise Workers. All employees are residents of a City. Employees who live in different cities from their managers get a special allowancemanagers get a special allowance.
MANAGER WORKERSUPERVISES
City City
Allowance
CITY
OF
Characteristic Entity
139
MANAGERSUPERVISES
CityName
Allowance
OF OF
WORKER
Step7. Identify weak entities.Clarify the notion of instance.Weak entities are often ambiguous and difficult to
agree onagree on.Attributes may be part of a key for a weak entity, but
at least one (one-must) relationship for identification is required. So when we convert this into a table it will require one of the PKs from the strong entities as part of its own composite PK.
Validation, not design.
140
The purpose of identification is not to allocate a primary key, but to validate the concept. We have to be able to justify the concept of the relationship in the real world.
Never invent keys. I know that it is tempting but you must reflect the business as it is.