字段操作

1、修改字段名:

alter table 表名 rename column A to B

2、修改字段類型:

alter table 表名 alter column 字段名 type not null

3、修改字段默認值

alter table 表名 add default (0) for 字段名 with values

如果字段有默認值,則需要先刪除字段的約束,在添加新的默認值,

select c.name from sysconstraints a

inner join syscolumns b on a.colid=b.colid

inner join sysobjects c on a.constid=c.id

where a.id=object_id('表名')

and b.name='字段名'

根據(jù)約束名稱刪除約束

alter table 表名 drop constraint 約束名

根據(jù)表名向字段中增加新的默認值

alter table 表名 add default (0) for 字段名 with values

4、增加字段:

alter table 表名 add 字段名 type not null default 0

5、刪除字段:

alter table 表名?drop column 字段名;

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容