{"componentChunkName":"component---src-templates-post-template-js","path":"/211016-database-relation-design/","result":{"data":{"allMarkdownRemark":{"edges":[{"node":{"id":"17e4d2df-df95-529f-b102-720d1dcd4f8b","html":"<h1>ER-to-Relational Mapping</h1>\n<br />\n<p><strong>An ER Schema for COMPANY</strong></p>\n<br />\n<div style=\"text-align: center\">\n       <span class=\"gatsby-resp-image-wrapper\" style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \">\n      <a class=\"gatsby-resp-image-link\" href=\"/static/e4029aa76d889e6ea962f69b76147429/2637b/ER_COMPANY.png\" style=\"display: block\" target=\"_blank\" rel=\"noopener\">\n    <span class=\"gatsby-resp-image-background-image\" style=\"padding-bottom: 88.54166666666666%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAASCAYAAABb0P4QAAAACXBIWXMAABYlAAAWJQFJUiTwAAACbElEQVQ4y32UiY7aQBBE/f8/FoUlSsRqCWsWfODxfd8cpqJqsGUIiaXR2G3P666uGWtBEMDzPMRxDMdxkOe5zFVVYbyu16sM3Ge5n8XnQwvDEL7vI4oiHA4HARuGIWC+K4oCz9cc+hzXCLNtG03TCOR4PCJNU6nQskxkWYbz+Yw8S1CkCfq+nwDDMEghlmVNiTUC6rpG27YCYxYu6rpOoIS7zgH7zzXs3RaObUr8crkITCklSghlcm3MxiqSJJFBCJOUZTklaeoKZZ7JMxNyMVtEGBNQJduljb1g+ev1B97eFvj4eBf5Y18J56IgCCXONjGx67lYrX5huXzDp76RqrW5Q5R5Op0EMGZmjM9pEiNLYvR999Dv8/mEIs8EJqbMgfxglE9ZlE4gQXv9Nwx9gyjwUDeNfMfk5m4rcdexReXUQ2YYgeNMKN3jwtOxR13e7ofrVWRTQds0CDyFvutuLhPEigi5DMMNPgzyzMV0n9AoDBF6CoE6wHPpbISiyBEEPnRdRxxHwtHYDzafrnVtizxN0LWNOJbc92OeZdInZRlQ1h6B5yLPC1ljmgYMcy9AFjBJztIUxnYDg7360qf+5WmMLPJly7AFVFRWlRxPApumFdMYF8kPLrfN/TR0KIviZsR2A8f8gvX1iYO5kxZwB+x2O3Ga7XBdV+IPwOk8zkyifF/ZSHyF0HVQV6U4ycF+vTrP2r/+HONFc3j0+v74lBIv12nzF8+XUg6WPxb4vviG1ftPJEn8X5hUOIdxphS6RQO411xXCZgztwl3Bc2aS54X8xeQP1v+QXhWed+23RQry0rOtmma4I/5FfAPAwlocnNXhk8AAAAASUVORK5CYII='); background-size: cover; display: block;\"></span>\n  <picture>\n          <source srcset=\"/static/e4029aa76d889e6ea962f69b76147429/a59e9/ER_COMPANY.webp 192w,\n/static/e4029aa76d889e6ea962f69b76147429/0ca9f/ER_COMPANY.webp 384w,\n/static/e4029aa76d889e6ea962f69b76147429/dc9b9/ER_COMPANY.webp 768w,\n/static/e4029aa76d889e6ea962f69b76147429/e2c2f/ER_COMPANY.webp 1152w,\n/static/e4029aa76d889e6ea962f69b76147429/35ff6/ER_COMPANY.webp 1356w\" sizes=\"(max-width: 768px) 100vw, 768px\" type=\"image/webp\">\n          <source srcset=\"/static/e4029aa76d889e6ea962f69b76147429/3b721/ER_COMPANY.png 192w,\n/static/e4029aa76d889e6ea962f69b76147429/66595/ER_COMPANY.png 384w,\n/static/e4029aa76d889e6ea962f69b76147429/fe486/ER_COMPANY.png 768w,\n/static/e4029aa76d889e6ea962f69b76147429/d2d74/ER_COMPANY.png 1152w,\n/static/e4029aa76d889e6ea962f69b76147429/2637b/ER_COMPANY.png 1356w\" sizes=\"(max-width: 768px) 100vw, 768px\" type=\"image/png\">\n          <img class=\"gatsby-resp-image-image\" src=\"/static/e4029aa76d889e6ea962f69b76147429/fe486/ER_COMPANY.png\" alt=\"ER COMPANY\" title=\"ER COMPANY\" loading=\"lazy\" decoding=\"async\" style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\">\n        </picture>\n  </a>\n    </span>\n</div>\n<br />\n<br />\n<br />\n<p><strong>The Relational Schema for COMPANY</strong></p>\n<br />\n<div style=\"text-align: center\">\n       <span class=\"gatsby-resp-image-wrapper\" style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \">\n      <a class=\"gatsby-resp-image-link\" href=\"/static/eee27e7c638afd39be042b6b4faf85d2/b5cb9/Relational_COMPANY.png\" style=\"display: block\" target=\"_blank\" rel=\"noopener\">\n    <span class=\"gatsby-resp-image-background-image\" style=\"padding-bottom: 72.91666666666666%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAPCAYAAADkmO9VAAAACXBIWXMAABYlAAAWJQFJUiTwAAABtUlEQVQ4y42UB4tCQQyE3///VYJiRcHeuyL23kuObyDyuEO5hSG7bnaSSfIMyuWyZbNZ63Q6djwebb/f2+FwsPP5rPN2u9UZy51jt9vpd/d3BI1GwyDFVqtV7SuVikWjUcvn8zq3220rFovycfi5UCjIv1aryQZEWK/XtlqtzNfr9bJ6vW7j8VhRud9sNrZcLm2xWCi72+1ml8tFSu73u95wDpLJpEUiEYvH44rW6/UUmaw841KpZP1+3x6Px7sMHhj4EiGRcZhOpxaLxazVaokUgjDm87kIT6eT1JDh9XoVIPJsg2azqWyoQTqdtuFwKEk4QADYQ+CySOD5fL7vHdwHyEkkEmpAKpVSx6kVDr6oEYS+p66fliQjl3SJwEMehVeYEEsjwzUMIyArRgTpZIt8OkwJut2uGjMajd4Z/yb8k6EPLaMBCcVnNADFn0wmNpvN/k9IVxkTZNNBAlD4Twv5XwlzuZyBTCajxmCRDSmPwyBLas0UfCT0uUI2zj5TPGY0eOQW+HB/JGSY+VKwNIPsAPM4GAy05xPkzwMw5F8lU3Qe0lGaAikd5wwB9WXPb373jfAH6qpv84ItewcAAAAASUVORK5CYII='); background-size: cover; display: block;\"></span>\n  <picture>\n          <source srcset=\"/static/eee27e7c638afd39be042b6b4faf85d2/a59e9/Relational_COMPANY.webp 192w,\n/static/eee27e7c638afd39be042b6b4faf85d2/0ca9f/Relational_COMPANY.webp 384w,\n/static/eee27e7c638afd39be042b6b4faf85d2/dc9b9/Relational_COMPANY.webp 768w,\n/static/eee27e7c638afd39be042b6b4faf85d2/e2c2f/Relational_COMPANY.webp 1152w,\n/static/eee27e7c638afd39be042b6b4faf85d2/aa71c/Relational_COMPANY.webp 1532w\" sizes=\"(max-width: 768px) 100vw, 768px\" type=\"image/webp\">\n          <source srcset=\"/static/eee27e7c638afd39be042b6b4faf85d2/3b721/Relational_COMPANY.png 192w,\n/static/eee27e7c638afd39be042b6b4faf85d2/66595/Relational_COMPANY.png 384w,\n/static/eee27e7c638afd39be042b6b4faf85d2/fe486/Relational_COMPANY.png 768w,\n/static/eee27e7c638afd39be042b6b4faf85d2/d2d74/Relational_COMPANY.png 1152w,\n/static/eee27e7c638afd39be042b6b4faf85d2/b5cb9/Relational_COMPANY.png 1532w\" sizes=\"(max-width: 768px) 100vw, 768px\" type=\"image/png\">\n          <img class=\"gatsby-resp-image-image\" src=\"/static/eee27e7c638afd39be042b6b4faf85d2/fe486/Relational_COMPANY.png\" alt=\"Relational COMPANY\" title=\"Relational COMPANY\" loading=\"lazy\" decoding=\"async\" style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\">\n        </picture>\n  </a>\n    </span>\n</div>\n<br />\n<br />\n<p><strong>1. 모든 정보(모든 Attribute 포함)을 보존한다.</strong></p>\n<p><strong>2. 가능한 한 제약을 유지한다.</strong></p>\n<p>• 관계형 모델에서는 모든 제약 조건을 유지할 수 없다.</p>\n<p>• ex) ER에서 1:10과 같은 최대 cardinality ratio</p>\n<p><strong>3. null 값을 최소화한다.</strong></p>\n<p>• 가능한 한 구체적으로 한다.</p>\n<p>• 이것은 Logical Schema에서 Physical Schema로의 Mapping을 돕는다.</p>\n<h2>Step1: Mapping of Regular Entity Types</h2>\n<ul>\n<li>\n<p>ER Schema의 각 강력한 <strong>Entity Type E</strong>에 대해 E의 모든 Attribute을 포함하는 <strong>Relation R</strong>을 만든다.</p>\n</li>\n<li>\n<p>E의 Key Attribute 중 하나를 R의 <strong>Primary Key</strong>로 선택한다.</p>\n</li>\n<li>\n<p>E의 선택된 Key가 Composite(합성)인 경우 Key에 대해 선택된 단순 Attribute Set은 함께 R의 PK가 된다.E</p>\n</li>\n</ul>\n<h2>Step2: Mapping of Weak Entity Types</h2>\n<ul>\n<li>\n<p>Entity Type E가 있는 ER Schema의 각 Weak Entity Type W에 대해, Relation R을 만들고 W의 Attribute을 R의 Attribute로 포함한다.</p>\n</li>\n<li>\n<p>Entity Type에 해당하는 Relation의 <strong>PK Attribute</strong>을 R의 <strong>Foreign Key (FK) Attribute</strong>로 포함한다.</p>\n</li>\n<li>\n<p><strong>R의 PK는 부모의 PK와 Weak Entity W의 partial key (있는 경우)의 조합이다.</strong></p>\n<ul>\n<li>ex) The DEPENDENT relation PK: <strong>{Essn, Dependent_name}</strong></li>\n</ul>\n</li>\n</ul>\n<h2>Step 3: Mapping of Binary 1:1 Relationship Types</h2>\n<ul>\n<li>\n<p>ER Schema의 각 <strong>Binary 1:1 Relation Type R</strong>에 대해 참여하는 Entity Type에 해댱하는 <strong>Reltaion S 및 T를 식별한다.</strong></p>\n<p><strong>1. Foreign key approach (2 relations) option:</strong></p>\n<ul>\n<li>\n<p>Relation 중 하나를 선택한다. (S)</p>\n</li>\n<li>\n<p>S의 경우 R에 <strong>전체 참여가 있는 Entity 유형</strong>을 선택하는 것이 좋다.</p>\n</li>\n<li>\n<p><strong>T의 PK를 S의 FK로 포함한다.</strong></p>\n</li>\n<li>\n<p>ex) ER Schema의 MANAGES 관계 유형</p>\n<ul>\n<li>\n<p><strong>Relation S</strong> : DEPARTMENT entity type (총 참여로 인해)</p>\n</li>\n<li>\n<p><strong>Relation T</strong> : EMPLOYEE entity type</p>\n<ul>\n<li>\n<p>The <strong>FK</strong> of <strong>S</strong> (ex. the DEPARTMENT relation):</p>\n</li>\n<li>\n<p>Mgr_Ssn <strong>←</strong> The <strong>PK</strong> (ex. Ssn) of <strong>T</strong> (ex. the EMPLOYEE relation)</p>\n</li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n<p><strong>2. Merged relation (1 relation) option:</strong></p>\n<ul>\n<li>두 Relation을 하나로 합친다. 이는 두 참여가 모두 total일 경우 적합하다.</li>\n</ul>\n<br />\n<p><strong>3. Cross-reference or relationship relation (3 relations) option:</strong></p>\n<ul>\n<li>\n<p>Entity Type을 나타내는 두 Relation S 및 T의 PK를 상호 참조할 목적으로 <strong>세 번째 Relation U를 설정한다.</strong></p>\n</li>\n<li>\n<p><strong>U의 PK는 S와 T의 FK 중 하나이다. 다른 FK는 U의 unique key가 된다.</strong></p>\n</li>\n</ul>\n</li>\n</ul>\n<h2>Step 4: Mapping of Binary 1:N Relationship Types</h2>\n<ul>\n<li>\n<p>각 일반 Binary 1:N Relation Type R에 대해 N-side에 참여하는 Entity Type을 나타내는 <strong>Relation S</strong>를 식별한다.</p>\n</li>\n<li>\n<p>Relation T(R에 참여하는 다른 Entity Type)의 PK를 S에 FK에 포함한다.</p>\n</li>\n<li>\n<p><strong>1:N Relation Type</strong>의 모든 simple attribute을 S의 attribute로 포함한다.</p>\n</li>\n<li>\n<p>ex) The <strong>WORKS_FOR</strong> relationship type in the ER schema</p>\n<ul>\n<li>\n<p><strong>Relation S</strong>: The EMPLOYEE entity type (N-side)</p>\n</li>\n<li>\n<p><strong>Relation T</strong> : The DEPARTMENT entity type (1-side)</p>\n</li>\n<li>\n<p><strong>The FK (Dno) of S</strong>: borrowed from the PK, Dnumber of T</p>\n</li>\n</ul>\n</li>\n</ul>\n<h2>Step 5: Mapping of Binary M:N Relationship Types</h2>\n<ul>\n<li>\n<p>각 일반 <strong>Binary M:N Relation Type R</strong>에 대해 <strong>Relationship Relation</strong>이라 하는 새 <strong>Relation U</strong>를 생성하여 R을 나타낸다.</p>\n</li>\n<li>\n<p>참여 Entity type을 나타내는 Reltion의 PK를 U에 FK Attribute로 포함한다. 그 것들의 조합은 <strong>U의 PK를 형성한다.</strong></p>\n</li>\n<li>\n<p><strong>M:N Relation Type의 모든 simple attribute을 U의 Attribute로 포함한다.</strong></p>\n</li>\n<li>\n<p>ex) The <strong>WORKS_ON</strong> relationship type in ER</p>\n<ul>\n<li>\n<p><strong>Relation U</strong> : The WORKS_ON relationship type</p>\n</li>\n<li>\n<p><strong>FKs</strong> (Essn and Pno) : EMPLOYEE 및 PROJECT Relation의 PK(Ssn 및 Pnumber)에서 각각 차용</p>\n</li>\n<li>\n<p><strong>PK</strong> : {Essn, Pno}</p>\n</li>\n<li>\n<p>One attribute : Hours, from Hours of WORKS_ON</p>\n</li>\n</ul>\n</li>\n</ul>\n<h2>Step6: Mapping of Multi valued Attributes</h2>\n<ul>\n<li>\n<p>각 <strong>multivalued attribute A에</strong> 대해 새 <strong>Relation U</strong>를 만든다.</p>\n</li>\n<li>\n<p>Relation U에는 다음이 포함된다.</p>\n<ul>\n<li>\n<p>A에 해당하는 Attribute</p>\n</li>\n<li>\n<p><strong>FK</strong>, 예를들어 K 또는 A를 Attribute를 소유하는 <strong>Entity Type의 PK</strong> (PK: {A, K})</p>\n</li>\n</ul>\n</li>\n<li>\n<p>ex) The <strong>Locations</strong> multi-valued attribute of Department</p>\n<ul>\n<li>\n<p><strong>Relation U</strong>: the <strong>DEPT_LOCATIONS</strong> relation</p>\n</li>\n<li>\n<p><strong>A</strong>: <strong>Dlocation</strong>, from <strong>Locations of the DEPARTMENT</strong> entity type</p>\n</li>\n<li>\n<p><strong>FK</strong>: <strong>Dnumber</strong>, from the <strong>PK of the DEPARTMENT</strong> entity type</p>\n</li>\n<li>\n<p><strong>PK</strong>: {Dlocation, Dnumber}</p>\n</li>\n</ul>\n</li>\n</ul>\n<h2>Step 7: Mapping of N-ary Relationship Types</h2>\n<ul>\n<li>\n<p><strong>n > 2인 각 n-ary Relation Type R</strong>에 대해 새 <strong>Relationship Relation U</strong>를 생성하여 R을 나타낸다.</p>\n</li>\n<li>\n<p>참여하는 Entity Type을 나타내는 Relation의 <strong>PK</strong>를 U에 <strong>FK</strong> Attribute로 포함한다.</p>\n</li>\n<li>\n<p>n-ary Relation Type의 모든 simple attribute을 U의 Attribute로 포함한다.</p>\n</li>\n<li>\n<p>ex)</p>\n<ul>\n<li>\n<p><strong>Relation U</strong> : The <strong>SUPPLY</strong> relation</p>\n</li>\n<li>\n<p><strong>PKs/FKs</strong> : {Sname, Partno, ProjName}</p>\n</li>\n<li>\n<p><strong>The other attribute</strong> : <strong>Quantity</strong></p>\n</li>\n</ul>\n</li>\n</ul>\n<h2>ER과 Relational Model 간의 대응</h2>\n<div style=\"text-align: center\">\n  <span class=\"gatsby-resp-image-wrapper\" style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \">\n      <a class=\"gatsby-resp-image-link\" href=\"/static/aaaeab9736abc584de3fef202d7b3ae4/f97d7/CorrespondenceERtoRelational.png\" style=\"display: block\" target=\"_blank\" rel=\"noopener\">\n    <span class=\"gatsby-resp-image-background-image\" style=\"padding-bottom: 47.39583333333333%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAABYlAAAWJQFJUiTwAAABMElEQVQoz12Ri46CUAxE+f//M6IBBBHiAxAUBUSdzWnSDbtNmvtqpzNzgzRNFYahNpuNPp+PPN7vt+Z51vP51Hq91na71Wq1Up7nOh6P9v4/vt+vgqZpVFWViqJQWZa6XC46nU62v9/vut1u2u/3BkRSf71edT6frRZwVoYTAQ+Hw8GKkyRRHMd27rpO4zgawyiKtNvtlGWZgVNDPepI7xmGQUHbtjaFC4phBlvAyL7vrQkA3qglUVXXtamhl7NJhiHMAIEFzHh4PB4GhmRnwxveMWiaJmOPLex/PWQClAEj+SA8er1eJsEZwgLpDOeDuHO/Af0DiDdQphnTYef+LQHZ0wxTB1n+sH0KU9w7QDyWzTCnBvncowDvWQFaZgCIS2NdTvPg3tMHoQIFXusMfwBbVKrkzA+GmQAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"></span>\n  <picture>\n          <source srcset=\"/static/aaaeab9736abc584de3fef202d7b3ae4/a59e9/CorrespondenceERtoRelational.webp 192w,\n/static/aaaeab9736abc584de3fef202d7b3ae4/0ca9f/CorrespondenceERtoRelational.webp 384w,\n/static/aaaeab9736abc584de3fef202d7b3ae4/dc9b9/CorrespondenceERtoRelational.webp 768w,\n/static/aaaeab9736abc584de3fef202d7b3ae4/e2c2f/CorrespondenceERtoRelational.webp 1152w,\n/static/aaaeab9736abc584de3fef202d7b3ae4/f3efb/CorrespondenceERtoRelational.webp 1536w,\n/static/aaaeab9736abc584de3fef202d7b3ae4/fab06/CorrespondenceERtoRelational.webp 2000w\" sizes=\"(max-width: 768px) 100vw, 768px\" type=\"image/webp\">\n          <source srcset=\"/static/aaaeab9736abc584de3fef202d7b3ae4/3b721/CorrespondenceERtoRelational.png 192w,\n/static/aaaeab9736abc584de3fef202d7b3ae4/66595/CorrespondenceERtoRelational.png 384w,\n/static/aaaeab9736abc584de3fef202d7b3ae4/fe486/CorrespondenceERtoRelational.png 768w,\n/static/aaaeab9736abc584de3fef202d7b3ae4/d2d74/CorrespondenceERtoRelational.png 1152w,\n/static/aaaeab9736abc584de3fef202d7b3ae4/e8464/CorrespondenceERtoRelational.png 1536w,\n/static/aaaeab9736abc584de3fef202d7b3ae4/f97d7/CorrespondenceERtoRelational.png 2000w\" sizes=\"(max-width: 768px) 100vw, 768px\" type=\"image/png\">\n          <img class=\"gatsby-resp-image-image\" src=\"/static/aaaeab9736abc584de3fef202d7b3ae4/fe486/CorrespondenceERtoRelational.png\" alt=\"CorrespondenceERtoRelational\" title=\"CorrespondenceERtoRelational\" loading=\"lazy\" decoding=\"async\" style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\">\n        </picture>\n  </a>\n    </span>\n</div>","frontmatter":{"title":"[Database] Relation Database Design","date":"2021.10.16.","category":"Data Science","categoryColor":"seagreen","tags":["DB"]}}}]}},"pageContext":{"slug":"/211016-database-relation-design/","next":{"frontmatter":{"title":"[Database] Relational Model"},"fields":{"slug":"/211016-database-relational-model/"}},"previous":{"frontmatter":{"title":"[SQL] Basic SQL (1) - CREATE, SELECT"},"fields":{"slug":"/211017-sql-basic-1/"}}}},"staticQueryHashes":[]}