{"id":585,"date":"2019-06-04T01:51:07","date_gmt":"2019-06-04T09:51:07","guid":{"rendered":"https:\/\/db2tutorial.com\/?page_id=585"},"modified":"2020-06-29T23:14:41","modified_gmt":"2020-06-30T07:14:41","slug":"db2-primary-key","status":"publish","type":"page","link":"https:\/\/www.db2tutorial.com\/db2-basics\/db2-primary-key\/","title":{"rendered":"Db2 Primary Key"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use the Db2 <code>PRIMARY KEY<\/code> constraint to define a primary key for a table.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Db2 primary key overview<\/h2>\n\n\n\n<p>A primary key of a table is a column or group of columns whose values uniquely identify every row in the table.<\/p>\n\n\n\n<p>Each table has one and only one primary key. A primary key is optional. However, it&#8217;s a good practice to have a primary key in every table.<\/p>\n\n\n\n<p>To define a primary key for a table, you use the <code>PRIMARY KEY<\/code> constraint.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Creating a table with a primary key<\/h3>\n\n\n\n<p>The following statement <a href=\"https:\/\/db2tutorial.com\/db2-basics\/db2-create-table\/\">creates a table<\/a> with a primary key:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> table_name (\n\tpk_column <span class=\"hljs-keyword\">type<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span> PRIMARY <span class=\"hljs-keyword\">KEY<\/span>,\n\t...\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>If the primary key consists of two or more columns, you use the following syntax:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">CREATE TABLE table_name (\n\tpk_column1 type NOT <span class=\"hljs-keyword\">NULL<\/span>,\n\tpk_column2 type NOT <span class=\"hljs-keyword\">NULL<\/span>,\n\t...,\n\tPRIMARY KEY(pk_column1,pk_column2,...)\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>When you create a table with the primary key constraint, Db2 automatically creates a unique index on the primary key columns. This unique index is also known as the primary index.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Adding a primary key to an existing table<\/h3>\n\n\n\n<p>To add a primary key to a table, you use the following form of <code>ALTER TABLE<\/code> statement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">TABLE<\/span> table_name\n&#91;<span class=\"hljs-keyword\">ADD<\/span> <span class=\"hljs-keyword\">CONSTRAINT<\/span> constraint_name]\nPRIMARY <span class=\"hljs-keyword\">KEY<\/span> (primary_key_columns);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Note that the <code>ADD CONSTRAINT<\/code> clause is optional.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Removing a primary key from a table<\/h3>\n\n\n\n<p>To remove a primary key from a table, you use the following form of the <code>ALTER TABLE<\/code> statement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">TABLE<\/span> table_name \n<span class=\"hljs-keyword\">DROP<\/span> PRIMARY <span class=\"hljs-keyword\">KEY<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Primary key and NOT NULL constraint<\/h3>\n\n\n\n<p>The primary key of a table cannot contain NULL values. In other database systems such as SQL Server, Oracle, and MySQL, the columns included in the primary key columns will implicitly receive the <code>NOT NULL<\/code> constraint. However, in DB2, you must explicitly declare all primary key columns as <code>NOT NULL<\/code> columns.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Primary key and identity column<\/h3>\n\n\n\n<p>Because the primary key must contain unique values that uniquely identify each row of a table, the <a href=\"https:\/\/db2tutorial.com\/db2-basics\/db2-identity-column\/\">identity column<\/a> is an ideal choice for the primary key.<\/p>\n\n\n\n<p>The following syntax shows how to create a table with a primary key as an identity column:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> table_name(\n\tpk_column <span class=\"hljs-built_in\">INT<\/span> \n\t\t<span class=\"hljs-keyword\">GENERATED<\/span> <span class=\"hljs-keyword\">ALWAYS<\/span> <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">IDENTITY<\/span> \n\t\t<span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span> \n\t\tPRIMARY <span class=\"hljs-keyword\">KEY<\/span>,\n\t...,\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Db2 primary key examples<\/h2>\n\n\n\n<p>Let&#8217;s take some examples of creating new tables with primary keys.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1) Creating a table with a primary key example<\/h3>\n\n\n\n<p>Suppose <a href=\"https:\/\/en.wikipedia.org\/wiki\/Social_Security_number\" target=\"_blank\" rel=\"noopener noreferrer\">SSN<\/a> uniquely identifies a person. The following statement creates the <code>persons<\/code> table whose primary key is the SSN column:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> persons (\n\tssn <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">11<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span> PRIMARY <span class=\"hljs-keyword\">KEY<\/span>,\n\tfirst_name <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">100<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tlast_name <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">100<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tgender <span class=\"hljs-built_in\">CHAR<\/span>(<span class=\"hljs-number\">1<\/span>)\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This statement <a href=\"https:\/\/db2tutorial.com\/db2-basics\/db2-insert\/\">inserts<\/a> a new person into the <code>persons<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span> \n\tpersons(ssn,first_name,last_name,gender)\n<span class=\"hljs-keyword\">VALUES<\/span>\n\t(<span class=\"hljs-string\">'123-45-6789'<\/span>,<span class=\"hljs-string\">'John'<\/span>,<span class=\"hljs-string\">'Doe'<\/span>,<span class=\"hljs-string\">'M'<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The following statement attempts to <a href=\"https:\/\/db2tutorial.com\/db2-basics\/db2-insert\/\">insert a new row<\/a> into the <code>persons<\/code> table with an SSN that already exists:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span> \n\tpersons(ssn,first_name,last_name,gender)\n<span class=\"hljs-keyword\">VALUES<\/span>\n\t(<span class=\"hljs-string\">'123-45-6789'<\/span>,<span class=\"hljs-string\">'Jane'<\/span>,<span class=\"hljs-string\">'Doe'<\/span>,<span class=\"hljs-string\">'F'<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Db2 issued the following error:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">SQL0803N  One or more values <span class=\"hljs-keyword\">in<\/span> the INSERT statement, UPDATE statement, or\nforeign key update caused by a DELETE statement are not valid because the\nprimary key, unique constraint or unique index identified by <span class=\"hljs-string\">\"1\"<\/span> constrains\ntable <span class=\"hljs-string\">\"DB2ADMIN.PERSONS\"<\/span> <span class=\"hljs-keyword\">from<\/span> having duplicate values <span class=\"hljs-keyword\">for<\/span> the index key.<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">2) Creating a table with a primary key as an identity column example<\/h3>\n\n\n\n<p>The following example creates a table named <code>members<\/code> with a primary key column as an identity column:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> members(\n\tmember_id <span class=\"hljs-built_in\">INT<\/span> \n\t\t<span class=\"hljs-keyword\">GENERATED<\/span> <span class=\"hljs-keyword\">BY<\/span> <span class=\"hljs-keyword\">DEFAULT<\/span> <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">IDENTITY<\/span> \n\t\tPRIMARY <span class=\"hljs-keyword\">KEY<\/span>,\n\tfirst_name <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">100<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tlast_name <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">100<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tgender <span class=\"hljs-built_in\">CHAR<\/span>(<span class=\"hljs-number\">1<\/span>)\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Each time you insert a new row into the <code>members<\/code> table, Db2 automatically generates a sequential number for the <code>member_id<\/code> column.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span> \n\tmembers(first_name,last_name,gender)\n<span class=\"hljs-keyword\">VALUES<\/span>\n\t(<span class=\"hljs-string\">'Mary'<\/span>,<span class=\"hljs-string\">'Jane'<\/span>,<span class=\"hljs-string\">'F'<\/span>),\n\t(<span class=\"hljs-string\">'Peter'<\/span>,<span class=\"hljs-string\">'Crane'<\/span>,<span class=\"hljs-string\">'M'<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Here are the contents of the <code>members<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> * <span class=\"hljs-keyword\">FROM<\/span> members;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"250\" height=\"55\" src=\"https:\/\/db2tutorial.com\/wp-content\/uploads\/2019\/06\/Db2-Primary-Key-as-Identity-column.png\" alt=\"Db2 Primary Key as Identity column\" class=\"wp-image-586\"\/><\/figure>\n\n\n\n<p>Notice that the <code>member_id<\/code> has the sequential integer 1 and 2.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3) Creating a new table whose primary key has more than one column example<\/h3>\n\n\n\n<p>The following example creates a new table whose primary key contains two columns:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> enrollments (\n\tmember_id <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tmembership_id <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tstart_date <span class=\"hljs-built_in\">DATE<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tPRIMARY <span class=\"hljs-keyword\">KEY<\/span>(member_id, membership_id)\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">4) Adding a primary key to an existing table example<\/h3>\n\n\n\n<p>This example creates a new table without a primary key:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> memberships(\n\tmembership_id <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\t<span class=\"hljs-keyword\">name<\/span> <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">100<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tdescription <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">150<\/span>)\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Before promoting the <code>membership_id<\/code> as the primary key, you first need to make sure that this column does not have duplicate values. Then, you use the following statement to add a primary key to the <code>memberships<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">TABLE<\/span> memberships\n\t<span class=\"hljs-keyword\">ADD<\/span> PRIMARY <span class=\"hljs-keyword\">KEY<\/span>(membership_id);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this tutorial, you have learned about Db2 primary key and how to create a new table with a primary key.<\/p>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"585\"\n\t\t\t\tdata-post-url=\"https:\/\/www.db2tutorial.com\/db2-basics\/db2-primary-key\/\"\n\t\t\t\tdata-post-title=\"Db2 Primary Key\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"585\"\n\t\t\t\tdata-post-url=\"https:\/\/www.db2tutorial.com\/db2-basics\/db2-primary-key\/\"\n\t\t\t\tdata-post-title=\"Db2 Primary Key\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn about Db2 primary key and how to use the PRIMARY KEY constraint to define a primary key for a table.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":141,"menu_order":46,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-585","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>A Ultimate Guide to Db2 Primary Key By Practical Examples<\/title>\n<meta name=\"description\" content=\"In this tutorial, you will learn about Db2 primary key and how to use the PRIMARY KEY constraint to define a primary key for a table.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.db2tutorial.com\/db2-basics\/db2-primary-key\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A Ultimate Guide to Db2 Primary Key By Practical Examples\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you will learn about Db2 primary key and how to use the PRIMARY KEY constraint to define a primary key for a table.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.db2tutorial.com\/db2-basics\/db2-primary-key\/\" \/>\n<meta property=\"og:site_name\" content=\"DB2 Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2020-06-30T07:14:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/db2tutorial.com\/wp-content\/uploads\/2019\/06\/Db2-Primary-Key-as-Identity-column.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.db2tutorial.com\/db2-basics\/db2-primary-key\/\",\"url\":\"https:\/\/www.db2tutorial.com\/db2-basics\/db2-primary-key\/\",\"name\":\"A Ultimate Guide to Db2 Primary Key By Practical Examples\",\"isPartOf\":{\"@id\":\"https:\/\/www.db2tutorial.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.db2tutorial.com\/db2-basics\/db2-primary-key\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.db2tutorial.com\/db2-basics\/db2-primary-key\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/db2tutorial.com\/wp-content\/uploads\/2019\/06\/Db2-Primary-Key-as-Identity-column.png\",\"datePublished\":\"2019-06-04T09:51:07+00:00\",\"dateModified\":\"2020-06-30T07:14:41+00:00\",\"description\":\"In this tutorial, you will learn about Db2 primary key and how to use the PRIMARY KEY constraint to define a primary key for a table.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.db2tutorial.com\/db2-basics\/db2-primary-key\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.db2tutorial.com\/db2-basics\/db2-primary-key\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.db2tutorial.com\/db2-basics\/db2-primary-key\/#primaryimage\",\"url\":\"https:\/\/db2tutorial.com\/wp-content\/uploads\/2019\/06\/Db2-Primary-Key-as-Identity-column.png\",\"contentUrl\":\"https:\/\/db2tutorial.com\/wp-content\/uploads\/2019\/06\/Db2-Primary-Key-as-Identity-column.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.db2tutorial.com\/db2-basics\/db2-primary-key\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.db2tutorial.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Db2 Basics\",\"item\":\"https:\/\/www.db2tutorial.com\/db2-basics\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Db2 Primary Key\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.db2tutorial.com\/#website\",\"url\":\"https:\/\/www.db2tutorial.com\/\",\"name\":\"DB2 Tutorial\",\"description\":\"A Comprehensive DB2 Tutorial\",\"publisher\":{\"@id\":\"https:\/\/www.db2tutorial.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.db2tutorial.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.db2tutorial.com\/#organization\",\"name\":\"Db2 Tutorial\",\"url\":\"https:\/\/www.db2tutorial.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.db2tutorial.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/db2tutorial.com\/wp-content\/uploads\/2019\/03\/favicon.png\",\"contentUrl\":\"https:\/\/db2tutorial.com\/wp-content\/uploads\/2019\/03\/favicon.png\",\"width\":500,\"height\":500,\"caption\":\"Db2 Tutorial\"},\"image\":{\"@id\":\"https:\/\/www.db2tutorial.com\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"A Ultimate Guide to Db2 Primary Key By Practical Examples","description":"In this tutorial, you will learn about Db2 primary key and how to use the PRIMARY KEY constraint to define a primary key for a table.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.db2tutorial.com\/db2-basics\/db2-primary-key\/","og_locale":"en_US","og_type":"article","og_title":"A Ultimate Guide to Db2 Primary Key By Practical Examples","og_description":"In this tutorial, you will learn about Db2 primary key and how to use the PRIMARY KEY constraint to define a primary key for a table.","og_url":"https:\/\/www.db2tutorial.com\/db2-basics\/db2-primary-key\/","og_site_name":"DB2 Tutorial","article_modified_time":"2020-06-30T07:14:41+00:00","og_image":[{"url":"https:\/\/db2tutorial.com\/wp-content\/uploads\/2019\/06\/Db2-Primary-Key-as-Identity-column.png","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.db2tutorial.com\/db2-basics\/db2-primary-key\/","url":"https:\/\/www.db2tutorial.com\/db2-basics\/db2-primary-key\/","name":"A Ultimate Guide to Db2 Primary Key By Practical Examples","isPartOf":{"@id":"https:\/\/www.db2tutorial.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.db2tutorial.com\/db2-basics\/db2-primary-key\/#primaryimage"},"image":{"@id":"https:\/\/www.db2tutorial.com\/db2-basics\/db2-primary-key\/#primaryimage"},"thumbnailUrl":"https:\/\/db2tutorial.com\/wp-content\/uploads\/2019\/06\/Db2-Primary-Key-as-Identity-column.png","datePublished":"2019-06-04T09:51:07+00:00","dateModified":"2020-06-30T07:14:41+00:00","description":"In this tutorial, you will learn about Db2 primary key and how to use the PRIMARY KEY constraint to define a primary key for a table.","breadcrumb":{"@id":"https:\/\/www.db2tutorial.com\/db2-basics\/db2-primary-key\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.db2tutorial.com\/db2-basics\/db2-primary-key\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.db2tutorial.com\/db2-basics\/db2-primary-key\/#primaryimage","url":"https:\/\/db2tutorial.com\/wp-content\/uploads\/2019\/06\/Db2-Primary-Key-as-Identity-column.png","contentUrl":"https:\/\/db2tutorial.com\/wp-content\/uploads\/2019\/06\/Db2-Primary-Key-as-Identity-column.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.db2tutorial.com\/db2-basics\/db2-primary-key\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.db2tutorial.com\/"},{"@type":"ListItem","position":2,"name":"Db2 Basics","item":"https:\/\/www.db2tutorial.com\/db2-basics\/"},{"@type":"ListItem","position":3,"name":"Db2 Primary Key"}]},{"@type":"WebSite","@id":"https:\/\/www.db2tutorial.com\/#website","url":"https:\/\/www.db2tutorial.com\/","name":"DB2 Tutorial","description":"A Comprehensive DB2 Tutorial","publisher":{"@id":"https:\/\/www.db2tutorial.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.db2tutorial.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.db2tutorial.com\/#organization","name":"Db2 Tutorial","url":"https:\/\/www.db2tutorial.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.db2tutorial.com\/#\/schema\/logo\/image\/","url":"https:\/\/db2tutorial.com\/wp-content\/uploads\/2019\/03\/favicon.png","contentUrl":"https:\/\/db2tutorial.com\/wp-content\/uploads\/2019\/03\/favicon.png","width":500,"height":500,"caption":"Db2 Tutorial"},"image":{"@id":"https:\/\/www.db2tutorial.com\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/www.db2tutorial.com\/wp-json\/wp\/v2\/pages\/585","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.db2tutorial.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.db2tutorial.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.db2tutorial.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.db2tutorial.com\/wp-json\/wp\/v2\/comments?post=585"}],"version-history":[{"count":2,"href":"https:\/\/www.db2tutorial.com\/wp-json\/wp\/v2\/pages\/585\/revisions"}],"predecessor-version":[{"id":1141,"href":"https:\/\/www.db2tutorial.com\/wp-json\/wp\/v2\/pages\/585\/revisions\/1141"}],"up":[{"embeddable":true,"href":"https:\/\/www.db2tutorial.com\/wp-json\/wp\/v2\/pages\/141"}],"wp:attachment":[{"href":"https:\/\/www.db2tutorial.com\/wp-json\/wp\/v2\/media?parent=585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}