DB2 alter表欄位

來源:互聯網
上載者:User

DB2 alter:add/delete/reset   column

1.添加欄位

alter table [table_name] add [column_name] [column_type]

2.更改欄位類型

alter table  [table_name] alter column [column_name] set data type  [column_type]

注意: 更改欄位類型是有限制的,如將欄位改為比之前類型長度大的可以,如果要改小或者修改小數點長度,必須先drop掉原來的column,然後再重新添加.

例如我要將一個Varchar(10)的column改為Varchar(6) 或者將一個DECIMAL(16, 2)的column改為DECIMAL(16, 4)等,均不能使用上述語句修改,另外改為不同的類型,也需要先drop掉column。

3.去掉欄位

alter table [table_name] drop column [column_name]

注意:drop掉欄位之後,可能會導致表查詢/插入操作不能執行,需要對錶進行reorg。

4.為欄位添加預設值

alter table [table_name] alter column [column_name] set default [value]

5. 添加帶預設值的欄位

alter table [table_name] add column [column_name] [column_type] not null with default [value]

6. 設定欄位預設時間為目前時間

alter table [table_name] alter column [column_name] set default  current date; default current date;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.