{"id":738,"date":"2025-08-02T05:39:00","date_gmt":"2025-08-01T20:39:00","guid":{"rendered":"https:\/\/touhyo.com\/blog\/?p=738"},"modified":"2025-09-02T00:11:13","modified_gmt":"2025-09-01T15:11:13","slug":"db-renumbering","status":"publish","type":"post","link":"https:\/\/touhyo.com\/blog\/en\/db-renumbering\/","title":{"rendered":"db renumbering"},"content":{"rendered":"\n<p>This method involves discarding unnecessary data and starting from the latest data. In essence, it is a minor adjustment to the numbering system. There are rare cases where verification is required. Careful attention is required when operating the command line (SQL) as it directly affects the database (incorrect operation is not permitted).<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><pre class=\"shiki material-theme-lighter\" style=\"background-color: #FAFAFA\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F76D47\">ALTER<\/span><span style=\"color: #90A4AE\"> <\/span><span style=\"color: #F76D47\">TABLE<\/span><span style=\"color: #90A4AE\"> tbl_a AUTO_INCREMENT <\/span><span style=\"color: #39ADB5\">=<\/span><span style=\"color: #90A4AE\"> <\/span><span style=\"color: #F76D47\">16<\/span><span style=\"color: #90A4AE\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This is for when you want to delete numbers 16 and above from the database and start numbering again from 16. If you don&#8217;t know the latest number, you can write it like this.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><pre class=\"shiki material-theme-lighter\" style=\"background-color: #FAFAFA\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F76D47\">SELECT<\/span><span style=\"color: #90A4AE\"> <\/span><span style=\"color: #6182B8\">MAX<\/span><span style=\"color: #90A4AE\">(id) <\/span><span style=\"color: #F76D47\">AS<\/span><span style=\"color: #90A4AE\"> max_id_a <\/span><span style=\"color: #F76D47\">FROM<\/span><span style=\"color: #90A4AE\"> tbl_a;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>The above is a method for obtaining the current maximum value from the latest ID.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><pre class=\"shiki monokai\" style=\"background-color: #272822\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F8F8F2\">max_id_a\uff1a31<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>If 31 is returned, add &#8220;+1&#8221; as shown below and execute with 32.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><pre class=\"shiki material-theme-lighter\" style=\"background-color: #FAFAFA\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F76D47\">ALTER<\/span><span style=\"color: #90A4AE\"> <\/span><span style=\"color: #F76D47\">TABLE<\/span><span style=\"color: #90A4AE\"> tbl_a AUTO_INCREMENT <\/span><span style=\"color: #39ADB5\">=<\/span><span style=\"color: #90A4AE\"> <\/span><span style=\"color: #F76D47\">32<\/span><span style=\"color: #90A4AE\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>It is also acceptable to add &#8220;+1&#8221; to the current maximum value as shown below.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><pre class=\"shiki material-theme-lighter\" style=\"background-color: #FAFAFA\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F76D47\">SELECT<\/span><span style=\"color: #90A4AE\"> <\/span><span style=\"color: #F76D47\">IFNULL<\/span><span style=\"color: #90A4AE\">(<\/span><span style=\"color: #6182B8\">MAX<\/span><span style=\"color: #90A4AE\">(id) <\/span><span style=\"color: #39ADB5\">+<\/span><span style=\"color: #90A4AE\"> <\/span><span style=\"color: #F76D47\">1<\/span><span style=\"color: #90A4AE\">, <\/span><span style=\"color: #F76D47\">1<\/span><span style=\"color: #90A4AE\">) <\/span><span style=\"color: #F76D47\">AS<\/span><span style=\"color: #90A4AE\"> next_id <\/span><span style=\"color: #F76D47\">FROM<\/span><span style=\"color: #90A4AE\"> tbl_a;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This is a measure to prevent unnecessary empty slots. Adjusting values in anticipation of future numbering may facilitate data management. Verification is required.<\/p>\n\n\n\n<p>MySQL\/MariaDB compatible. Other RDBs (e.g. PostgreSQL) need conversion.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This method involves discarding unnecessary data and starting from the latest data. In essence, it is a minor adjustment to the numbering system. There are rare cases where verification is required. Careful attention is required when operating the command line (SQL) as it directly affects the database (incorrect operation is not permitted). This is for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"en_US","_original_post":"https:\/\/touhyo.com\/blog\/?p=731","footnotes":""},"categories":[1],"tags":[],"class_list":["post-738","post","type-post","status-publish","format-standard","hentry","category-memo","en-US"],"_links":{"self":[{"href":"https:\/\/touhyo.com\/blog\/wp-json\/wp\/v2\/posts\/738","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/touhyo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/touhyo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/touhyo.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/touhyo.com\/blog\/wp-json\/wp\/v2\/comments?post=738"}],"version-history":[{"count":17,"href":"https:\/\/touhyo.com\/blog\/wp-json\/wp\/v2\/posts\/738\/revisions"}],"predecessor-version":[{"id":1032,"href":"https:\/\/touhyo.com\/blog\/wp-json\/wp\/v2\/posts\/738\/revisions\/1032"}],"wp:attachment":[{"href":"https:\/\/touhyo.com\/blog\/wp-json\/wp\/v2\/media?parent=738"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/touhyo.com\/blog\/wp-json\/wp\/v2\/categories?post=738"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/touhyo.com\/blog\/wp-json\/wp\/v2\/tags?post=738"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}