{"id":178993,"date":"2024-04-23T16:04:44","date_gmt":"2024-04-23T15:04:44","guid":{"rendered":"https:\/\/liora.io\/en\/?p=178993"},"modified":"2026-02-17T14:38:53","modified_gmt":"2026-02-17T13:38:53","slug":"primary-key-definition-advantages-and-special-features","status":"publish","type":"post","link":"https:\/\/liora.io\/en\/primary-key-definition-advantages-and-special-features","title":{"rendered":"Primary key: Definition, advantages and special features"},"content":{"rendered":"\n<p><strong>Relational databases contain thousands and thousands of rows. To simplify processing, it is vital to identify the different records in a table clearly and efficiently. This is where primary keys come in. <\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-primary-keys-unique-fields-in-your-data-table\">Primary keys, unique fields in your data table<\/h2>\n\n\n\n<p>The <strong>primary key<\/strong> refers to one (or more) attribute(s) which allows records to be fully differentiated. In practical terms, it is a single field for all the records in a table.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-the-advantages-of-a-primary-key\">The advantages of a primary key<\/h2>\n\n\n\n<p>The purpose of <strong>primary keys<\/strong> is to structure the database so that it is easier to identify the rows in the table. In doing so, primary keys make it possible to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/liora.io\/en\/data-quality-10-mistakes-not-to-make\">Guarantee data integrity and accuracy: <\/a>each row is only recorded once and no important information is lost.<\/li>\n\n\n\n<li><strong>Simplify the update process:<\/strong> simply select the different primary keys to modify or delete rows.<\/li>\n\n\n\n<li>Quicker access to data: if you know the table&#8217;s primary key, you can access the data you need more easily.<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex is-content-justification-center\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"\/en\/courses\/data-ai\/\">Learn how to use primary keys<\/a><\/div>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"example-of-a-primary-key\">Example of a primary key<\/h3>\n\n\n\n<p>To help you better <strong>understand primary keys,<\/strong> here is an example:<\/p>\n\n\n\n<div>\n  <table style=\"width:100%;border-collapse: collapse;border: 1px solid #ddd\">\n    <thead>\n      <tr style=\"background-color: #ff6745;color: #ffffff\">\n        <th style=\"border: 1px solid #ddd;padding: 8px\">Name<\/th>\n        <th style=\"border: 1px solid #ddd;padding: 8px\">First Name<\/th>\n        <th style=\"border: 1px solid #ddd;padding: 8px\">Age<\/th>\n      <\/tr>\n    <\/thead>\n    <tbody>\n      <tr>\n        <td style=\"border: 1px solid #ddd;padding: 8px\">Dupont<\/td>\n        <td style=\"border: 1px solid #ddd;padding: 8px\">Jeanne<\/td>\n        <td style=\"border: 1px solid #ddd;padding: 8px\">25<\/td>\n      <\/tr>\n\n      <tr>\n        <td style=\"border: 1px solid #ddd;padding: 8px\">Leroy<\/td>\n        <td style=\"border: 1px solid #ddd;padding: 8px\">Marie<\/td>\n        <td style=\"border: 1px solid #ddd;padding: 8px\">21<\/td>\n      <\/tr>\n\n      <tr>\n        <td style=\"border: 1px solid #ddd;padding: 8px\">Dupont<\/td>\n        <td style=\"border: 1px solid #ddd;padding: 8px\">Pierre<\/td>\n        <td style=\"border: 1px solid #ddd;padding: 8px\">21<\/td>\n      <\/tr>\n    <\/tbody>\n  <\/table>\n<\/div>\n\n\n\n\n<div style=\"height:1px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>In this example, only the &#8220;First name&#8221; attribute is used to differentiate the rows in the table. And for good reason, in the name, &#8220;Smith&#8221; is found 2 times. The same applies to age 21. The first name attribute is therefore a primary key.<\/p>\n\n\n\n<p>However, this is no longer the case with the following table:<\/p>\n\n\n\n<div>\n  <table style=\"width:100%;border-collapse: collapse;border: 1px solid #ddd\">\n    <thead>\n      <tr style=\"background-color: #ff6745;color: #ffffff\">\n        <th style=\"border: 1px solid #ddd;padding: 8px\">Name<\/th>\n        <th style=\"border: 1px solid #ddd;padding: 8px\">First Name<\/th>\n        <th style=\"border: 1px solid #ddd;padding: 8px\">Age<\/th>\n      <\/tr>\n    <\/thead>\n    <tbody>\n      <tr>\n        <td style=\"border: 1px solid #ddd;padding: 8px\">Dupont<\/td>\n        <td style=\"border: 1px solid #ddd;padding: 8px\">Jeanne<\/td>\n        <td style=\"border: 1px solid #ddd;padding: 8px\">25<\/td>\n      <\/tr>\n\n      <tr>\n        <td style=\"border: 1px solid #ddd;padding: 8px\">Leroy<\/td>\n        <td style=\"border: 1px solid #ddd;padding: 8px\">Jeanne<\/td>\n        <td style=\"border: 1px solid #ddd;padding: 8px\">21<\/td>\n      <\/tr>\n\n      <tr>\n        <td style=\"border: 1px solid #ddd;padding: 8px\">Dupont<\/td>\n        <td style=\"border: 1px solid #ddd;padding: 8px\">Pierre<\/td>\n        <td style=\"border: 1px solid #ddd;padding: 8px\">21<\/td>\n      <\/tr>\n    <\/tbody>\n  <\/table>\n<\/div>\n\n\n\n\n<div style=\"height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>In this case, no single attribute can be used to differentiate between records. So you need to select several attributes, such as surname + first name. By combining the two, you can see that there is never the same line twice. Here, the last name + first name attributes constitute a primary key.<\/p>\n\n\n\n<p><strong>Good to know:<\/strong> <a href=\"https:\/\/liora.io\/en\/datasets-top-5-places-to-find-quality-datasets\">databases<\/a> often contain an ID attribute which serves as the primary key. This involves assigning a distinct number to each row (1,2,3,4&#8230;). This primary key is created automatically at the very beginning of the table (column A) in order to differentiate each record.<\/p>\n\n\n\n<p>This is why the term primary key is very often confused with identifier. Although the two are often identical, this is not automatic.<\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"the-different-types-of-primary-key\">The different types of primary key<\/h2>\n\n\n\n<p>There are different types of <strong>primary keys<\/strong>. The most common are :<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Natural keys:<\/strong> these are attributes that contain significant information (without which it is impossible to make a mistake). This is the case, for example, with a social security number.<\/li>\n\n\n\n<li><strong>Substitution keys:<\/strong> these are artificial keys, such as an automatically generated number.<\/li>\n\n\n\n<li><strong>Composite keys:<\/strong> this is a combination of several attributes, such as the first and last names of customers.<\/li>\n<\/ul>\n\n\n<h2 class=\"wp-block-heading\" id=\"primary-and-foreign-keys\">Primary and foreign keys<\/h2>\n\n\n\n<p>The <strong>ultimate purpose of the primary key<\/strong> is to link related records in other tables. For example, the customer ID can be used in a table grouping all the company&#8217;s customers and another table grouping customers by salesperson.<\/p>\n\n\n\n<p>This is where <strong>foreign keys<\/strong> come into play. These are one or more attributes which are the primary key in an A table and which are used to characterise the elements in a B table. In this case, it is generally the ID (of a customer, a product, an employee, etc.) that is used in several different tables.<\/p>\n\n\n\n<p>To find out more about <a href=\"https:\/\/liora.io\/en\/how-to-choose-a-data-governance-course\">data management<\/a>, sign up for one of our training courses.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Hybrid learning at DataScientest - The most effective learning method !\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/9UIHp6DCjbU?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-a89b3969 wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"\/en\/courses\/data-ai\/\">Join the Liora training courses<\/a><\/div>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"key-facts\">Key facts:<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Primary keys are unique fields used to differentiate rows in a database.<\/li>\n\n\n\n<li>Most of the time, primary keys are IDs (or identifiers). But this is not always the case.<\/li>\n\n\n\n<li>Foreign keys are used to link data between different tables.<\/li>\n<\/ul>\n\n\n\n<script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"FAQPage\",\n  \"mainEntity\": [\n    {\n      \"@type\": \"Question\",\n      \"name\": \"Primary keys, unique fields in your data table\",\n      \"acceptedAnswer\": {\n        \"@type\": \"Answer\",\n        \"text\": \"The primary key refers to one (or more) attribute(s) which allows records to be fully differentiated. In practical terms, it is a single field for all the records in a table.\"\n      }\n    },\n    {\n      \"@type\": \"Question\",\n      \"name\": \"The advantages of a primary key\",\n      \"acceptedAnswer\": {\n        \"@type\": \"Answer\",\n        \"text\": \"The purpose of primary keys is to structure the database so that it is easier to identify the rows in the table. In doing so, primary keys make it possible to: \u2022 Guarantee data integrity and accuracy: each row is only recorded once and no important information is lost. \u2022 Simplify the update process: simply select the different primary keys to modify or delete rows. \u2022 Quicker access to data: if you know the table\u2019s primary key, you can access the data you need more easily.\"\n      }\n    },\n    {\n      \"@type\": \"Question\",\n      \"name\": \"Example of a primary key\",\n      \"acceptedAnswer\": {\n        \"@type\": \"Answer\",\n        \"text\": \"To help you better understand primary keys, here is an example: Name First Name Age Dupont Jeanne 25 Leroy Marie 21 Dupont Pierre 21 In this example, only the \u201cFirst name\u201d attribute is used to differentiate the rows in the table. And for good reason, in the name, \u201cSmith\u201d is found 2 times. The same applies to age 21. The first name attribute is therefore a primary key. However, this is no longer the case with the following table: Name First Name Age Dupont Jeanne 25 Leroy Jeanne 21 Dupont Pierre 21 In this case, no single attribute can be used to differentiate between records. So you need to select several attributes, such as surname + first name. By combining the two, you can see that there is never the same line twice. Here, the last name + first name attributes constitute a primary key. Good to know: databases often contain an ID attribute which serves as the primary key. This involves assigning a distinct number to each row (1,2,3,4\u2026). This primary key is created automatically at the very beginning of the table (column A) in order to differentiate each record. This is why the term primary key is very often confused with identifier. Although the two are often identical, this is not automatic.\"\n      }\n    },\n    {\n      \"@type\": \"Question\",\n      \"name\": \"The different types of primary key\",\n      \"acceptedAnswer\": {\n        \"@type\": \"Answer\",\n        \"text\": \"There are different types of primary keys. The most common are: \u2022 Natural keys: these are attributes that contain significant information (without which it is impossible to make a mistake). This is the case, for example, with a social security number. \u2022 Substitution keys: these are artificial keys, such as an automatically generated number. \u2022 Composite keys: this is a combination of several attributes, such as the first and last names of customers.\"\n      }\n    },\n    {\n      \"@type\": \"Question\",\n      \"name\": \"Primary and foreign keys\",\n      \"acceptedAnswer\": {\n        \"@type\": \"Answer\",\n        \"text\": \"The ultimate purpose of the primary key is to link related records in other tables. For example, the customer ID can be used in a table grouping all the company\u2019s customers and another table grouping customers by salesperson. This is where foreign keys come into play. These are one or more attributes which are the primary key in an A table and which are used to characterise the elements in a B table. In this case, it is generally the ID (of a customer, a product, an employee, etc.) that is used in several different tables.\"\n      }\n    },\n    {\n      \"@type\": \"Question\",\n      \"name\": \"Key facts:\",\n      \"acceptedAnswer\": {\n        \"@type\": \"Answer\",\n        \"text\": \"\u2022 Primary keys are unique fields used to differentiate rows in a database. \u2022 Most of the time, primary keys are IDs (or identifiers). But this is not always the case. \u2022 Foreign keys are used to link data between different tables.\"\n      }\n    }\n  ]\n}\n<\/script>\n\n","protected":false},"excerpt":{"rendered":"<p>Relational databases contain thousands and thousands of rows. To simplify processing, it is vital to identify the different records in a table clearly and efficiently. This is where primary keys come in. Primary keys, unique fields in your data table The primary key refers to one (or more) attribute(s) which allows records to be fully [&hellip;]<\/p>\n","protected":false},"author":50,"featured_media":178997,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"editor_notices":[],"footnotes":""},"categories":[2433],"class_list":["post-178993","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-ai"],"acf":[],"_links":{"self":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts\/178993","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/users\/50"}],"replies":[{"embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/comments?post=178993"}],"version-history":[{"count":3,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts\/178993\/revisions"}],"predecessor-version":[{"id":207045,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts\/178993\/revisions\/207045"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/media\/178997"}],"wp:attachment":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/media?parent=178993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/categories?post=178993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}