1. 程式人生 > >SQL server 新增、修改、刪除欄位

SQL server 新增、修改、刪除欄位

1、新增欄位

alter table 表名 add 欄位名 type not null default 0

2、修改欄位名

alter table 表名 rename column A to B

3、修改欄位型別

alter table 表名 modify column UnitPrice decimal(18, 4) not null 

4、修改欄位預設值

alter table 表名 drop constraint 約束名字   ------說明:刪除表的欄位的原有約束

alter table 表名 add constraint 約束名字 DEFAULT 預設值 for 欄位名稱 -------說明:新增一個表的欄位的約束並指定預設值

5、刪除欄位

alter table 表名 drop column 欄位名;