Upload
ginger-allison
View
215
Download
0
Tags:
Embed Size (px)
Citation preview
Copyright Kathy S. Schwaig, 2001 1
MBA 8473
Kathy S. Schwaig
Information Technology
Copyright Kathy S. Schwaig, 2001 2
Database Design StepsDatabase Design Steps
User Requirements
Conceptual Design(E.g. entity-relationship model)
Logical Design(E.g. relational model)
Physical Design(optimize for
performance)
Copyright Kathy S. Schwaig, 2001 3
•Database requirements from user
•User view: part of database important to user
•Difficult! Why?
User RequirementsUser Requirements
Copyright Kathy S. Schwaig, 2001 4
Conceptual Design Entity-Relationship Model
Conceptual Design Entity-Relationship Model
EntityA “thing” of interest.
May be tangible (employee) or intangible (banking transaction).
E.g. employee, department, manager, customer.
Attributes -- properties or characteristics.
KeyEach entity must be uniquely identified by an attribute
or group of attributes called a key. E.g.: Employee: [EMP#, name, address, phone#]
Copyright Kathy S. Schwaig, 2001 5
Order number
Order date
Item number
Quantity Amount
4340 02/08/94 1583 2 1740
Key fieldThis record describes the entity called ORDER and its attributes. The specific values for order number, order date, item number, quantity, and amount for this particular order are the fields for this record. Order number is the key field because each order is assigned a unique identification number.
Order : [Order number , order date, item number, quantity, amount]
Attributes
ENTITY = ORDER
Copyright Kathy S. Schwaig, 2001 6
An association between entities.E.g. Managers manage Employees
Cardinalities indicate the number of each entity that may participate in the relationship.One to one (1:1)One to many (1:N)Many to many (N:M)
M:N relationships may have relationship attributes.E.g. Employees assigned-to Projects:[length-of-time]
N : M
RelationshipRelationship
Copyright Kathy S. Schwaig, 2001 7
Entity- Relationship DiagramEntity- Relationship Diagram
Each entity represented by a rectangle.
Each relationship represented by a diamond.
Attributes shown in ovals.
Cardinalities next to entities
Copyright Kathy S. Schwaig, 2001 8
E-R DiagramE-R Diagram
Student Course
SSN name
address
grade Course#
description
assigned toN M
Copyright Kathy S. Schwaig, 2001 9
You have been asked to create a database for a small consulting company. The company wants to keep track of which employees are assigned to which project and what dates they start and stop working on them. An employee can work on more than one project at a time (as any MBA student knows). You also need to keep track of which client sponsors which project(s). Each project usually requires a set of skills so you need to know what skills an employee has and when he or she obtained them. Employees are encouraged to find clients and receive extra compensation for
doing so.
Consulting Company DatabaseConsulting Company Database
Copyright Kathy S. Schwaig, 2001 10
Project
Employee
Emp#
Client
Client-Id
sponsors
finds
start-date
end-date
Project#
has
date
acquired
Skill
requires
Skill-
name MN
M
N
l
N
M
N
1
N
assigned to
Copyright Kathy S. Schwaig, 2001 11
Entities
Employee : [Emp#, name, address, dob, hourly-rate]
Client : [Client-Id, name, phone, date-signed]
Skill : [Skill-name, description]
Project : [Project#, name, date-began, date-completed]
Consulting Company DatabaseEntity-Relationship Model
Consulting Company DatabaseEntity-Relationship Model
Copyright Kathy S. Schwaig, 2001 12
Relationships
Employee finds Client
1 : N
Client sponsors Project
1 : N
Employee has Skill : [date-acquired]
N : M
Project requires Skill
N : M
Employee assigned-to Project : [start-date, end-date]
N : M
Consulting Company DatabaseEntity-Relationship Model (cont’d)
Consulting Company DatabaseEntity-Relationship Model (cont’d)
Copyright Kathy S. Schwaig, 2001 13
Relational Data ModelRelational Data Model
One basic construct: the relation.
Relations represent both entities and relationships.
Data Manipulation Language: English-like.
Dominant database structure.
DB2 by IBM
ACCESS by Microsoft
ORACLE
Copyright Kathy S. Schwaig, 2001 14
Translate E-R Model into Relational ModelTranslate E-R Model into Relational Model
Each entity represented by an (entity) relation N:M relationship represented by a separate
(relationship) relationKey is concatenation (joining together) of entity
keys.Relationship attributes are non keys.
1:N relationship represented by foreign key, i.e. key of entity on “1” side appears as non key in relation for the entity on the “N” side.
Copyright Kathy S. Schwaig, 2001 15
Example: Student-CourseExample: Student-Course
Design a database to keep track of what courses a student takes and the grade he or she receives.
Entities: Student: [SSN, name, address]Course: [Course-Id, description]
Relationships: Student takes Course: [grade] N : M
Copyright Kathy S. Schwaig, 2001 16
Student RelationStudent Relation
SSN name address
111-22-3333 M . Tomkins 17 Oak St.
444-71-2222 L.Richardo 22 Tilly Court
795-44-1111 H. M cEnroe 33 Star St.
C ourse-Id description
M B A 401 M gt. Inform ation System s
C IS 481 Strategic System s
C IS 721 D atabase M gt. System s
Course RelationCourse Relation
Copyright Kathy S. Schwaig, 2001 17
Takes RelationTakes Relation
SSN Course-Id, grade
795-44-1111 CIS 721 A
444-71-2222 CIS 481 B
111-22-3333 MBA 401 B
Copyright Kathy S. Schwaig, 2001 18
Employee : [Emp#, name, address, dob, hourly-rate]
Client : [Client-Id, name, phone, date-signed, emp#]
Project : [Project#, name, date-began, date-completed, client-id]
Skill : [Skill-name, description]
Has-skill : [Emp#, Skill-name, date-acquired]
Requires : [Project#, Skill-name]
Assigned : [Emp#, Project#, start-date, end-date]
Consulting Company Relational Model
Consulting Company Relational Model
Copyright Kathy S. Schwaig, 2001 19
EmployeeEmp# name address dob hourly-
rate741 Fred Smith 12 Peachtree Rd 1 Jan 1960 75852 Sarah Thomas 807 Piedmont Rd 6 May 1959 85963 Daniel McCarthy 4321 Cobb Dr 15 Oct 1961 69357 Ellen Lewis 15 Peachtree Rd 14 Feb 1961 55
ClientClient--Id name phone date-signed emp#1150 Joe Johnson 555-7412 14 Dec 1998 8521151 Stacey Smith 555-8523 7 Jan 1999 7411152 Donald Davis 888-3699 26 Jan 1999 8521153 Ed Edwards 777-9513 28 Feb 1999 963
ProjectProject# name date-began date-completed client-id9357 Virtual Courtyard 30 Jan 1999 11529159 Metro 8 Jan 1999 1 Mar 1999 11519752 Pontiac 5 Mar 1999 11539684 Looking Glass 30 Dec 1998 15 Feb 1999 1150
SkillSkill-name descriptionRelational database Relational db design and implementationObject-oriented database Object-oriented db design and implementationData Mining Implementing data mining systemsElectronic Commerce Intranet development and ecommerce
applications
Copyright Kathy S. Schwaig, 2001 20
Has-skillEmp# Skill-name date-required852 Electronic Commerce 7 Jan 1999852 Relational database 30 Dec 1998741 Relational database 15 Jan 1999852 Data Mining 10 Jan 1999963 Data Mining 15 Mar 1999
RequiresProject# Skill-name9357 Electronic Commerce9684 Relational database9159 Relational database9684 Data Mining9357 Data Mining9752 Data Mining
AssignedEmp# Project# start-date end-date852 9357 30 Jan 1999741 9159 8 Jan 1999 1 Mar 1999963 9752 5 Mar 1999852 9684 30 Dec 1998 15 Feb 1999
Copyright Kathy S. Schwaig, 2001 21
SQL QuerySQL Query
SELECT columns FROM tables WHEREconditions ORDER BY columns
•What date was the project called “Metro” completed? Select date-completed From project Where name=‘Metro’
•Answer: 1 Mar 1999
Copyright Kathy S. Schwaig, 2001 22
SQL QuerySQL Query
•What is the name of the client who sponsors the project called “Pontiac”? Select client.name From client, project Where project.name=‘Pontiac’ and project.client-id=client.client-id
•Answer: Ed Edwards
Copyright Kathy S. Schwaig, 2001 23
•What skills are required for the project called “Virtual Courtyard”?
SELECT requires.skill-name
FROM requires, project
WHERE project.name= ‘Virtual Courtyard’ and
requires.project# = project.project#
Answer: Electronic Commerce
Data Mining
SQL QuerySQL Query