{"id":347,"date":"2015-12-05T21:22:51","date_gmt":"2015-12-05T14:22:51","guid":{"rendered":"http:\/\/www.sqlitetutorial.net\/?page_id=347"},"modified":"2022-04-03T15:05:15","modified_gmt":"2022-04-03T08:05:15","slug":"sqlite-primary-key","status":"publish","type":"page","link":"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/","title":{"rendered":"SQLite Primary Key"},"content":{"rendered":"\r\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use SQLite <code>PRIMARY KEY<\/code> constraint to define a primary key for a table.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Introduction to SQLite primary key<\/h2>\r\n\r\n\r\n\r\n<p>A primary key is a column or group of columns used to identify the uniqueness of rows in a table. Each table has one and only one primary key.<\/p>\r\n\r\n\r\n\r\n<p>SQLite allows you to define primary key in two ways:<\/p>\r\n\r\n\r\n\r\n<p>First, if the primary key has only one column, you use the <code>PRIMARY KEY<\/code> column constraint to define the primary key as follows:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">CREATE TABLE table_name(\r\n   column_1 INTEGER NOT <span class=\"hljs-keyword\">NULL<\/span> PRIMARY KEY,\r\n   ...\r\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><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>\r\n\r\n\r\n<p>Second, in case primary key consists of two or more columns, you use the <code>PRIMARY KEY<\/code> table constraint to define the primary as shown in the following statement.<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" 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(\r\n   column_1 <span class=\"hljs-built_in\">INTEGER<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\r\n   column_2 <span class=\"hljs-built_in\">INTEGER<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\r\n   ...\r\n   PRIMARY <span class=\"hljs-keyword\">KEY<\/span>(column_1,column_2,...)\r\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><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>\r\n\r\n\r\n<p>In SQL standard, the primary key column must not contain <code>NULL<\/code> values. It means that the primary key column has an implicit <code><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-not-null-constraint\/\">NOT NULL<\/a><\/code> constraint.<\/p>\r\n\r\n\r\n\r\n<p>However, to make the current version of SQLite compatible with the earlier version, SQLite allows the primary key column to contain <code>NULL<\/code> values.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">SQLite primary key and rowid table<\/h2>\r\n\r\n\r\n\r\n<p>When you <a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-create-table\/\">create a table<\/a> without specifying the <code>WITHOUT ROWID<\/code> option, SQLite adds an implicit column called <code>rowid<\/code> that stores 64-bit signed integer. The <code>rowid<\/code> column is a key that uniquely identifies the rows in the table. Tables that have <code>rowid<\/code> columns are called <code>rowid<\/code> tables.<\/p>\r\n\r\n\r\n\r\n<p>If a table has the primary key that consists of one column, and that column is defined as <code>INTEGER<\/code> then this primary key column becomes an <em>alias<\/em> for the <code>rowid<\/code> column.<\/p>\r\n\r\n\r\n\r\n<p>Notice that if you assign another integer type such as <code>BIGINT<\/code> and <code>UNSIGNED INT<\/code> to the primary key column, this column will not be an alias for the <code>rowid<\/code> column.<\/p>\r\n\r\n\r\n\r\n<p>Because the <code>rowid<\/code> table organizes its data as a B-tree, querying and sorting data of a <code>rowid<\/code> table are very fast. It is faster than using a primary key which is not an alias of the <code>rowid<\/code>.<\/p>\r\n\r\n\r\n\r\n<p>Another important note is that if you declare a column with the <code>INTEGER<\/code> type and <code>PRIMARY KEY DESC<\/code> clause, this column will not become an alias for the <code>rowid<\/code> column:<\/p>\r\n\r\n\r\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\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> <span class=\"hljs-keyword\">table<\/span>(\r\n   pk <span class=\"hljs-built_in\">INTEGER<\/span> PRIMARY <span class=\"hljs-keyword\">KEY<\/span> <span class=\"hljs-keyword\">DESC<\/span>,\r\n   ...\r\n);<\/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>\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Creating SQLite primary key examples<\/h2>\r\n\r\n\r\n\r\n<p>The following statement creates a table named <code>countries<\/code> which has <code>country_id<\/code> column as the primary key.<\/p>\r\n\r\n\r\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\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> countries (\r\n   country_id <span class=\"hljs-built_in\">INTEGER<\/span> PRIMARY <span class=\"hljs-keyword\">KEY<\/span>,\r\n   <span class=\"hljs-keyword\">name<\/span> <span class=\"hljs-built_in\">TEXT<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>\r\n);<\/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>\r\n\r\n\r\n<p><a class=\"sql\" href=\"https:\/\/www.sqlitetutorial.net\/tryit\/query\/sqlite-primary-key\/#1\" target=\"_blank\" rel=\"noopener noreferrer\">Try It<\/a><\/p>\r\n\r\n\r\n\r\n<p>Because the primary key of the <code>countries<\/code> table has only one column, we defined the primary key using <code>PRIMARY KEY<\/code> column constraint.<\/p>\r\n\r\n\r\n\r\n<p>It is possible to use the <code>PRIMARY KEY<\/code> table constraint to define the primary key that consists of one column as shown in the following statement:<\/p>\r\n\r\n\r\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> languages (\r\n   language_id <span class=\"hljs-built_in\">INTEGER<\/span>,\r\n   <span class=\"hljs-keyword\">name<\/span> <span class=\"hljs-built_in\">TEXT<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\r\n   PRIMARY <span class=\"hljs-keyword\">KEY<\/span> (language_id)\r\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>\r\n\r\n\r\n<p><a class=\"sql\" href=\"https:\/\/www.sqlitetutorial.net\/tryit\/query\/sqlite-primary-key\/#2\" target=\"_blank\" rel=\"noopener noreferrer\">Try It<\/a><\/p>\r\n\r\n\r\n\r\n<p>However, for tables that the primary keys consist of more than one column, you must use <code>PRIMARY KEY<\/code> table constraint to define primary keys.<\/p>\r\n\r\n\r\n\r\n<p>The following statement creates the <code>country_languages<\/code> table whose primary key consists of two columns.<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">CREATE TABLE country_languages (\r\n\tcountry_id INTEGER NOT <span class=\"hljs-keyword\">NULL<\/span>,\r\n\tlanguage_id INTEGER NOT <span class=\"hljs-keyword\">NULL<\/span>,\r\n\tPRIMARY KEY (country_id, language_id),\r\n\tFOREIGN KEY (country_id) REFERENCES countries (country_id) \r\n            ON DELETE CASCADE ON UPDATE NO ACTION,\r\n\tFOREIGN KEY (language_id) REFERENCES languages (language_id) \r\n            ON DELETE CASCADE ON UPDATE NO ACTION\r\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><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>\r\n\r\n\r\n<p><a class=\"sql\" href=\"https:\/\/www.sqlitetutorial.net\/tryit\/query\/sqlite-primary-key\/#3\" target=\"_blank\" rel=\"noopener noreferrer\">Try It<\/a><\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Adding SQLite primary key example<\/h2>\r\n\r\n\r\n\r\n<p>Unlike other database systems e.g., MySQL and PostgreSQL, you cannot use the <code><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-alter-table\/\">ALTER TABLE<\/a><\/code>&nbsp;statement to add a primary key to an existing table.<\/p>\r\n\r\n\r\n\r\n<p>You need to follow these steps to work around the limitation:<\/p>\r\n\r\n\r\n\r\n<ol class=\"wp-block-list\"><li>First, set the <a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-foreign-key\/\">foreign key<\/a> constarint check off.<\/li><li>Next, rename the table to another table name (old_table)<\/li><li>Then, create a new table (table) with exact structure of the table that you have been renamed.<\/li><li>After that, copy data from the old_table to the table.<\/li><li>Finally, turn on the foreign key constraint check on<\/li><\/ol>\r\n\r\n\r\n\r\n<p>See the following statements:<\/p>\r\n\r\n\r\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\">PRAGMA<\/span> foreign_keys=<span class=\"hljs-keyword\">off<\/span>;\r\n\r\n<span class=\"hljs-keyword\">BEGIN<\/span> <span class=\"hljs-keyword\">TRANSACTION<\/span>;\r\n\r\n<span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">TABLE<\/span> <span class=\"hljs-keyword\">table<\/span> <span class=\"hljs-keyword\">RENAME<\/span> <span class=\"hljs-keyword\">TO<\/span> old_table;\r\n\r\n<span class=\"hljs-comment\">-- define the primary key constraint here<\/span>\r\n<span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> <span class=\"hljs-keyword\">table<\/span> ( ... );\r\n\r\n<span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span> <span class=\"hljs-keyword\">table<\/span> <span class=\"hljs-keyword\">SELECT<\/span> * <span class=\"hljs-keyword\">FROM<\/span> old_table;\r\n\r\n<span class=\"hljs-keyword\">COMMIT<\/span>;\r\n\r\n<span class=\"hljs-keyword\">PRAGMA<\/span> foreign_keys=<span class=\"hljs-keyword\">on<\/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>\r\n\r\n\r\n<p><a class=\"sql\" href=\"https:\/\/www.sqlitetutorial.net\/tryit\/query\/sqlite-primary-key\/#4\" target=\"_blank\" rel=\"noopener noreferrer\">Try It<\/a><\/p>\r\n\r\n\r\n\r\n<p>The <code>BEGIN TRANSACTION<\/code> starts a new transaction. It ensures that all subsequent statements execute successfully or nothing executes at all.<\/p>\r\n\r\n\r\n\r\n<p>The <code>COMMIT<\/code> statement commits all the statements.<\/p>\r\n\r\n\r\n\r\n<p>Let&#8217;s create a table name <code>cities<\/code> without a primary key.<\/p>\r\n\r\n\r\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\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> cities (\r\n   <span class=\"hljs-keyword\">id<\/span> <span class=\"hljs-built_in\">INTEGER<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\r\n   <span class=\"hljs-keyword\">name<\/span> <span class=\"hljs-built_in\">text<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>\r\n);\r\n\r\n<span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span> cities (<span class=\"hljs-keyword\">id<\/span>, <span class=\"hljs-keyword\">name<\/span>)\r\n<span class=\"hljs-keyword\">VALUES<\/span>(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-string\">'San Jose'<\/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>\r\n\r\n\r\n<p><a class=\"sql\" href=\"https:\/\/www.sqlitetutorial.net\/tryit\/query\/sqlite-primary-key\/#5\" target=\"_blank\" rel=\"noopener noreferrer\">Try It<\/a><\/p>\r\n\r\n\r\n\r\n<p>In order to add the primary key to the <code>cities<\/code> table, you perform the following steps:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">PRAGMA<\/span> foreign_keys=<span class=\"hljs-keyword\">off<\/span>;\r\n\r\n<span class=\"hljs-keyword\">BEGIN<\/span> <span class=\"hljs-keyword\">TRANSACTION<\/span>;\r\n\r\n<span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">TABLE<\/span> cities <span class=\"hljs-keyword\">RENAME<\/span> <span class=\"hljs-keyword\">TO<\/span> old_cities;\r\n\r\n<span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> cities (\r\n   <span class=\"hljs-keyword\">id<\/span> <span class=\"hljs-built_in\">INTEGER<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span> PRIMARY <span class=\"hljs-keyword\">KEY<\/span>,\r\n   <span class=\"hljs-keyword\">name<\/span> <span class=\"hljs-built_in\">TEXT<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>\r\n);\r\n\r\n<span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span> cities \r\n<span class=\"hljs-keyword\">SELECT<\/span> * <span class=\"hljs-keyword\">FROM<\/span> old_cities;\r\n\r\n<span class=\"hljs-keyword\">DROP<\/span> <span class=\"hljs-keyword\">TABLE<\/span> old_cities;\r\n\r\n<span class=\"hljs-keyword\">COMMIT<\/span>;\r\n\r\n<span class=\"hljs-keyword\">PRAGMA<\/span> foreign_keys=<span class=\"hljs-keyword\">on<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><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>\r\n\r\n\r\n<p><a class=\"sql\" href=\"https:\/\/www.sqlitetutorial.net\/tryit\/query\/sqlite-primary-key\/#6\" target=\"_blank\" rel=\"noopener noreferrer\">Try It<\/a><\/p>\r\n\r\n\r\n\r\n<p>If you use SQLite GUI tool, you can use the following statement to show the table&#8217;s information.<\/p>\r\n\r\n\r\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\">PRAGMA<\/span> table_info(&#91;cities]);<\/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>\r\n\r\n\r\n<p><a class=\"sql\" href=\"https:\/\/www.sqlitetutorial.net\/tryit\/query\/sqlite-primary-key\/#7\" target=\"_blank\" rel=\"noopener noreferrer\">Try It<\/a><\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"371\" height=\"62\" src=\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2015\/12\/SQLite-Primary-Key-Example.jpg\" alt=\"SQLite Primary Key Example\" class=\"wp-image-349\" srcset=\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2015\/12\/SQLite-Primary-Key-Example.jpg 371w, https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2015\/12\/SQLite-Primary-Key-Example-300x50.jpg 300w\" sizes=\"auto, (max-width: 371px) 100vw, 371px\" \/><\/figure>\r\n\r\n\r\n\r\n<p>In this tutorial, you have learned use the SQLite <code>PRIMARY KEY<\/code> constraint to define the primary key for a table.<\/p>\r\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=\"347\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/\"\n\t\t\t\tdata-post-title=\"SQLite 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=\"347\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/\"\n\t\t\t\tdata-post-title=\"SQLite 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>Summary: in this tutorial, you will learn how to use SQLite PRIMARY KEY constraint to define a primary key for a table. Introduction to SQLite primary key A primary key is a column or group of columns used to identify the uniqueness of rows in a table. Each table has one and only one primary [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":2,"menu_order":45,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-347","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>SQLite Primary Key: The Ultimate Guide To Primary Key<\/title>\n<meta name=\"description\" content=\"This tutorial shows you how to use SQLite PRIMARY KEY constraint to define the 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.sqlitetutorial.net\/sqlite-primary-key\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQLite Primary Key: The Ultimate Guide To Primary Key\" \/>\n<meta property=\"og:description\" content=\"This tutorial shows you how to use SQLite PRIMARY KEY constraint to define the primary key for a table.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/\" \/>\n<meta property=\"og:site_name\" content=\"SQLite Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-03T08:05:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2015\/12\/SQLite-Primary-Key-Example.jpg\" \/>\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\":\"Article\",\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/www.sqlitetutorial.net\/#\/schema\/person\/6d69b968cad0102e30d6694ed8dc6427\"},\"headline\":\"SQLite Primary Key\",\"datePublished\":\"2015-12-05T14:22:51+00:00\",\"dateModified\":\"2022-04-03T08:05:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/\"},\"wordCount\":613,\"image\":{\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2015\/12\/SQLite-Primary-Key-Example.jpg\",\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/\",\"url\":\"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/\",\"name\":\"SQLite Primary Key: The Ultimate Guide To Primary Key\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlitetutorial.net\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2015\/12\/SQLite-Primary-Key-Example.jpg\",\"datePublished\":\"2015-12-05T14:22:51+00:00\",\"dateModified\":\"2022-04-03T08:05:15+00:00\",\"description\":\"This tutorial shows you how to use SQLite PRIMARY KEY constraint to define the primary key for a table.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/#primaryimage\",\"url\":\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2015\/12\/SQLite-Primary-Key-Example.jpg\",\"contentUrl\":\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2015\/12\/SQLite-Primary-Key-Example.jpg\",\"width\":371,\"height\":62,\"caption\":\"SQLite Primary Key Example\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlitetutorial.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQLite Primary Key\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlitetutorial.net\/#website\",\"url\":\"https:\/\/www.sqlitetutorial.net\/\",\"name\":\"SQLite Tutorial\",\"description\":\"A Step-by-step SQLite Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlitetutorial.net\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlitetutorial.net\/#\/schema\/person\/6d69b968cad0102e30d6694ed8dc6427\",\"name\":\"admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQLite Primary Key: The Ultimate Guide To Primary Key","description":"This tutorial shows you how to use SQLite PRIMARY KEY constraint to define the 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.sqlitetutorial.net\/sqlite-primary-key\/","og_locale":"en_US","og_type":"article","og_title":"SQLite Primary Key: The Ultimate Guide To Primary Key","og_description":"This tutorial shows you how to use SQLite PRIMARY KEY constraint to define the primary key for a table.","og_url":"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/","og_site_name":"SQLite Tutorial","article_modified_time":"2022-04-03T08:05:15+00:00","og_image":[{"url":"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2015\/12\/SQLite-Primary-Key-Example.jpg","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/#article","isPartOf":{"@id":"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/"},"author":{"name":"admin","@id":"https:\/\/www.sqlitetutorial.net\/#\/schema\/person\/6d69b968cad0102e30d6694ed8dc6427"},"headline":"SQLite Primary Key","datePublished":"2015-12-05T14:22:51+00:00","dateModified":"2022-04-03T08:05:15+00:00","mainEntityOfPage":{"@id":"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/"},"wordCount":613,"image":{"@id":"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2015\/12\/SQLite-Primary-Key-Example.jpg","inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/","url":"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/","name":"SQLite Primary Key: The Ultimate Guide To Primary Key","isPartOf":{"@id":"https:\/\/www.sqlitetutorial.net\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/#primaryimage"},"image":{"@id":"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2015\/12\/SQLite-Primary-Key-Example.jpg","datePublished":"2015-12-05T14:22:51+00:00","dateModified":"2022-04-03T08:05:15+00:00","description":"This tutorial shows you how to use SQLite PRIMARY KEY constraint to define the primary key for a table.","breadcrumb":{"@id":"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/#primaryimage","url":"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2015\/12\/SQLite-Primary-Key-Example.jpg","contentUrl":"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2015\/12\/SQLite-Primary-Key-Example.jpg","width":371,"height":62,"caption":"SQLite Primary Key Example"},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlitetutorial.net\/sqlite-primary-key\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlitetutorial.net\/"},{"@type":"ListItem","position":2,"name":"SQLite Primary Key"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlitetutorial.net\/#website","url":"https:\/\/www.sqlitetutorial.net\/","name":"SQLite Tutorial","description":"A Step-by-step SQLite Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlitetutorial.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlitetutorial.net\/#\/schema\/person\/6d69b968cad0102e30d6694ed8dc6427","name":"admin"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/pages\/347","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/comments?post=347"}],"version-history":[{"count":1,"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/pages\/347\/revisions"}],"predecessor-version":[{"id":2799,"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/pages\/347\/revisions\/2799"}],"up":[{"embeddable":true,"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/pages\/2"}],"wp:attachment":[{"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/media?parent=347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}