{"id":4887,"date":"2021-08-02T06:33:59","date_gmt":"2021-08-02T06:33:59","guid":{"rendered":"https:\/\/www.aiproblog.com\/index.php\/2021\/08\/02\/key-attributes-in-er-diagrams\/"},"modified":"2021-08-02T06:33:59","modified_gmt":"2021-08-02T06:33:59","slug":"key-attributes-in-er-diagrams","status":"publish","type":"post","link":"https:\/\/www.aiproblog.com\/index.php\/2021\/08\/02\/key-attributes-in-er-diagrams\/","title":{"rendered":"Key Attributes in ER Diagrams"},"content":{"rendered":"<p>Author: Stephanie Glen<\/p>\n<div>\n<ul>\n<li>\n<a href=\"https:\/\/storage.ning.com\/topology\/rest\/1.0\/file\/get\/9340309254?profile=original\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/storage.ning.com\/topology\/rest\/1.0\/file\/get\/9340309254?profile=RESIZE_710x\" class=\"align-full\"><\/a>Overview of different types of keys used in E-R diagrams.<\/li>\n<li>How to establish a primary key from a set of alternatives.<\/li>\n<li>Composite, superkey, candidate, primary and alternate keys explained.<\/li>\n<li>Other keys you may come across include foreign and partial keys.<\/li>\n<\/ul>\n<p>If you\u2019re unfamiliar with entities and attributes, you may want to read <a href=\"https:\/\/www.datasciencecentral.com\/profiles\/blogs\/intro-to-the-e-r-diagram\" target=\"_blank\" rel=\"noopener\">Intro to the E-R Diagram<\/a> first.<\/p>\n<p><span>The ER diagram is a way to model a database in an organized and efficient way.\u00a0<\/span>A <strong>key<\/strong> is a way to categorize attributes in an E-R diagram.\u00a0When you first start making E-R diagrams, the number of different choices for keys can be overwhelming. However, the goal of the E-R diagram is to create a simplified &#8220;bird&#8217;s eye&#8221; view of your data. A judicious choice of keys helps to achieve that goal. Although there are many different types of keys to choose from in a set of data, relatively few will actually make it to your finished diagram.<\/p>\n<h2>Composite Keys<\/h2>\n<p>In general, keys can be single-attribute (unary) or multi-attribute (n-ary).\u00a0A <em>composite key<\/em> requires more than one attribute. If a key is composite, like {state,driver license#}, a composite attribute can be made from the separate parts. In the early stages of database design, like E-R diagram creation, entity attributes are often composite or multi-valued. However, these may create problems down the road and need to be handled in specific ways when you translate into an actual database [1].\u00a0<\/p>\n<h2>Superkey, Candidate, Primary and Alternate Key<\/h2>\n<p><strong>\u00a0<\/strong><strong>A superkey<\/strong> of an entity set is an attribute, or set of attributes, with values that uniquely identify each entity in the set. For example, a DMV database might contain the following information:<\/p>\n<p><a href=\"https:\/\/storage.ning.com\/topology\/rest\/1.0\/file\/get\/9340012276?profile=original\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/storage.ning.com\/topology\/rest\/1.0\/file\/get\/9340012276?profile=RESIZE_710x\" class=\"align-full\"><\/a><\/p>\n<p>In this example, <em>{License #}<\/em> is a superkey as it is a unique identifier. {Make,Model,Owner,State,License#,VIN#} and {State,License#,VIN#} are also superkeys. On the other hand, {Owner} or {Make,Model,Owner} are <em>not<\/em> superkeys as these could refer to more than one person [2].<\/p>\n<p><strong>A candidate key is<\/strong> a minimal super key that uniquely identifies an entity. Minimal superkeys have no unnecessary attributes; In other words, superkeys that don\u2019t have subsets that are also superkeys. \u00a0For example, {State,License#} or {VIN} in the above set are possible choices for candidate keys. \u00a0<\/p>\n<p>One you have identified all the candidate keys, choose a <strong>primary key<\/strong>. Each strong entity in an E-R diagram has a primary key. You may have several candidate keys to choose from. In general, choose a simple key over a composite one. In addition, make sure that the primary key has the following properties [3]:<\/p>\n<ol>\n<li>A non-null value for each instance of the entity.<\/li>\n<li>A unique value for each instance of an entity.<\/li>\n<li>A non-changing value for the life of each entity instance.<\/li>\n<\/ol>\n<p>In this example, the best choice to identify a particular car is {VIN}, as it would never change for the lifetime of the vehicle. The first digit of a driver license number will change when a name change occurs, so this does meet the requirements of property 3 above. In addition, {VIN} is the logical choice because it is directly associated with the car. If an ownership change would occur, the VIN would stay the same. <strong>An alternate key<\/strong> is any candidate key not chosen as the primary key. For this example, {State,License#} is an alternate key. A <strong>partial key<\/strong> identifies a weak entity. Weak entities&#8211;those that rely on other entities&#8211;do not have primary keys [4]. Instead, they have a partial key&#8211;<span>one or more attributes that uniquely identify it via an owner entity.<\/span>\u00a0<\/p>\n<p><a href=\"https:\/\/storage.ning.com\/topology\/rest\/1.0\/file\/get\/9340113075?profile=original\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/storage.ning.com\/topology\/rest\/1.0\/file\/get\/9340113075?profile=RESIZE_710x\" class=\"align-full\"><\/a><\/p>\n<p>When the word \u201ckey\u201d is used in an E-R diagram, it usually refers to the primary key for an entity [5]. Show the primary key by underlining the attribute.\u00a0<\/p>\n<p><a href=\"https:\/\/storage.ning.com\/topology\/rest\/1.0\/file\/get\/9340120254?profile=original\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/storage.ning.com\/topology\/rest\/1.0\/file\/get\/9340120254?profile=RESIZE_710x\" class=\"align-full\"><\/a><\/p>\n<p><em>\u00a0<\/em><\/p>\n<p>Dashed underlines indicate partial keys.\u00a0<\/p>\n<p><a href=\"https:\/\/storage.ning.com\/topology\/rest\/1.0\/file\/get\/9340280680?profile=original\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/storage.ning.com\/topology\/rest\/1.0\/file\/get\/9340280680?profile=RESIZE_710x\" class=\"align-full\"><\/a><\/p>\n<\/p>\n<h2>Other Keys You May Come Across<\/h2>\n<p><strong>Foreign keys<\/strong> are not used in E-R models, but they are used in relational databases to indicate an attribute that is the primary key of another table. Foreign keys are used to establish a relationship when both tables have the same attribute [5].<\/p>\n<p>A <strong>secondary key<\/strong> is used strictly for retrieval purposes and accessing records [5]. These keys do not have to be unique and are typically not included in an E-R diagram. The term secondary key is also occasionally used as a synonym for alternate key [6].<\/p>\n<h2>References<\/h2>\n<p>[1] <a href=\"http:\/\/pld.cs.luc.edu\/database\/ER.html\">Entity-Relationship modeling<\/a><\/p>\n<p>[2] <a href=\"https:\/\/cs.gmu.edu\/~jessica\/cs450_f15\/cs450_ER1.pdf\">Relational Model and the Entity-Relationship (ER) Model<\/a><\/p>\n<p>[3] <a href=\"https:\/\/condor.depaul.edu\/gandrus\/240IT\/accesspages\/primary-foreign-keys.htm\">Primary and Foreign Keys<\/a><\/p>\n<p>[4] <a href=\"https:\/\/www.lucidchart.com\/pages\/ER-diagram-symbols-and-meaning\" target=\"_blank\" rel=\"noopener\">Entity-Relationship Diagram Symbols and Notation<\/a><\/p>\n<p>[5] <a href=\"http:\/\/jcsites.juniata.edu\/faculty\/rhodes\/dbms\/ermodel.htm\">The Entity-Relationship Model<\/a><\/p>\n<p><a href=\"https:\/\/www.lucidchart.com\/pages\/ER-diagram-symbols-and-meaning\" target=\"_blank\" rel=\"noopener\"><\/a><\/p>\n<p>[6] <a href=\"http:\/\/carl.sandiego.edu\/itmg320\/lecture_slides\/Database_design__ER_v400309.pptx\" target=\"_blank\" rel=\"noopener\">Database Design ER<\/a><\/p>\n<\/div>\n<p><a href=\"https:\/\/www.datasciencecentral.com\/xn\/detail\/6448529:BlogPost:1060054\">Go to Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Author: Stephanie Glen Overview of different types of keys used in E-R diagrams. How to establish a primary key from a set of alternatives. Composite, [&hellip;] <span class=\"read-more-link\"><a class=\"read-more\" href=\"https:\/\/www.aiproblog.com\/index.php\/2021\/08\/02\/key-attributes-in-er-diagrams\/\">Read More<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":474,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[26],"tags":[],"_links":{"self":[{"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/posts\/4887"}],"collection":[{"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/comments?post=4887"}],"version-history":[{"count":0,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/posts\/4887\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/media\/474"}],"wp:attachment":[{"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/media?parent=4887"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/categories?post=4887"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/tags?post=4887"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}