- Now we want to convert the conceptual ER schema into a relational database schema
- This step is called Mapping
- We then express this relational schema using SQL code
Relational Data Model
![[Data Models in Databases#23-relational-model-ุงูุฃุดูุฑ|2.3 Relational Model (ุงูุฃุดูุฑ)]]
Constraints
We talked about Participation Constraints In relationships
ER to Relational Mapping
Mapping Steps
Summary
Mapping Type | Solution |
---|---|
1. Strong Entities | Create a new table for each strong entity |
2. Weak Entities | Create a new table and add a foreign key for the strong entity |
3. Binary Relationships | |
- 1:1 Must-Must | Combine in one table (no new table needed) |
- 1:1 May-Must | Foreign key on the โMustโ side (no new table needed) |
- 1:1 May-May | Foreign key on either side (no new table needed) |
- 1:M Must from โManyโ side | Foreign key on the โManyโ side (no new table needed) |
- 1:M May from โManyโ side | Foreign key on the โManyโ side (no new table needed) |
- M:N | Create a new linking table for the relationship |
4. Ternary Relationships | Create a new linking table with three foreign keys |
5. Unary Relationships | Use a self-referencing foreign key or create a new table depending on the relationship type |
1. Mapping of regular(Strong) Entity Types
1) Composite Attribute
ุนุดุงู ุฃุธูุฑูุง ุจุนู
ููุง ุนูู ุญุณุจ ุงูู Constraint File ุฃู ููุง ููููุง ุนููู Equations File
ููุงุฒู
ุฃูุชุจ ูููุง ุญุงุฌุฉ ุฒู Composite ุงููุง ูุชุธูุฑ ุงูุฅุณู
(Mahmoud Feshar)
ูุนูู ุจูุชุจ ุงูู
ุนุงุฏูุฉ ููุณูุง ุฃู ุงูู Equation
2) Multivalued Attributes
ุงูู Complex Attribute ุฒููุง ุจุฑุถู ุจุงูุธุจุท
3) Mapping of Derived Attributes
ุจูุนู ู Ignore ููู Derived ูููุชุจ ุงูุฃุตููุฉ ุจุณ ู ู ูู ูู ุงูุจูุฒููุณ ูุฎูููุง ูุนู ููุง Column ุนุงุฏู
ุจููุชุจ ุจุฑุถู ุงูู
ุนุงุฏูุฉ ุจุชุงุนูุง ูู ุงูู Equations File
ูุนูู ู
ุซููุง Age = CurrentDate - DOB
ูู ูู ู
ุฑุฉ ูุญุณุจ ุงูู
ุนุงุฏูุฉ ุฏู ูุฃูุง ู
ุด ู
ุนุงูุง Resources ูุงุนู
ููุง Column ุนุงุฏู
ุฃู ูู ุนุงูุฒ ุฃุนู
ู ู
ุซููุง ุงูุฃุจูููุดู ูุจูุง ุณุฑูุน ูุฃูู ู
ุด ูุนู
ู ุงูุนู
ููุฉ ุฏู ุฒู ุงูุฃุจูููุดูุฒ ุงููุงูุช
ูุงุฒู
ุชุนู
ู ู
ูุดู ูู ุงูู Equation ูู ูู ู
ุนุชู
ุฏุฉ ุนูู ุฏุงุชุง ู
ู Table ุชุงูู
2. Mapping of Weak Entity Type
ุงูุชูุฑ ุงู ุงูู Weak Entity ู
ุจูุจูุงุด ูููุง Primary key ูุจูุจูุง ูููุง Partial Key
3. Mapping Relationships
1) Binary M:N Relationship
2) Binary 1:M Relationship
Approach 1 (Must)
Approach 2 (May)
3)Binary 1:1 Relationship
Approach 1 (Total-partial)
Approach 2 (Total-total)
Approach 3 (Partial-partial)
Summary
4. Mapping of N-ary Relationship
5. Mapping of Unary Relationship
ุจุนู ููุง ูู ููุณ ุงูู Table ูุฃุฒูุฏ FK ูููุง ุจูุดุงูุฑ ุนูู PK ุฏุง ูู ุญุงูุฉ ุงูู 1:M
ูู ุญุงูุฉ ุงูู M:N ุจูุนู ู Table ุฌุฏูุฏุฉ ุจูุจูุง ูููุง ุงุชููู FK ุจูุดุงูุฑูุง ุนูู ููุณ ุงูู PK ุงูุญูุงุฑ ุฏุง ุงุณู ู Junction Table
Junction Table
ุงูู Junction Table ุจุจุณุงุทุฉ ูู ุฌุฏูู ุจูุนู ูู ูู ููุงุนุฏ ุงูุจูุงูุงุช ุนูุดุงู ููุฏุฑ ููุตู ุจูู ุฌุฏูููู ุนูุฏูู ุนูุงูุฉ Many-to-Many. ุทูุจ ููู ุจูุญุชุงุฌูุ ูุฃู ูุงุนุฏุฉ ุงูุจูุงูุงุช ู ุง ุชูุฏุฑุด ุชุนู ู ุงูุนูุงูุฉ ุฏู ู ุจุงุดุฑุฉุ ููุงุฒู ูุนู ู ุฌุฏูู ุซุงูุซ ููุตู ุจูููู .
ุทูุจ ูุงุฎุฏ ู ุซุงู ุจุณูุทุ
ุฎูููุง ูููู ุฅู ุนูุฏูุง ูุงุนุฏุฉ ุจูุงูุงุช ููู ุฏุฑุณุฉุ ูุนูุฏูุง ุฌุฏูููู ุฑุฆูุณููู:
- ุฌุฏูู Students (ุงูุทูุงุจ)ุ ููู ุจูุงูุงุช ุนู ูู ุทุงูุจ ุฒู ุงุณู ู ูุฑูู ุงูุทุงูุจ.
- ุฌุฏูู Courses (ุงูู ูุงุฏ)ุ ููู ุจูุงูุงุช ุนู ูู ู ุงุฏุฉ ุฒู ุงุณู ุงูู ุงุฏุฉ ูุฑูู ุงูู ุงุฏุฉ.
ุทูุจ ุงูู ุดููุฉ ููุง ุฅู ุงูุทุงูุจ ุงููุงุญุฏ ู ู ูู ูุงุฎุฏ ุฃูุชุฑ ู ู ู ุงุฏุฉุ ูุงูู ุงุฏุฉ ุงููุงุญุฏุฉ ู ู ูู ูููู ูููุง ุฃูุชุฑ ู ู ุทุงูุจ. ูุนูู ุนูุฏูุง ุนูุงูุฉ Many-to-Many.
ูุญู ุงูู ุดููุฉ ุฅุฒุงูุ
ุจูุนู ู ุฌุฏูู ุฌุฏูุฏ ูุณู ูู Students_Coursesุ ูุฏู ูู ุงูู Junction Table ุงููู ูููุตู ุจูู Students ูCourses.
ูู ุงูุฌุฏูู ุฏู ุจูุญุท:
- ุงูู
student_id
: ุฏู ุฒู ุงูู ูุชุงุญ ุงููู ุจูุฑุจุทูุง ุจุฌุฏูู Students. - ุงูู
course_id
: ุฏู ุงูู ูุชุงุญ ุงููู ุจูุฑุจุทูุง ุจุฌุฏูู Courses.
ุดูู ุงูุจูุงูุงุช ูู ุงูุฌุฏูู
ูุชุจูู ุจุงูุดูู ุฏู:
student_id | course_id |
---|---|
1 | 101 |
1 | 102 |
2 | 101 |
3 | 103 |