{"id":853,"date":"2023-02-07T07:25:32","date_gmt":"2023-02-07T11:25:32","guid":{"rendered":"https:\/\/www.searchenginegenie.com\/programming-blog\/?p=853"},"modified":"2023-02-07T07:25:34","modified_gmt":"2023-02-07T11:25:34","slug":"update-ids-in-identity-table-in-sql-server","status":"publish","type":"post","link":"https:\/\/www.searchenginegenie.com\/programming-blog\/update-ids-in-identity-table-in-sql-server\/","title":{"rendered":"Update IDs in identity table in SQL server"},"content":{"rendered":"\n<ol class=\"wp-block-list\"><li>Create a temporary table with the same schema as the identity table.<\/li><li>Copy the data from the identity table into the temporary table.<\/li><li>Update the IDs in the temporary table to the new values.<\/li><li>Truncate the identity table.<\/li><li>Copy the data in the temporary table back into the identity table.<\/li><li>Drop the temporary table.<\/li><\/ol>\n\n\n\n<p><\/p>\n\n\n\n<p>CREATE TABLE #TempTable (<br>ID INT IDENTITY,<br>Column1 VARCHAR(50),<br>Column2 VARCHAR(50)<br>);<\/p>\n\n\n\n<p>INSERT INTO #TempTable<br>SELECT * FROM IdentityTable;<\/p>\n\n\n\n<p>UPDATE #TempTable<br>SET ID = NewValue<br>WHERE ID = OldValue;<\/p>\n\n\n\n<p>TRUNCATE TABLE IdentityTable;<\/p>\n\n\n\n<p>INSERT INTO IdentityTable<br>SELECT * FROM #TempTable;<\/p>\n\n\n\n<p>DROP TABLE #TempTable;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Create a temporary table with the same schema as the identity table. Copy the data from the identity table into the temporary table. Update the IDs in the temporary table to the new values. Truncate the identity table. Copy the data in the temporary table back into the identity table. Drop the temporary table. CREATE [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-853","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/posts\/853","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/comments?post=853"}],"version-history":[{"count":1,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/posts\/853\/revisions"}],"predecessor-version":[{"id":854,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/posts\/853\/revisions\/854"}],"wp:attachment":[{"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/media?parent=853"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/categories?post=853"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/tags?post=853"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}