熱線電話:13121318867

登錄
首頁大數據時代如何用SQL語句添加和修改字段?
如何用SQL語句添加和修改字段?
2020-07-09
收藏

SQL語句添加字段并不難,下面小編整理了SQL添加和修改字段的基本命令,希望對各位小伙伴有所幫助。

增加字段

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

在指定位置插入新字段:

alter table 表名 add [column] 字段字段類型 是否可為空 comment '注釋' after 指定某字段 ;

刪除字段

alter table 表名 drop column 字段名;

修改字段名:

alter table 表名 rename column A to B

修改字段類型:

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

修改字段默認值:

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='字段名'

根據約束名稱刪除約束

alter table 表名 drop constraint 約束名

根據表名向字段中增加新的默認值

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

數據分析咨詢請掃描二維碼

若不方便掃碼,搜微信號:CDAshujufenxi

數據分析師資訊
更多

OK
客服在線
立即咨詢
日韩人妻系列无码专区视频,先锋高清无码,无码免费视欧非,国精产品一区一区三区无码
客服在線
立即咨詢