<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shanikayodhagama on Medium]]></title>
        <description><![CDATA[Stories by Shanikayodhagama on Medium]]></description>
        <link>https://medium.com/@shanikayodhagama?source=rss-ce02159af780------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LMPdbIYn7SGtTm0GHMyktA.jpeg</url>
            <title>Stories by Shanikayodhagama on Medium</title>
            <link>https://medium.com/@shanikayodhagama?source=rss-ce02159af780------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 14:07:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shanikayodhagama/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ER to Relational Mapping]]></title>
            <link>https://medium.com/@shanikayodhagama/er-to-relational-mapping-a818b35182d5?source=rss-ce02159af780------2</link>
            <guid isPermaLink="false">https://medium.com/p/a818b35182d5</guid>
            <category><![CDATA[er-diagram]]></category>
            <category><![CDATA[schema]]></category>
            <dc:creator><![CDATA[Shanikayodhagama]]></dc:creator>
            <pubDate>Wed, 24 Aug 2022 02:07:49 GMT</pubDate>
            <atom:updated>2022-08-24T02:07:49.222Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*x6G35nRmdjvaaN-R_RyDUA.png" /></figure><p>I know that you have a better understanding about how to model an Entity-Relationship (ER) diagram and you are curious to know about how to design a relational database schema for your ER model. Well, this is the best time for it!</p><p>Here I’m going to introduce seven steps to design a database schema. Before that let me explain about strong entity sets and weak entity sets in an ER model</p><p><strong>Weak Entity.</strong></p><p>Weak entity set is an entity set that does not have primary key. The existence of a weak entity set depends on the existence of the <strong>identifying </strong>entity set. The discriminator (or partial key) of a weak entity set is the set of attributes that distinguishes among all of a weak entity set. Normally, we represent the discriminator in ER model by underling with a dashed line. As well as you can easily identify the weak entity set using double diamond.</p><p>Ex: a room can only exists with a hotel</p><figure><img alt="1.1" src="https://cdn-images-1.medium.com/max/904/1*Oijmj4U1dLemqMBi6eiNGg.png" /><figcaption>Diagram 1.1</figcaption></figure><p>All other entity sets except the weak entity sets, we can consider as strong entity sets in your ER model.</p><p>To explain all the things, I use below ER diagram which is relevant to car insurance company.</p><p>Strong entities: <strong>Customer, Car, Policy,Options,Claim</strong></p><p>Weak entity: <strong>Accident</strong></p><p><em>Example ER Diagram</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*hwV3k4AdJxY8JGppr9DNrg.png" /><figcaption>ER diagram for car insurance company</figcaption></figure><p>Let’s start!✌</p><p><strong>Step 1: strong entity sets</strong></p><p>For each strong entity sets in your ER model, create a corresponding relation(table) that includes all the simple attributes of the entity set. Then, choose one of the key attributes (or set of attributes) as the primary key.</p><p>For composite attributes, include the simple components as attributes.</p><p>Example: <em>For the name attribute in </em><strong><em>Customer</em></strong><em> relation, we can put (first name, last name) separately.</em></p><p>If there are multi valued attributes, do not include them into the relation for the first step.(Note: I have explained it in the 5th step.)</p><p>Example: <em>Phone_no</em> attribute in the <strong>customer</strong> relation</p><p><strong>Step 2: weak entity sets</strong></p><p>Add all the primary key attributes of the <strong>identifying entity set</strong> to the weak entity relation as foreign keys and keep simple attributes of weak relation as it is. So, the primary key of weak entity relation is the combination of all the primary key attributes from the identifying entity set and partial key of the weak entity.</p><p><em>Example</em> :</p><p><strong>Car </strong>and <strong>Accident</strong> entity sets have weak relationship. Since this ER model related to insurance company if there is no car there will not be accidents. here, Car is the identifying entity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*vbSK_kUj46xpYtTomNLUIQ.png" /></figure><p>In the database schema, we represent as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/463/1*EXxCIVuuZUU1NfIK9_qvHQ.png" /></figure><p><strong>Step 3: Binary 1:1 relationship</strong></p><p>If your ER model has relation that has binary 1:1 (one to one) relationship, first you look the participation in both sides.</p><p><strong>I)</strong> If the two entity sets have partial participation or total participation in both side ,simply you can choose any of the relation and put primary key of other entity set as foreign key.</p><p><em>Example</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*JBgtn-hsNDlAkdIZmJmgyg.png" /></figure><p>Here, I selected <strong>Car</strong> relation and <em>policy_no</em> added to the <strong>Car </strong>relation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*XhUJ1k0A1Lmouo8P89YdWw.png" /></figure><ul><li>Alternative approach</li></ul><p>You can merge the two entity types and the relationship into a single relation. This is possible when the both participation are total. Remember that!</p><p><em>Example</em>:</p><p>You can put above Policy and Car entities into a single entity as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/181/1*OnVuSdMsNmDtKUROP1kdOw.png" /></figure><p><strong>II)</strong> If you have total participation in one side and partial participation in other side, choose the relation which is in total participation side and put primary key of other entity set as foreign key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*nyEiXXABH_8l3QXUv4llRg.png" /></figure><p><strong>Accident</strong> relation has the total participation. so, we can create schema like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*x656gfI1tD28mTF9RQtyxQ.png" /></figure><p><strong>Step 4: binary 1: N relationship</strong></p><p>For each binary 1: N (one to many) relationship, identify the relation that represent the entity type at the <em>N side.</em> Then include the primary key of the relation which is in <em>1 side</em> to the entity type at the <em>N side </em>as a foreign key. Keep all other attributes of the relation which is in <em>N side</em> as it is.</p><p><em>Example</em>:</p><p><strong>Car &amp; Custome</strong>r relations has 1: N (one to many) relationship.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*U1ysA9Xlrbmfd4y071fVUw.png" /></figure><p>So, the entity which is in<em> N side</em> is <strong>Car.</strong>So<strong>, </strong>we add the primary key of<strong> Customer</strong> relation to the<strong> Car </strong>relation as foreign key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*8GUwiUwgJ1tOZV3jSCumOg.png" /></figure><p><strong>Step 5: Binary M: N relationship</strong></p><p>If there is M: N (Many to many) relationship in your ER model, for each relationship you should create a new relation and include all the primary keys of relation that represent the participating entity sets, as foreign keys on new relation. The combination of the foreign keys forms the primary key of new relation.</p><p><em>Example:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*CZuucu7v_PbMo5xWx2a2xA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*Y1Vd28fSWE6rs_Yo-guOKA.png" /></figure><p><strong>Policy &amp; Options</strong> relations has M: N (many to many) relationship. Therefore, we should create a new relation call <strong>Includes</strong>.</p><p><strong>Step 6: Multi-valued attributes</strong></p><p>For each multi-valued attribute, create a new relation then add an attribute corresponding to multi-valued attribute values. And add the primary key of the corresponding relation where the multi-valued attribute was, to the new table as foreign key. So, the primary key of new table is the combination of foreign key and other attribute.</p><p><em>Example</em>:</p><p>There is a multi-valued attribute in <strong>Customer </strong>entity set (Note: in the first step I did not add phone number attribute to the customer relation). So, create a new relation call <strong>Phone_numbers</strong> and included <em>customer_id </em>attribute as foreign key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*KRz1sVzaUR3QFjr07UNjAQ.png" /></figure><p><strong>Step 7: Mapping <em>N-ary relationships</em></strong></p><p>For each n -ary relationship, you can create a new relation to represent their relationship. Then, include the primary keys of relations that represent the participating entity sets as foreign keys. Further if your relationship has simple attributes, include them also into the new relation. the primary key of new relation is usually a combination of all the foreign keys.</p><p><em>Example</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*b7iPCC9oZZdLU6RiPiTa2Q.png" /></figure><p>In the above ER model you can see the relationship( Supply) also has a attribute and you have three relations( Project, item,supplier). you can create a new relation in your schema as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/181/1*avdauCrVxUAA6Q3TNlHpUQ.png" /></figure><p>However, if the cardinality constraints on any of the participating entity set is 1, then their foreign key is not needed in the primary key of your new relation.</p><p><em>Example:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*hlKBavX8tFYv5is8mdMeJA.png" /></figure><p>you can see, there are one to many and many to many relationships in above n-ary ER model. we can put it in the schema as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/181/1*gnXYUVcu42DcioKlTKph5w.png" /></figure><p>Finally, if you correctly follow all of the things, your final schema diagram for car insurance company, would be like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*jHn_vVOUkl803QY626ZEMg.png" /><figcaption>Schema diagram for a car insurance company.</figcaption></figure><p>That’s how we map ER diagrams into relational schema. 😍</p><p><strong>Hope you got the idea!</strong></p><p>Thanks for reading!😍</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a818b35182d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>