{"id":96,"date":"2009-09-29T12:03:36","date_gmt":"2009-09-29T12:03:36","guid":{"rendered":"http:\/\/beta.robertprice.co.uk\/robblog\/2009\/09\/setting_an_auto_increment_seed_in_mysql-shtml\/"},"modified":"2009-09-29T12:03:36","modified_gmt":"2009-09-29T12:03:36","slug":"setting_an_auto_increment_seed_in_mysql-shtml","status":"publish","type":"post","link":"https:\/\/www.robertprice.co.uk\/robblog\/setting_an_auto_increment_seed_in_mysql-shtml\/","title":{"rendered":"Setting An AUTO_INCREMENT Seed In MySQL"},"content":{"rendered":"<p>\nI&#8217;ve used <a href=\"http:\/\/www.mysql.com\/\">MySQL<\/a> for many years and I&#8217;ve (nearly) always used <a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/example-auto-increment.html\"><code>AUTO_INCREMENT<\/code><\/a> to get unique primary keys for my tables.\n<\/p>\n<p>\nI came across a requirement earlier today that meant that I needed an <var>id<\/var> to start from 100000, instead of the the usual 1.\n<\/p>\n<p>\nNormally I&#8217;d have just created a dummy record with an <var>id<\/var> of 100000 so the next insert would occur at 100001. This works as <code>AUTO_INCREMENT<\/code> automatically inserts the current highest value plus 1 for a column when you insert a row with <var>NULL<\/var> or <var>0<\/var> for the row&#8217;s value. This isn&#8217;t very elegant so I spent a few minutes with the MySQL manual and found that it is possible to seed the <code>AUTO_INCREMENT<\/code> to start at a specific value without having to use a dummy insert.\n<\/p>\n<p>\nWhen creating a table you add a seed value at the end of the create statement something like this&#8230;\n<\/p>\n<div class=\"code\"><code>CREATE TABLE test(<br \/>\nid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,<br \/>\nname VARCHAR(50)<br \/>\n) AUTO_INCREMENT = 100000;<br \/>\n<\/code><\/div>\n<p>\nThis means the first insert will have an <var>id<\/var> value of 100001 (the highest current value plus 1).\n<\/p>\n<p>\nYou can also alter an existing table to set the <code>AUTO_INCREMENT<\/code> seed&#8230;\n<\/p>\n<div class=\"code\"><code>ALTER TABLE test AUTO_INCREMENT=200000;<br \/>\n<\/code><\/div>\n<p>\nThe next insert will have an <var>id<\/var> of 200001 now.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve used MySQL for many years and I&#8217;ve (nearly) always used AUTO_INCREMENT to get unique primary keys for my tables. I came across a requirement earlier today that meant that I needed an id to start from 100000, instead of the the usual 1. Normally I&#8217;d have just created a dummy record with an id &hellip; <a href=\"https:\/\/www.robertprice.co.uk\/robblog\/setting_an_auto_increment_seed_in_mysql-shtml\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Setting An AUTO_INCREMENT Seed In MySQL&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[2],"tags":[42],"class_list":["post-96","post","type-post","status-publish","format-standard","hentry","category-dev","tag-mysql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Setting An AUTO_INCREMENT Seed In MySQL - Robert Price<\/title>\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.robertprice.co.uk\/robblog\/setting_an_auto_increment_seed_in_mysql-shtml\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Setting An AUTO_INCREMENT Seed In MySQL - Robert Price\" \/>\n<meta property=\"og:description\" content=\"I&#8217;ve used MySQL for many years and I&#8217;ve (nearly) always used AUTO_INCREMENT to get unique primary keys for my tables. I came across a requirement earlier today that meant that I needed an id to start from 100000, instead of the the usual 1. Normally I&#8217;d have just created a dummy record with an id &hellip; Continue reading &quot;Setting An AUTO_INCREMENT Seed In MySQL&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.robertprice.co.uk\/robblog\/setting_an_auto_increment_seed_in_mysql-shtml\/\" \/>\n<meta property=\"og:site_name\" content=\"Robert Price\" \/>\n<meta property=\"article:published_time\" content=\"2009-09-29T12:03:36+00:00\" \/>\n<meta name=\"author\" content=\"rob\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"rob\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/setting_an_auto_increment_seed_in_mysql-shtml\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/setting_an_auto_increment_seed_in_mysql-shtml\\\/\"},\"author\":{\"name\":\"rob\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"headline\":\"Setting An AUTO_INCREMENT Seed In MySQL\",\"datePublished\":\"2009-09-29T12:03:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/setting_an_auto_increment_seed_in_mysql-shtml\\\/\"},\"wordCount\":188,\"keywords\":[\"MySQL\"],\"articleSection\":[\"Dev\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/setting_an_auto_increment_seed_in_mysql-shtml\\\/\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/setting_an_auto_increment_seed_in_mysql-shtml\\\/\",\"name\":\"Setting An AUTO_INCREMENT Seed In MySQL - Robert Price\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\"},\"datePublished\":\"2009-09-29T12:03:36+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/setting_an_auto_increment_seed_in_mysql-shtml\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/setting_an_auto_increment_seed_in_mysql-shtml\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/setting_an_auto_increment_seed_in_mysql-shtml\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Setting An AUTO_INCREMENT Seed In MySQL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\",\"name\":\"Robert Price\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\",\"name\":\"rob\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"caption\":\"rob\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Setting An AUTO_INCREMENT Seed In MySQL - Robert Price","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.robertprice.co.uk\/robblog\/setting_an_auto_increment_seed_in_mysql-shtml\/","og_locale":"en_GB","og_type":"article","og_title":"Setting An AUTO_INCREMENT Seed In MySQL - Robert Price","og_description":"I&#8217;ve used MySQL for many years and I&#8217;ve (nearly) always used AUTO_INCREMENT to get unique primary keys for my tables. I came across a requirement earlier today that meant that I needed an id to start from 100000, instead of the the usual 1. Normally I&#8217;d have just created a dummy record with an id &hellip; Continue reading \"Setting An AUTO_INCREMENT Seed In MySQL\"","og_url":"https:\/\/www.robertprice.co.uk\/robblog\/setting_an_auto_increment_seed_in_mysql-shtml\/","og_site_name":"Robert Price","article_published_time":"2009-09-29T12:03:36+00:00","author":"rob","twitter_card":"summary_large_image","twitter_misc":{"Written by":"rob","Estimated reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.robertprice.co.uk\/robblog\/setting_an_auto_increment_seed_in_mysql-shtml\/#article","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/setting_an_auto_increment_seed_in_mysql-shtml\/"},"author":{"name":"rob","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"headline":"Setting An AUTO_INCREMENT Seed In MySQL","datePublished":"2009-09-29T12:03:36+00:00","mainEntityOfPage":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/setting_an_auto_increment_seed_in_mysql-shtml\/"},"wordCount":188,"keywords":["MySQL"],"articleSection":["Dev"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/www.robertprice.co.uk\/robblog\/setting_an_auto_increment_seed_in_mysql-shtml\/","url":"https:\/\/www.robertprice.co.uk\/robblog\/setting_an_auto_increment_seed_in_mysql-shtml\/","name":"Setting An AUTO_INCREMENT Seed In MySQL - Robert Price","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website"},"datePublished":"2009-09-29T12:03:36+00:00","author":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"breadcrumb":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/setting_an_auto_increment_seed_in_mysql-shtml\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.robertprice.co.uk\/robblog\/setting_an_auto_increment_seed_in_mysql-shtml\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.robertprice.co.uk\/robblog\/setting_an_auto_increment_seed_in_mysql-shtml\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.robertprice.co.uk\/robblog\/"},{"@type":"ListItem","position":2,"name":"Setting An AUTO_INCREMENT Seed In MySQL"}]},{"@type":"WebSite","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website","url":"https:\/\/www.robertprice.co.uk\/robblog\/","name":"Robert Price","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.robertprice.co.uk\/robblog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5","name":"rob","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","caption":"rob"}}]}},"_links":{"self":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/96","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/comments?post=96"}],"version-history":[{"count":0,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/96\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/media?parent=96"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/categories?post=96"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/tags?post=96"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}