Copyright Kathy S. Schwaig, MBA 8473 Kathy S. Schwaig Information Technology
Copyright Kathy S. Schwaig, Database 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, Database requirements from user User view: part of database important to user Difficult! Why? User Requirements
Copyright Kathy S. Schwaig, Conceptual Design Entity-Relationship Model Entity A “thing” of interest. May be tangible (employee) or intangible (banking transaction). E.g. employee, department, manager, customer. Attributes -- properties or characteristics. Key Each 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, Order number Order date Item number QuantityAmount /08/ Key field This 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, 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 Relationship
Copyright Kathy S. Schwaig, Entity- 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, E-R Diagram StudentCourse SSNname address gradeCourse# description assigned to NM
Copyright Kathy S. Schwaig, 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 Database
Copyright Kathy S. Schwaig, Project Employee Emp# Client Client-Id sponsors finds start-date end-date Project# has date acquired Skill requires Skill- name M N M N l N M N 1 N assigned to
Copyright Kathy S. Schwaig, 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 Database Entity-Relationship Model
Copyright Kathy S. Schwaig, 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 Database Entity-Relationship Model (cont’d)
Copyright Kathy S. Schwaig, Relational 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, Translate E-R Model into Relational Model Each entity represented by an (entity) relation N:M relationship represented by a separate (relationship) relation Key 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, Example: 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, Student Relation Course Relation
Copyright Kathy S. Schwaig, Takes Relation
Copyright Kathy S. Schwaig, 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
Copyright Kathy S. Schwaig,
Copyright Kathy S. Schwaig,
Copyright Kathy S. Schwaig, SQL Query SELECTcolumns FROMtables WHEREconditions ORDER BYcolumns What date was the project called “Metro” completed? Select date-completed From project Where name=‘Metro’ Answer: 1 Mar 1999
Copyright Kathy S. Schwaig, SQL 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, 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 Query