Database Design Using Entity-Relationship Models zMapping E-R models into relations zFour common...
-
Upload
caiden-woodbridge -
Category
Documents
-
view
218 -
download
0
Transcript of Database Design Using Entity-Relationship Models zMapping E-R models into relations zFour common...
![Page 1: Database Design Using Entity-Relationship Models zMapping E-R models into relations zFour common data structures.](https://reader035.fdocuments.in/reader035/viewer/2022062404/5519b1c355034667578b460e/html5/thumbnails/1.jpg)
Database Design Using Entity-Relationship Models
Mapping E-R models into relationsFour common data structures
![Page 2: Database Design Using Entity-Relationship Models zMapping E-R models into relations zFour common data structures.](https://reader035.fdocuments.in/reader035/viewer/2022062404/5519b1c355034667578b460e/html5/thumbnails/2.jpg)
Mapping E-R Models to Tables
We may not be familiar with all notationsThere may be E-R constructs that cannot
be translated directly Multi-valued attributes Ternary relationships
We may need to change the data model Change a relationship into an entity Change an entity into an attribute Collapse two entities Make a strong entity weak
![Page 3: Database Design Using Entity-Relationship Models zMapping E-R models into relations zFour common data structures.](https://reader035.fdocuments.in/reader035/viewer/2022062404/5519b1c355034667578b460e/html5/thumbnails/3.jpg)
Basic Conversion Rules
A database conforming to an E-R diagram can be represented by a collection of tables.
Converting an E-R diagram to a table format is the basis for deriving a relational database design from an E-R diagram. Primary keys allow entities and relationships to
be expressed uniformly as tables. For each entity and many-to-many relationship
there is a unique table, named after it. Each table has columns (generally corresponding
to attributes) with unique names.
![Page 4: Database Design Using Entity-Relationship Models zMapping E-R models into relations zFour common data structures.](https://reader035.fdocuments.in/reader035/viewer/2022062404/5519b1c355034667578b460e/html5/thumbnails/4.jpg)
Representing Entities as Tables
A strong entity set reduces to a table with the same attributes
CUSTOMER (CustNumber, CustName, Address, City,State, Zip, ContactName, PhoneNumber)
![Page 5: Database Design Using Entity-Relationship Models zMapping E-R models into relations zFour common data structures.](https://reader035.fdocuments.in/reader035/viewer/2022062404/5519b1c355034667578b460e/html5/thumbnails/5.jpg)
Representing Entities
We then may need to normalize the table if it is not in DK/NF
De-normalize?
CUSTOMER (CustomerNumber, Address, Zip, ContactName)ZIP-TABLE (Zip, City, State)CONTACT (ContactName, PhoneNumber)
Interrelation (integrity) constraints:CUSTOMER[Zip] ZIP-TABLE[Zip]
CUSTOMER[ContactName] CONTACT[ContactName]
CUSTOMER (CustNumber, CustName, Address, City, State, Zip, ContactName, PhoneNumber)
![Page 6: Database Design Using Entity-Relationship Models zMapping E-R models into relations zFour common data structures.](https://reader035.fdocuments.in/reader035/viewer/2022062404/5519b1c355034667578b460e/html5/thumbnails/6.jpg)
Representing Weak Entities
Weak entity sets must be documented by referential integrity constraints
An ID-dependent weak entity set becomes a table that includes a column for the primary key of the identifying strong entity
The table corresponding to the weak relationship is redundant
![Page 7: Database Design Using Entity-Relationship Models zMapping E-R models into relations zFour common data structures.](https://reader035.fdocuments.in/reader035/viewer/2022062404/5519b1c355034667578b460e/html5/thumbnails/7.jpg)
Representing HAS-A Relationships
1:1 - Place key of one relation into other Perhaps they should be combined!
1:N - Place key of parent into child
Foreign key!
![Page 8: Database Design Using Entity-Relationship Models zMapping E-R models into relations zFour common data structures.](https://reader035.fdocuments.in/reader035/viewer/2022062404/5519b1c355034667578b460e/html5/thumbnails/8.jpg)
Representing HAS-A Relationships
M:N - Build a table with columns for primary keys of two participating entity sets May add descriptive attributes of relationship set
Intersectionrelation
Error!
![Page 9: Database Design Using Entity-Relationship Models zMapping E-R models into relations zFour common data structures.](https://reader035.fdocuments.in/reader035/viewer/2022062404/5519b1c355034667578b460e/html5/thumbnails/9.jpg)
Recursive Relationships
Same as non-recursive relationships
One participant instead of two
E.g., 1:1 Remember two
alternatives Foreign key can have
NULL values (when?)
![Page 10: Database Design Using Entity-Relationship Models zMapping E-R models into relations zFour common data structures.](https://reader035.fdocuments.in/reader035/viewer/2022062404/5519b1c355034667578b460e/html5/thumbnails/10.jpg)
Recursive Relationships
What about 1:N and M:N recursive? Give an example of each, not from book :) How many tables do you end up with, in
each case? How is this different from the non-recursive
case? What is the domain of the foreign key?
![Page 11: Database Design Using Entity-Relationship Models zMapping E-R models into relations zFour common data structures.](https://reader035.fdocuments.in/reader035/viewer/2022062404/5519b1c355034667578b460e/html5/thumbnails/11.jpg)
Higher-order Relationships
Treat as combination of binary relationshipsBinary constraints must be enforced with
business rulesTypes of constraints:
MUST (ORDER:CUSTOMER:SALESPERSON)ORDER(OrdNo, CustNo, SalespersonNo, ...)CUSTOMER(CustNo, SalespersonNo, ...)SALESPERSON(SalespersonNo, ...)
MUST NOT (PRESCRIPTION:DRUG:PATIENT) MUST COVER (AUTO:REPAIR:TASK)
![Page 12: Database Design Using Entity-Relationship Models zMapping E-R models into relations zFour common data structures.](https://reader035.fdocuments.in/reader035/viewer/2022062404/5519b1c355034667578b460e/html5/thumbnails/12.jpg)
Representing IS-A Relationships
Specialization method Form a table for each sub-type entity No table for generalized (super-type) entity Common attributes are repeated
![Page 13: Database Design Using Entity-Relationship Models zMapping E-R models into relations zFour common data structures.](https://reader035.fdocuments.in/reader035/viewer/2022062404/5519b1c355034667578b460e/html5/thumbnails/13.jpg)
Representing IS-A Relationships
Generalization method Form a table for the super-type entity Form a table for each sub-type entity (include
primary key of generalized entity set, 1:1) Common attributes are inherited
Need this?Usually same key
![Page 14: Database Design Using Entity-Relationship Models zMapping E-R models into relations zFour common data structures.](https://reader035.fdocuments.in/reader035/viewer/2022062404/5519b1c355034667578b460e/html5/thumbnails/14.jpg)
Trees (hierarchies)
Nodes are entitiesOnly 1:N relationships
(branches)Each child has a
unique parent Root: unique node
without parent Siblings: children
sharing parentObvious relational
representation
Root
![Page 15: Database Design Using Entity-Relationship Models zMapping E-R models into relations zFour common data structures.](https://reader035.fdocuments.in/reader035/viewer/2022062404/5519b1c355034667578b460e/html5/thumbnails/15.jpg)
Simple Networks
Only 1:N relationships
But a child can have more than one parent (of different types)
Obvious relational representation
![Page 16: Database Design Using Entity-Relationship Models zMapping E-R models into relations zFour common data structures.](https://reader035.fdocuments.in/reader035/viewer/2022062404/5519b1c355034667578b460e/html5/thumbnails/16.jpg)
Complex Networks
A child can have multiple parents of the same type
At least one N:M relationshipNeed intersection relations(s)
![Page 17: Database Design Using Entity-Relationship Models zMapping E-R models into relations zFour common data structures.](https://reader035.fdocuments.in/reader035/viewer/2022062404/5519b1c355034667578b460e/html5/thumbnails/17.jpg)
Bills of Materials
A special case of networksM:N recursive relationshipsForeign keys in intersection
relation have same domain
![Page 18: Database Design Using Entity-Relationship Models zMapping E-R models into relations zFour common data structures.](https://reader035.fdocuments.in/reader035/viewer/2022062404/5519b1c355034667578b460e/html5/thumbnails/18.jpg)
Example: Practice!...
![Page 19: Database Design Using Entity-Relationship Models zMapping E-R models into relations zFour common data structures.](https://reader035.fdocuments.in/reader035/viewer/2022062404/5519b1c355034667578b460e/html5/thumbnails/19.jpg)
Another Example: Overhead
EMPLOYEE: SSN, Fname, Minit, Lname, BirthDate, Address, JobTypeSECRETARY: SSN, TypingSpeedTECHNICIAN: SSN, TGradeENGINEER: SSN, EngType
EMPLOYEE: SSN, Fname, Minit, Lname, BirthDate, Address, JobType, TypingSpeed, Tgrade, EngType
![Page 20: Database Design Using Entity-Relationship Models zMapping E-R models into relations zFour common data structures.](https://reader035.fdocuments.in/reader035/viewer/2022062404/5519b1c355034667578b460e/html5/thumbnails/20.jpg)
Another Example: Overhead
CAR: VehicleID, LicensePlateNo, Price MaxSpeed, NoOfPassengers
TRUCK: VehicleID, LicensePlateNo, Price, NoOfAxles, Tonnage
PART: PartNo, Description, MFlag, DrawingNo, ManufactureDate, BatchNo, PFlag, SupplierName, ListPrice
![Page 21: Database Design Using Entity-Relationship Models zMapping E-R models into relations zFour common data structures.](https://reader035.fdocuments.in/reader035/viewer/2022062404/5519b1c355034667578b460e/html5/thumbnails/21.jpg)
Another Example: Overhead
PERSON: SSN, Fname, Minit, Lname, BDate, No, Street, AptNo, City, State, Zip
EMPLOYEE: SSN, Salary, Rank, Office, Phone
STUDENT: SSN, Class, Gflag
GRAD_DEGREES: SSN, Year, Degree, College
INSTRUCTOR_RESEARCHER: SSN