[{"data":1,"prerenderedAt":72},["ShallowReactive",2],{"/2026/07/08-change-data-type-of-a-primary-key-in-sql-server":3},{"id":4,"title":5,"body":6,"date":63,"description":38,"extension":64,"meta":65,"navigation":66,"path":67,"robots":68,"seo":69,"stem":70,"__hash__":71},"posts/2026/07/08 change-data-type-of-a-primary-key-in-sql-server.md","08 Change Data Type Of A Primary Key In Sql Server",{"type":7,"value":8,"toc":60},"minimark",[9,18,21,25,39,41,44,52],[10,11,13],"post-title",{":date":12},"date",[14,15,17],"h1",{"id":16},"changing-data-type-of-a-primary-key-in-sql-server","Changing Data Type of a Primary Key in SQL Server",[19,20],"br",{},[22,23,24],"p",{},"I'm helping my team changing primary key data type, but a simple ALTER command doesn't work due to the PK constraint. I was under impression that a table always need a PK, so I can't drop the constraint, but I tried it anyway.",[26,27,28],"code-block",{},[29,30,35],"pre",{"className":31,"code":33,"language":34},[32],"language-text","ALTER TABLE [table]\nDROP CONSTRAINT PK_Id;\n","text",[36,37,33],"code",{"__ignoreMap":38},"",[19,40],{},[22,42,43],{},"And it works, I ended up with a table without any PK. Another ALTER to change the data type and one more ALTER to add back the PK constraint and voilà!",[26,45,46],{},[29,47,50],{"className":48,"code":49,"language":34},[32],"ALTER TABLE [table]\nALTER COLUMN Id INT;\n",[36,51,49],{"__ignoreMap":38},[26,53,54],{},[29,55,58],{"className":56,"code":57,"language":34},[32],"ALTER TABLE [table]\nADD CONSTRAINT PK_Id PRIMARY KEY (Id);\n",[36,59,57],{"__ignoreMap":38},{"title":38,"searchDepth":61,"depth":61,"links":62},2,[],"2026-07-08T00:00:00.000Z","md",{},true,"/2026/07/08-change-data-type-of-a-primary-key-in-sql-server",null,{"title":5,"description":38},"2026/07/08 change-data-type-of-a-primary-key-in-sql-server","D2yoP9yyna6GVCRwLl-3XwJc3-TFrPsdW5_1NlRqbyU",1785167451284]