{"id":2536,"date":"2019-08-13T09:48:01","date_gmt":"2019-08-13T09:48:01","guid":{"rendered":"http:\/\/teachcomputerscience.com\/?p=524"},"modified":"2024-07-24T10:26:12","modified_gmt":"2024-07-24T10:26:12","slug":"primary-key","status":"publish","type":"post","link":"https:\/\/teachcomputerscience.com\/primary-key\/","title":{"rendered":"Primary Key (Primary Keyword)"},"content":{"rendered":"<div class=\"gb-container gb-container-bf6eac48 upsell-block\"><div class=\"gb-inside-container\">\n<div class=\"gb-grid-wrapper gb-grid-wrapper-a63a2ab0\">\n<div class=\"gb-grid-column gb-grid-column-7b93d7a5\"><div class=\"gb-container gb-container-7b93d7a5\"><div class=\"gb-inside-container\">\n\n<h2 class=\"gb-headline gb-headline-0c5060a7 gb-headline-text\">GCSE Relational Databases (14-16 years)<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>An editable PowerPoint lesson presentation<\/li><li>Editable revision handouts<\/li><li>A glossary which covers the key terminologies of the module<\/li><li>Topic mindmaps for visualising the key concepts<\/li><li>Printable flashcards to help students engage active recall and confidence-based repetition<\/li><li>A quiz with accompanying answer key to test knowledge and understanding of the module<\/li><\/ul>\n\n\n<div class=\"gb-button-wrapper gb-button-wrapper-e34eb196\">\n\n<a class=\"gb-button gb-button-77aa27c8 gb-button-text\" href=\"https:\/\/teachcomputerscience.com\/ks3\/databases\/relational-databases\/\">View GCSE Relational Databases Resources<\/a>\n\n<\/div>\n<\/div><\/div><\/div>\n\n<div class=\"gb-grid-column gb-grid-column-5f603b7b\"><div class=\"gb-container gb-container-5f603b7b\"><div class=\"gb-inside-container\">\n\n<h2 class=\"gb-headline gb-headline-e548afcc gb-headline-text\">A-Level Relational Databases (16-18 years)<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>An editable PowerPoint lesson presentation<\/li><li>Editable revision handouts<\/li><li>A glossary which covers the key terminologies of the module<\/li><li>Topic mindmaps for visualising the key concepts<\/li><li>Printable flashcards to help students engage active recall and confidence-based repetition<\/li><li>A quiz with accompanying answer key to test knowledge and understanding of the module<\/li><\/ul>\n\n\n<div class=\"gb-button-wrapper gb-button-wrapper-13a487a7\">\n\n<a class=\"gb-button gb-button-13b86803 gb-button-text\" href=\"https:\/\/teachcomputerscience.com\/a-level\/exchanging-data\/relational-databases\/\">View A-Level Relational Databases Resources<\/a>\n\n<\/div>\n<\/div><\/div><\/div>\n<\/div>\n<\/div><\/div>\n\n\n\n\n<p>A primary key, also known as a primary keyword, is a key in a relational database that is specific for each record.\u00a0 It is a unique attribute, like a driver\u2019s license number, telephone number with area code, or vehicle identification number (VIN).\u00a0 A <a href=\"http:\/\/teachcomputerscience.com\/relational-databases\/\">relational database<\/a> can only have one primary key.\u00a0 Primary keys are usually displayed as columns in relational database tables.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/teachcomputerscience.com\/wp-content\/uploads\/2019\/08\/032-data.png\" alt=\"A primary key, also known as a primary keyword, is a key in a relational database that is specific for each record.\u00a0 It is a unique attribute, like a driver\u2019s license number, telephone number with area code, or vehicle identification number (VIN).\u00a0 A relational database can only have one primary key.\u00a0 Primary keys are usually displayed as columns in relational database tables.\" class=\"wp-image-5956\" width=\"315\" height=\"315\" title=\"\" srcset=\"https:\/\/teachcomputerscience.com\/wp-content\/uploads\/2019\/08\/032-data.png 512w, https:\/\/teachcomputerscience.com\/wp-content\/uploads\/2019\/08\/032-data-150x150.png 150w, https:\/\/teachcomputerscience.com\/wp-content\/uploads\/2019\/08\/032-data-300x300.png 300w\" sizes=\"auto, (max-width: 315px) 100vw, 315px\" \/><\/figure><\/div>\n\n\n\n<p>The choice of a primary key in a relational <a href=\"http:\/\/teachcomputerscience.com\/what-is-a-database\/\">database<\/a> often comes down to the preference of the administrator.&nbsp; The primary key for a given database can change when the specific needs of the users change.&nbsp; For example, the people in a town might be uniquely identified based on their driver\u2019s license numbers in one application, but in another situation, it might be more appropriate to identify them based on their telephone numbers.<\/p>\n\n\n\n<p>A primary key is a distinct identifier for a&nbsp;<a href=\"http:\/\/teachcomputerscience.com\/database-record\/\">database&nbsp;record<\/a>.&nbsp; One of the fields is typically assigned as the primary key once a table is created.&nbsp; While the primary key is often a number, a text field (or other&nbsp;data type) may also be assigned as a primary key.&nbsp; For example, if a database contains definitions of computer terms, it would make sense for each term to only be listed once in the database.&nbsp; By defining the &#8220;Term&#8221; field as the primary key, it would effectively guarantee that no term is listed more than once in the database.<\/p>\n\n\n\n<p>While a table&#8217;s primary key is usually assigned to a specific <a href=\"http:\/\/teachcomputerscience.com\/database-fields\/\">field<\/a>, it can also be composed of multiple values.&nbsp; For example, a database of news articles can utilise both the title and date fields to distinguish each entry.&nbsp; By combining the &#8220;Title&#8221; and &#8220;Date&#8221; fields as the primary key, it would ensure that no entries have the same title on the same day, which is crucial when it comes to organisation of the database.<\/p>\n\n\n\n<p>If several fields in a table cannot have identical values, most <a href=\"http:\/\/teachcomputerscience.com\/dbms\/\">database management system (DBMS)<\/a> also allow fields to be marked as &#8220;Unique.&#8221;&nbsp; This is similar to setting a field as the primary key, but isn\u2019t quite the same thing.&nbsp; The primary key also acts as an indicator to the record and offers a simple way for the DBMS to search through, sort, and access the records.&nbsp; Additionally, it helps to connect records across multiple tables.&nbsp; Therefore, while multiple fields within a table can be defined as &#8220;Unique,&#8221; each table can only have one primary key.&nbsp; The primary key field must be established for each record, and cannot be&nbsp;null.&nbsp; After all, an undefined identifier is not very useful.<\/p>\n\n\n\n<p>A primary key is either a special relational database table column, or a combination of columns selected to uniquely identify all <a href=\"http:\/\/teachcomputerscience.com\/database-table\/\">table<\/a> records.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Main Features of Primary Key<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>It must contain a unique value for each row of data.<\/li><li>It cannot contain null values.<\/li><\/ul>\n\n\n\n<p>A primary key is either an existing table column or a column that is specifically made by the database, in accordance with a defined sequence.<\/p>\n\n\n\n<p>The primary key concept is an important aspect to any efficient relational database.&nbsp; Relational databases would not work without a primary key\u2014and the closely related foreign key\u2014concepts.<\/p>\n\n\n\n<p>Almost everyone deals with primary keys frequently but unknowingly in everyday life.&nbsp; For example, students are routinely assigned unique identification (ID) numbers, and citizens of a country have unique government-assigned IDs.<\/p>\n\n\n\n<p>Take as an example a database that must contain all of the data stored by a commercial bank.&nbsp; The best option is to create a separate primary key in a new column named CUSTOMER_ID.&nbsp; The database automatically generates a unique number each time a customer is added, ensuring a consistent pattern unique identification.&nbsp; As this key is created, the column is assigned as the primary key within the SQL script that creates the table, and all null values are automatically rejected.<\/p>\n\n\n\n<h3 class=\"gb-headline gb-headline-81146e19 gb-headline-text\"><strong>Further Readings:<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/en.wikipedia.org\/wiki\/Primary_key\" target=\"_blank\" rel=\"noopener\">Primary key<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>A primary key, also known as a primary keyword, is a key in a relational database that is specific for each record.\u00a0 It is a unique attribute, like a driver\u2019s license number, telephone number with area code, or vehicle identification number (VIN).\u00a0 A relational database can only have one primary key.\u00a0 Primary keys are usually &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Primary Key (Primary Keyword)\" class=\"read-more button\" href=\"https:\/\/teachcomputerscience.com\/primary-key\/\" aria-label=\"More on Primary Key (Primary Keyword)\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_generate-full-width-content":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[12],"tags":[204,47],"class_list":["post-2536","post","type-post","status-publish","format-standard","hentry","category-databases","tag-article","tag-hide-old-upsell","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"acf":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/posts\/2536","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/comments?post=2536"}],"version-history":[{"count":2,"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/posts\/2536\/revisions"}],"predecessor-version":[{"id":605560,"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/posts\/2536\/revisions\/605560"}],"wp:attachment":[{"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/media?parent=2536"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/categories?post=2536"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/teachcomputerscience.com\/wp-json\/wp\/v2\/tags?post=2536"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}