How can I change primary key on SQL Azure

前端 未结 5 1584
无人共我
无人共我 2021-02-07 04:44

I am going to change the primary key on SQL Azure. But it throws an error when using Microsoft SQL Server Management Studio to generate the scripts. Because every tables on SQL

5条回答
  •  余生分开走
    2021-02-07 05:29

    I ran into this exact problem and contacted the Azure team on the forums. Basically it isn't possible. You'll need to create a new table and transfer the data to it.

    What I did was create a transaction and within it do the following:

    • Renamed the old table to OLD_MyTable.

    • Create the new table with the correct Primary Key and call it MyTable.

    • Select the contents from OLD_MyTable into MyTable.

    • Drop OLD_MyTable.

    You may also need to call sp_rename on any constraints so they don't conflict.

    See also: http://social.msdn.microsoft.com/Forums/en/ssdsgetstarted/thread/5cc4b302-fa42-4c62-956a-bbf79dbbd040

提交回复
热议问题