{"id":2686,"date":"2013-05-22T16:53:39","date_gmt":"2013-05-23T00:53:39","guid":{"rendered":"http:\/\/www.mysqltutorial.org\/?page_id=2686"},"modified":"2024-01-29T20:42:38","modified_gmt":"2024-01-30T03:42:38","slug":"mysql-primary-key","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-primary-key\/","title":{"rendered":"MySQL Primary Key"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use the <strong>MySQL primary key<\/strong> constraint to create the primary key for a table.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction to the MySQL primary key<\/h2>\n\n\n\n<p>In MySQL, a primary key is a column or a set of columns that uniquely identifies each row in the table. A primary key column must contain unique values. <\/p>\n\n\n\n<p>If the primary key consists of multiple columns, the combination of values in these columns must be unique. Additionally, a primary key column cannot contain NULL.<\/p>\n\n\n\n<p>A table can have either zero or one primary key, but not more than one.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Defining a single-column primary key<\/h3>\n\n\n\n<p>Typically, you define a primary key for a table when you <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-create-table\/\">create the table<\/a>. Here&#8217;s the syntax for defining the primary key that consists of one column:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">CREATE TABLE table_name(\n   column1 datatype PRIMARY KEY,\n   column2 datatype, \n   ...\n);<\/code><\/span><\/pre>\n\n\n<p>In this syntax, you define the <code>PRIMARY KEY<\/code> constraint as a <em>column constraint<\/em>.<\/p>\n\n\n\n<p>Additionally, you can put the <code>PRIMARY KEY<\/code> at the end of the column list:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">CREATE TABLE table_name(\n   column1 datatype,\n   column2 datatype, \n   ...,\n   PRIMARY KEY(column1)\n);<\/code><\/span><\/pre>\n\n\n<p>In this syntax, you define the <code>PRIMARY KEY<\/code> constraint as a <em>table constraint<\/em>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Defining a multi-column primary key<\/h3>\n\n\n\n<p>If the primary key consists of two or more columns, you need to use a table constraint to define the primary key:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">CREATE TABLE table_name(\n   column1 datatype,\n   column2 datatype,\n   column3 datatype,\n   ...,\n   PRIMARY KEY(column1, column2)\n);<\/code><\/span><\/pre>\n\n\n<p>In this syntax, you list the primary key columns inside parentheses, separated by commas, followed by the <code>PRIMARY KEY<\/code> keywords.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Adding a primary key to an existing table<\/h3>\n\n\n\n<p>If an existing table does not have a primary key, you can add a primary key to the table using the <code>ALTER TABLE ... ADD PRIMARY KEY<\/code> statement:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">ALTER TABLE table_name\nADD PRIMARY KEY(column1, column2, ...);<\/code><\/span><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Removing a primary key<\/h3>\n\n\n\n<p>In practice, you&#8217;ll rarely remove a primary key. However, if you want to do so, you can use the <code>ALTER TABLE ... DROP PRIMARY KEY<\/code> statement:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">ALTER TABLE table_name\nDROP PRIMARY KEY;<\/code><\/span><\/pre>\n\n\n<h2 class=\"wp-block-heading\">MySQL PRIMARY KEY examples<\/h2>\n\n\n\n<p>We&#8217;ll explore some examples of defining primary keys.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1) Defining a single-column primary key example<\/h3>\n\n\n\n<p>The following example <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-create-table\/\">creates a table<\/a> called <code>products<\/code>, which has the <code>id<\/code> column as the primary key:<\/p>\n\n\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 products(\n   id INT PRIMARY KEY,\n   name VARCHAR(<span class=\"hljs-number\">255<\/span>) NOT <span class=\"hljs-keyword\">NULL<\/span>\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>\n\n\n<p>When you <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-insert\/\">insert data<\/a> into the <code>products<\/code> table, you need to ensure the uniqueness of values in the <code>id<\/code> column. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">INSERT INTO products (id, name) \nVALUES \n    (<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-string\">'Laptop'<\/span>),\n    (<span class=\"hljs-number\">2<\/span>, <span class=\"hljs-string\">'Smartphone'<\/span>),\n    (<span class=\"hljs-number\">3<\/span>, <span class=\"hljs-string\">'Wireless Headphones'<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><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<p>If you attempt to insert a duplicate value into the primary key column, you&#8217;ll get an error. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">INSERT INTO products (id, name) \nVALUES \n  (<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-string\">'Bluetooth Speaker'<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><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<p>Error:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">ERROR <span class=\"hljs-number\">1062<\/span> (<span class=\"hljs-number\">23000<\/span>): Duplicate entry <span class=\"hljs-string\">'1'<\/span> <span class=\"hljs-keyword\">for<\/span> key <span class=\"hljs-string\">'products.PRIMARY'<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><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<p>The output indicates that MySQL found a duplicate entry 1 for the primary key of the <code>products<\/code> table.<\/p>\n\n\n\n<p>Keeping track of primary key values manually can be challenging. To simplify this process, MySQL provides the <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-auto_increment\/\">AUTO_INCREMENT<\/a> attribute, which automatically assigns a unique value to the primary key each time you insert a new record.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2) Defining a single-column primary key with AUTO_INCREMENT attribute example<\/h3>\n\n\n\n<p>The following statements re-create the <code>products<\/code> table with the primary key that uses the <code>AUTO_INCREMENT<\/code> attribute:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">DROP TABLE products; \n\nCREATE TABLE products(\n   id INT AUTO_INCREMENT PRIMARY KEY,\n   name VARCHAR(<span class=\"hljs-number\">255<\/span>) NOT <span class=\"hljs-keyword\">NULL<\/span>\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><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>Now, you can insert new rows into the <code>products<\/code> table without having to provide the values for the primary key column. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">INSERT INTO products (name) \nVALUES \n    (<span class=\"hljs-string\">'Laptop'<\/span>),\n    (<span class=\"hljs-string\">'Smartphone'<\/span>),\n    (<span class=\"hljs-string\">'Wireless Headphones'<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><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<p>MySQL automatically generates sequential integer values for the <code>id<\/code> column when a new row is inserted. <\/p>\n\n\n\n<p>Here&#8217;s the contents of the <code>products<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">SELECT * FROM products;<\/code><\/span><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">+----+---------------------+\n| id | name                |\n+----+---------------------+\n|  <span class=\"hljs-number\">1<\/span> | Laptop              |\n|  <span class=\"hljs-number\">2<\/span> | Smartphone          |\n|  <span class=\"hljs-number\">3<\/span> | Wireless Headphones |\n+----+---------------------+\n<span class=\"hljs-number\">3<\/span> rows <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-keyword\">set<\/span> (0.00 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><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\">3) Defining a multi-column primary key example<\/h3>\n\n\n\n<p>We&#8217;ll create a new table called <code>customers<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">CREATE TABLE customers(\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    first_name VARCHAR(<span class=\"hljs-number\">255<\/span>) NOT <span class=\"hljs-keyword\">NULL<\/span>,\n    last_name VARCHAR(<span class=\"hljs-number\">255<\/span>) NOT <span class=\"hljs-keyword\">NULL<\/span>,\n    email VARCHAR(<span class=\"hljs-number\">255<\/span>) NOT <span class=\"hljs-keyword\">NULL<\/span>\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><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>Suppose each customer has some favorite products and each product is favored by some customers.<\/p>\n\n\n\n<p>To model this relationship, you need to create a table called <code>favorites<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">CREATE TABLE faviorites(\n    customer_id INT,\n    product_id INT,\n    favorite_at TIMESTAMP <span class=\"hljs-keyword\">DEFAULT<\/span> CURRENT_TIMESTAMP,\n    PRIMARY KEY(customer_id, product_id)\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><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>The <code>favorites<\/code> table has a primary that consists of two columns <code>customer_id<\/code> and <code>product_id<\/code>. <\/p>\n\n\n\n<p>Note that in the <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-foreign-key\/\">foreign key tutorial<\/a>, you&#8217;ll learn how to define a foreign key for the <code>customer_id<\/code> column that references the <code>id<\/code> column of the <code>customers<\/code> table and a foreign key for the <code>product_id<\/code> column that references the <code>id<\/code> column of the <code>products<\/code> table.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4) Adding a primary key to a table example<\/h3>\n\n\n\n<p>The following statement creates a table called <code>tags<\/code> without a primary key:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">CREATE TABLE tags(\n    id INT,\n    name VARCHAR(<span class=\"hljs-number\">25<\/span>) NOT <span class=\"hljs-keyword\">NULL<\/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\">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>To make the <code>id<\/code> column the primary key, you use the <code>ALTER TABLE ... ADD PRIMARY KEY<\/code> statement:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">ALTER TABLE tags\nADD PRIMARY KEY(id);<\/code><\/span><\/pre>\n\n\n<h3 class=\"wp-block-heading\">5) Removing the primary key from a table<\/h3>\n\n\n\n<p>The following statement removes the primary key from the <code>tags<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">ALTER TABLE tags\nDROP PRIMARY KEY;<\/code><\/span><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A primary key is a unique identifier for a row in a table.<\/li>\n\n\n\n<li>Use the <code>PRIMARY KEY<\/code> constraint to define a primary key for a table.<\/li>\n<\/ul>\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=\"2686\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-primary-key\/\"\n\t\t\t\tdata-post-title=\"MySQL 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=\"2686\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-primary-key\/\"\n\t\t\t\tdata-post-title=\"MySQL 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 how to use MySQL primary key constraint to create the primary key for a table.<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":174,"menu_order":45,"comment_status":"closed","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-2686","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>MySQL Primary Key<\/title>\n<meta name=\"description\" content=\"In this tutorial, you will learn how to use MySQL primary key constraint to create 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.mysqltutorial.org\/mysql-basics\/mysql-primary-key\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MySQL Primary Key\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you will learn how to use MySQL primary key constraint to create the primary key for a table.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-primary-key\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-30T03:42:38+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-primary-key\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-primary-key\\\/\",\"name\":\"MySQL Primary Key\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"datePublished\":\"2013-05-23T00:53:39+00:00\",\"dateModified\":\"2024-01-30T03:42:38+00:00\",\"description\":\"In this tutorial, you will learn how to use MySQL primary key constraint to create the primary key for a table.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-primary-key\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-primary-key\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/mysql-primary-key\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MySQL Basics\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"MySQL Primary Key\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\",\"name\":\"MySQL Tutorial\",\"description\":\"A comprehensive MySQL Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mysqltutorial.org\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MySQL Primary Key","description":"In this tutorial, you will learn how to use MySQL primary key constraint to create 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.mysqltutorial.org\/mysql-basics\/mysql-primary-key\/","og_locale":"en_US","og_type":"article","og_title":"MySQL Primary Key","og_description":"In this tutorial, you will learn how to use MySQL primary key constraint to create the primary key for a table.","og_url":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-primary-key\/","og_site_name":"MySQL Tutorial","article_modified_time":"2024-01-30T03:42:38+00:00","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-primary-key\/","url":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-primary-key\/","name":"MySQL Primary Key","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"datePublished":"2013-05-23T00:53:39+00:00","dateModified":"2024-01-30T03:42:38+00:00","description":"In this tutorial, you will learn how to use MySQL primary key constraint to create the primary key for a table.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-primary-key\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-primary-key\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-primary-key\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.mysqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"MySQL Basics","item":"https:\/\/www.mysqltutorial.org\/mysql-basics\/"},{"@type":"ListItem","position":3,"name":"MySQL Primary Key"}]},{"@type":"WebSite","@id":"https:\/\/www.mysqltutorial.org\/#website","url":"https:\/\/www.mysqltutorial.org\/","name":"MySQL Tutorial","description":"A comprehensive MySQL Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mysqltutorial.org\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/2686","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/comments?post=2686"}],"version-history":[{"count":4,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/2686\/revisions"}],"predecessor-version":[{"id":14609,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/2686\/revisions\/14609"}],"up":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/174"}],"wp:attachment":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media?parent=2686"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}