Sql Server 增長字段、修改字段、修改類型、修改默認值

一、修改字段名:post

  alter table 表名 rename column A to Bblog

二、修改字段類型:it

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

三、修改字段默認值
  alter table 表名 add default (0) for 字段名 with valuesclass

  若是字段有默認值,則須要先刪除字段的約束,在添加新的默認值,object

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

  根據約束名稱刪除約束tab

  alter table 表名 drop constraint 約束名di

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

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

四、增長字段:

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

五、刪除字段:

  alter table 表名 drop column 字段名;

相關文章
相關標籤/搜索