{"id":1226,"date":"2023-04-13T15:26:42","date_gmt":"2023-04-13T14:26:42","guid":{"rendered":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/?page_id=1226"},"modified":"2023-08-28T10:11:41","modified_gmt":"2023-08-28T09:11:41","slug":"database-design","status":"publish","type":"page","link":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/data-modelling\/database-design\/","title":{"rendered":"Database design"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Entity relationship diagrams<\/h2>\n\n\n\n<p>In entity relationship diagrams the tables are drawn with lines connecting them to show relationships.<\/p>\n\n\n\n<p>They can either be simple, just showing the table name:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"333\" height=\"112\" src=\"https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13152756\/DB11.png\" alt=\"Example of a simple entity relationship diagram from BBC Bitesize\" class=\"wp-image-1230\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13152756\/DB11.png 333w, https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13152756\/DB11-300x101.png 300w\" sizes=\"auto, (max-width: 333px) 100vw, 333px\" \/><figcaption class=\"wp-element-caption\">Example of a simple entity relationship diagram from BBC Bitesize<\/figcaption><\/figure><\/div>\n\n\n<p>Or more complex, listing the attributes within the table:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"400\" height=\"181\" src=\"https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13152825\/DB12.png\" alt=\"Example of a more complex entity relationship diagram from BBC Bitesize \" class=\"wp-image-1231\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13152825\/DB12.png 400w, https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13152825\/DB12-300x136.png 300w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><figcaption class=\"wp-element-caption\">Example of a more complex entity relationship diagram from BBC Bitesize <\/figcaption><\/figure><\/div>\n\n\n<p>In either case, the important part of the design is the line connecting the tables. This represents the type of relationship between them.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">Entity occurrence diagrams<\/h2>\n\n\n\n<p>An entity-occurrence diagram shows the relationship between occurrences of entities. In other words specific entries in a table rather than the table as a whole.<\/p>\n\n\n\n<p>Each table is shown as a tall oval. Each occurrence of an entity is show by a dot and a description.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"296\" height=\"195\" src=\"https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13152944\/DB15.png\" alt=\"Example of an entity occurrence diagram from BBC Bitesize\" class=\"wp-image-1232\" \/><figcaption class=\"wp-element-caption\">Example of an entity occurrence diagram from BBC Bitesize  <\/figcaption><\/figure><\/div>\n\n\n<hr class=\"wp-block-separator has-css-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">One-to-one relationship<\/h2>\n\n\n\n<p>A one-to-one relation occurs when an entity in one table is only ever related to a single entity in another table and vice versa. It can be represented in either of the following ways:<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"511\" height=\"82\" src=\"https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153116\/DB16.png\" alt=\"Example of one-to-one shown as an entity relationship diagram\" class=\"wp-image-1233\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153116\/DB16.png 511w, https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153116\/DB16-300x48.png 300w\" sizes=\"auto, (max-width: 511px) 100vw, 511px\" \/><figcaption class=\"wp-element-caption\"> Example of one-to-one shown as an entity relationship diagram <\/figcaption><\/figure><\/div><\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"666\" height=\"404\" src=\"https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153125\/DB17.png\" alt=\"Example of one-to-one shown as an entity occurrence diagram\" class=\"wp-image-1234\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153125\/DB17.png 666w, https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153125\/DB17-300x182.png 300w\" sizes=\"auto, (max-width: 666px) 100vw, 666px\" \/><figcaption class=\"wp-element-caption\">Example of one-to-one shown as an entity occurrence diagram<\/figcaption><\/figure><\/div><\/div>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">One-to-many relationship<\/h2>\n\n\n\n<p>A one-to-many relation occurs when an entity in one table can be related to multiple entries in another table. It can be represented in either of the following ways:<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"607\" height=\"82\" src=\"https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153252\/DB18.png\" alt=\"Example of one-to-many shown as an entity relationship diagram\" class=\"wp-image-1235\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153252\/DB18.png 607w, https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153252\/DB18-300x41.png 300w\" sizes=\"auto, (max-width: 607px) 100vw, 607px\" \/><figcaption class=\"wp-element-caption\">Example of one-to-many shown as an entity relationship diagram<\/figcaption><\/figure><\/div><\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"695\" height=\"405\" src=\"https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153259\/DB19.png\" alt=\"Example of one-to-many shown as an entity occurrence diagram\" class=\"wp-image-1236\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153259\/DB19.png 695w, https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153259\/DB19-300x175.png 300w\" sizes=\"auto, (max-width: 695px) 100vw, 695px\" \/><figcaption class=\"wp-element-caption\">Example of one-to-many shown as an entity occurrence diagram<\/figcaption><\/figure>\n<\/div>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">Many-to-many relationship<\/h2>\n\n\n\n<p>A many-to-many relation occurs when an entities in one table can be related to multiple entries in another table and vice versa. It can be represented in either of the following ways:<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"607\" height=\"82\" src=\"https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153417\/DB20.png\" alt=\"Example of many-to-many shown as an entity relationship diagram\" class=\"wp-image-1237\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153417\/DB20.png 607w, https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153417\/DB20-300x41.png 300w\" sizes=\"auto, (max-width: 607px) 100vw, 607px\" \/><figcaption class=\"wp-element-caption\">Example of many-to-many shown as an entity relationship diagram<\/figcaption><\/figure><\/div><\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"714\" height=\"402\" src=\"https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153433\/DB21.png\" alt=\"Example of many-to-many shown as an entity occurrence diagram\" class=\"wp-image-1238\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153433\/DB21.png 714w, https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153433\/DB21-300x169.png 300w\" sizes=\"auto, (max-width: 714px) 100vw, 714px\" \/><figcaption class=\"wp-element-caption\">Example of many-to-many shown as an entity occurrence diagram<\/figcaption><\/figure><\/div><\/div>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">Data dictionaries<\/h2>\n\n\n\n<p>Data dictionaries are used to define the structure of a database.<\/p>\n\n\n\n<p>Data dictionaries contain the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The name of each entity.<\/li>\n\n\n\n<li>The name of each attributes for each entity.<\/li>\n\n\n\n<li>The data type of each attribute.<\/li>\n\n\n\n<li>The size of each attribute.<\/li>\n\n\n\n<li>The attributes that will be used as keys.<\/li>\n\n\n\n<li>Any validation of attributes.<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"316\" src=\"https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153535\/DB22-1024x316-1.png\" alt=\"Example data dictionary\" class=\"wp-image-1240\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153535\/DB22-1024x316-1.png 1024w, https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153535\/DB22-1024x316-1-300x93.png 300w, https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153535\/DB22-1024x316-1-768x237.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Example data dictionary<\/figcaption><\/figure><\/div>\n\n\n<hr class=\"wp-block-separator has-css-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">Validation of attributes<\/h2>\n\n\n\n<p>In an RDBMS you can specify that an attribute needs to meet certain criteria to be considered valid. Invalid data will not be accepted and so the insert or update command will be ignored.<\/p>\n\n\n\n<p>The criteria can be:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Presence. Has any data been provided e.g. leaving a field blank.<\/li>\n\n\n\n<li>Length. Limiting the input to a certain number of characters.<\/li>\n\n\n\n<li>Restricted choice. Only accepting inputs that are certain vales.<\/li>\n\n\n\n<li>Restricted range. Only accepting inputs between certain values.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">Query design<\/h2>\n\n\n\n<p>It is important to take time to design any queries that may need to be implemented later.<\/p>\n\n\n\n<p>At the design stage at SCQF level 6, it is necessary to state the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>fields<\/li>\n\n\n\n<li>tables<\/li>\n\n\n\n<li>search criteria<\/li>\n\n\n\n<li>sort order<\/li>\n\n\n\n<li>calculations<\/li>\n\n\n\n<li>grouping<\/li>\n<\/ul>\n\n\n\n<p>Shorthand can be used for the terms Ascending (ASC) and Descending (DESC).<\/p>\n\n\n\n<p>Only fields and tables are mandatory, the others depend on the query.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example<\/h2>\n\n\n\n<p>Here is an example query to find the details of the customers for the vehicle with an example number plate of \u201cAB1234CD\u201d.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"223\" src=\"https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153643\/DB23-1024x223-1.png\" alt=\"Example query design\" class=\"wp-image-1241\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153643\/DB23-1024x223-1.png 1024w, https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153643\/DB23-1024x223-1-300x65.png 300w, https:\/\/blogs.glowscotland.org.uk\/es\/public\/software\/uploads\/sites\/4063\/2023\/04\/13153643\/DB23-1024x223-1-768x167.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Example query design<\/figcaption><\/figure><\/div>\n\n\n<p class=\"nextlink\"><a href=\"https:\/\/blogs.glowscotland.org.uk\/es\/software\/data-modelling\/database-normalisation\/\" data-type=\"page\" data-id=\"1242\">Next: Database normalisation<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Entity relationship diagrams In entity relationship diagrams the tables are drawn with lines connecting them to show relationships. They can either be simple, just showing the table name: Or more complex, listing the attributes within the table: In either case, the important part of the design is the line connecting the tables. This represents the&hellip; <a class=\"more-link\" href=\"https:\/\/blogs.glowscotland.org.uk\/es\/software\/data-modelling\/database-design\/\">Continue reading <span class=\"screen-reader-text\">Database design<\/span><\/a><\/p>\n","protected":false},"author":5710,"featured_media":0,"parent":1179,"menu_order":3,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1226","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages\/1226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/users\/5710"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/comments?post=1226"}],"version-history":[{"count":4,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages\/1226\/revisions"}],"predecessor-version":[{"id":1352,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages\/1226\/revisions\/1352"}],"up":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages\/1179"}],"wp:attachment":[{"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/media?parent=1226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}