2012-05-04

【系統】PostgreSQL : 修改欄位名稱

Finder.png
最近又要增加一個欄位到某個Table。
但發現裡面好像有一個沒在用的欄位。
所以就直接把他取代成我要的欄位吧。

Synopsis:
ALTER TABLE [ ONLY ] name [ * ]
    RENAME [ COLUMN ] column TO new_column

所以SQL就會像下面寫的這樣。
ALTER TABLE member
    RENAME nick_name TO nickname

順便記一下Alter Table 的 Synopsis
ALTER TABLE [ ONLY ] name [ * ]
    action [, ... ]
ALTER TABLE [ ONLY ] name [ * ]
    RENAME [ COLUMN ] column TO new_column
ALTER TABLE name
    RENAME TO new_name

where action is one of:

    ADD [ COLUMN ] column type [ column_constraint [ ... ] ]
    DROP [ COLUMN ] column [ RESTRICT | CASCADE ]
    ALTER [ COLUMN ] column TYPE type [ USING expression ]
    ALTER [ COLUMN ] column SET DEFAULT expression
    ALTER [ COLUMN ] column DROP DEFAULT
    ALTER [ COLUMN ] column { SET | DROP } NOT NULL
    ALTER [ COLUMN ] column SET STATISTICS integer
    ALTER [ COLUMN ] column SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN }
    ADD table_constraint
    DROP CONSTRAINT constraint_name [ RESTRICT | CASCADE ]
    CLUSTER ON index_name
    SET WITHOUT CLUSTER
    SET WITHOUT OIDS
    OWNER TO new_owner
    SET TABLESPACE tablespace_name

參考: PostgreSQL : ALTER TABLE




0 comments:

張貼留言