ER Model To Relational Database
ER Model To Relational Database
E-commerce Application
Customer has only one cart. A cart belongs to only one customer
Customer can save multiple addresses in the application for further use like selecting delivery address
Primary key: A minimal set of attributes (columns) in a table that uniquely identifies rows in a table.
In the following tables, all the ids are primary keys as they uniquely identify each row in the table.
https://learning.ccbp.in/course?c_id=5d03f5a4-a285-4e52-8a57-18f718c4859f&t_id=514fa3b0-52eb-4e67-8e4f-21ac0618d716&s_id=c99aefb6-a4… 1/5
10/18/24, 8:02 AM Revolutionizing the Job Market | NxtWave
Relationships
We store the primary key of a customer in the address table to denote that the addresses are related to a particular customer.
This new column/s in the table that refer to the primary key of another table is called Foreign Key.
https://learning.ccbp.in/course?c_id=5d03f5a4-a285-4e52-8a57-18f718c4859f&t_id=514fa3b0-52eb-4e67-8e4f-21ac0618d716&s_id=c99aefb6-a4… 2/5
10/18/24, 8:02 AM Revolutionizing the Job Market | NxtWave
Here,
This is similar to one-to-many relationship. But, we need to ensure that only one cart is associated to a customer
Here, we cannot store either the primary key of a product in the cart table or vice versa.
To store the relationship between the cart and product tables, we use a Junction Table.
https://learning.ccbp.in/course?c_id=5d03f5a4-a285-4e52-8a57-18f718c4859f&t_id=514fa3b0-52eb-4e67-8e4f-21ac0618d716&s_id=c99aefb6-a4… 3/5
10/18/24, 8:02 AM Revolutionizing the Job Market | NxtWave
Note
We store the properties related to a many-to-many relationship in the junction table. For example, quantity of each product in the
cart should be stored in the junction table cart_product
ER Model
Relational Database
https://learning.ccbp.in/course?c_id=5d03f5a4-a285-4e52-8a57-18f718c4859f&t_id=514fa3b0-52eb-4e67-8e4f-21ac0618d716&s_id=c99aefb6-a4… 4/5
10/18/24, 8:02 AM Revolutionizing the Job Market | NxtWave
https://learning.ccbp.in/course?c_id=5d03f5a4-a285-4e52-8a57-18f718c4859f&t_id=514fa3b0-52eb-4e67-8e4f-21ac0618d716&s_id=c99aefb6-a4… 5/5