SQL SERVER在添加新字段的时候要求可以为空,但是如果要添加非空的新字段呢?
可以执行下面的语句:
alter table [table] add NewColumn int --添加一个可以为空的新列
go
update [table] set NewColumn=0 --设置新列的值为0
go
ALTER TABLE [table] ALTER COLUMN
NewColumn int not null --设置新列为非空
SQL SERVER在添加新字段的时候要求可以为空,但是如果要添加非空的新字段呢?
可以执行下面的语句:
alter table [table] add NewColumn int --添加一个可以为空的新列
go
update [table] set NewColumn=0 --设置新列的值为0
go
ALTER TABLE [table] ALTER COLUMN
NewColumn int not null --设置新列为非空