Presentation is loading. Please wait.

Presentation is loading. Please wait.

ER to Relational Translation COMSATS INSTITUTE OF INFORMATION TECHNOLOGY, VEHARI.

Similar presentations


Presentation on theme: "ER to Relational Translation COMSATS INSTITUTE OF INFORMATION TECHNOLOGY, VEHARI."— Presentation transcript:

1 ER to Relational Translation COMSATS INSTITUTE OF INFORMATION TECHNOLOGY, VEHARI

2 Relational Models Tables: In relation data model, relations are saved in the format of Tables. This format stores the relation among entities. A table has rows and columns, where rows represent records and columns represents the attributes. Tuple: A single row of a table, which contains a single record for that relation is called a tuple. Relation instance: A finite set of tuples in the relational database system represents relation instance. Relation instances do not have duplicate tuples.

3 Relational Models Relation schema: This describes the relation name (table name), attributes and their names. Relation key: Each row has one or more attributes which can identify the row in the relation (table) uniquely, is called the relation key. Attribute domain: Every attribute has some pre-defined value scope, known as attribute domain.

4

5 From ER Model to Relational Model So… how do we convert an ER diagram into a table?? Simple!! Basic Ideas:  Build a table for each entity set  Build a table for each relationship set if necessary (more on this later)  Make a column in the table for each attribute in the entity set  Primary Key

6 Example – Strong Entity Set SIDNameMajorGPA 1234JohnCS2.8 5678MaryEE3.6 Student SIDName Major GPA Advisor Professor SSNName Dept SSNNameDept 9999SmithMath 8888LeeCS

7 Representation of Weak Entity Set Weak Entity Set Cannot exists alone To build a table/schema for weak entity set ◦Construct a table with one column for each attribute in the weak entity set ◦Augment one extra column on the right side of the table, put in there the primary key of the Strong Entity Set (the entity set that the weak entity set is depending on) ◦Primary Key of the weak entity set = foreign key

8 Example – Weak Entity Set AgeNameParent_SID 10Bart1234 8Lisa5678 Student SIDName Major GPA Name Age Childrenowns * Primary key of Children is Parent_SID + Name

9 Representation of Relationship Set Unary/Binary Relationship set  Depends on the cardinality and participation of the relationship N-ary (multiple) Relationship set Identifying Relationship  No relational model representation necessary

10 Representing Relationship Set Unary/Binary Relationship For one-to-one relationship w/out total participation ◦Build a table with two columns, one column for each participating entity set’s primary key. Add successive columns, one for each descriptive attributes of the relationship set (if any). For one-to-one relationship with one entity set having total participation ◦Augment one extra column on the right side of the table of the entity set with total participation, put in there the primary key of the entity set without complete participation as per to the relationship.

11 Example – One-to-One Relationship Set SIDMaj_ID CoS_Degree 9999071234 8888055678 Student SIDName Major GPA ID Code Majorstudy * Primary key can be either SID or Maj_ID_Co Degree

12 Example – One-to-One Relationship Set SIDNameMajorGPALP_S/NHav_Cond 9999BartEconomy-4.0123-456Own 8888LisaPhysics4.0567-890Loan Student SIDName Major GPA S/N # LaptopHave * Primary key can be either SID or LP_S/N Condition Brand 1:1 Relationship

13 Representing Relationship Set Unary/Binary Relationship For one-to-many relationship w/out total participation ◦Same thing as one-to-one For one-to-many/many-to-one relationship with one entity set having total participation on “many” side ◦Augment one extra column on the right side of the table of the entity set on the “many” side, put in there the primary key of the entity set on the “one” side as per to the relationship.

14 Example – Many-to-One Relationship Set SIDNameMajorGPAPro_SSNAd_Sem 9999BartEconomy-4.0123-456Fall 2006 8888LisaPhysics4.0567-890Fall 2005 Student SIDName Major GPA SSN Professor * Primary key of this table is SID Semester Name N:1 Relationship Dept Advisor

15 Representing Relationship Set Unary/Binary Relationship For many-to-many relationship ◦Same thing as one-to-one relationship without total participation. ◦Primary key of this new schema is the union of the foreign keys of both entity sets.

16 Representing Relationship Set N-ary Relationship Intuitively Simple ◦Build a new table with as many columns as there are attributes for the union of the primary keys of all participating entity sets. ◦Augment additional columns for descriptive attributes of the relationship set (if necessary) ◦The primary key of this table is the union of all primary keys of entity sets that are on “many” side ◦That is it, we are done.

17 Example – N-ary Relationship Set P-Key1P-Key2P-Key3A-KeyD-Attribute 9999888877776666Yes 1234567890123456No E-Set 1 P-Key1 Another Set * Primary key of this table is P-Key1 + P-Key2 + P-Key3 D-Attribute A relationship A-Key E-Set 2 P-Key2 E-Set 3 P-Key3

18 Representing Composite Attribute Relational Model Indivisibility Rule Applies One column for each component attribute NO column for the composite attribute itself Professor SSNName Address SSNNameStreetCity 9999Dr. Smith50 1 st St.Fake City 8888Dr. Lee1 B St.San Jose StreetCity

19 Representing Multivalue Attribute For each multivalue attribute in an entity set/relationship set ◦Build a new relation schema with two columns ◦One column for the primary keys of the entity set/relationship set that has the multivalue attribute ◦Another column for the multivalue attributes. Each cell of this column holds only one value. So each value is represented as an unique tuple ◦Primary key for this schema is the union of all attributes

20 Example – Multivalue attribute SIDNameMajorGPA 1234JohnCS2.8 5678HomerEE3.6 Student SIDName Major GPA Stud_SIDChildren 1234Johnson 1234Mary 5678Bart 5678Lisa 5678Maggie Children The primary key for this table is Student_SID + Children, the union of all attributes


Download ppt "ER to Relational Translation COMSATS INSTITUTE OF INFORMATION TECHNOLOGY, VEHARI."

Similar presentations


Ads by Google