2013-09-26 35 views
0

我有一個表,例如,重新排列表中的行而不截斷它們以重新插入?

Health condition | Description 
----------------------------------------------- 
OtherHealth   | Other Health Care Needs 
TraumaBrain   | Traumatic Brain Injury 
None    | None 

現在,我很遺憾,我最後添加的最後一列。現在這個表上有依賴關係,所以我不能截斷並重新插入它們。所以我正在尋找一種方法來將最後一行放在第一位。

+4

行的順序沒有在SQL表中的任何重要性。 –

回答

0

要重新排列這兩列使用

alter table t rename column "Health condition" to c1; 
alter table t rename column "Description" to c2; 
update t set c1=c2, c2=c1; 
alter table t rename column c1 to "Description"; 
alter table t rename column c2 to "Health condition";