How do I swap column values in sql server 2008?

后端 未结 8 596
春和景丽
春和景丽 2020-12-08 09:40

I have a table called Employee

 Eno     ename     AttributeValue      AttributeName  
 1       aa           a123             abc
 2       bbb          b123           


        
8条回答
  •  悲&欢浪女
    2020-12-08 09:50

    All the previous techniques are slow for big tables they move data instead of renaming columns, this is a simple solution:

    ALTER TABLE "amplitude"
    RENAME COLUMN "start_hour_displayed" TO "temp";
    
    ALTER TABLE "amplitude"
    RENAME COLUMN "start_hour" TO "start_hour_displayed";
    
    ALTER TABLE "amplitude"
    RENAME COLUMN "temp" TO "start_hour";
    

    If you have views of functions linked you have to backup them before and restore them after.

提交回复
热议问题