这在SQL Server 2008中不起作用:

ALTER TABLE Employee ALTER COLUMN CityBorn SET DEFAULT 'SANDNES'

错误是:

关键字“SET”附近的语法错误。

我做错了什么?


当前回答

ALTER TABLE [dbo].[Employee] ADD  DEFAULT ('N') FOR [CityBorn]

其他回答

试试下面的命令;

ALTER TABLE Person11
ADD CONSTRAINT col_1_def
DEFAULT 'This is not NULL' FOR Address
ALTER TABLE [dbo].[Employee] ADD  DEFAULT ('N') FOR [CityBorn]

这将在SQL Server工作:

ALTER TABLE Employee ADD CONSTRAINT DF_SomeName DEFAULT N'SANDNES' FOR CityBorn;
ALTER TABLE Employee ADD DEFAULT 'SANDNES' FOR CityBorn

刚刚发现3个简单的步骤来改变已经存在的列,之前是空的

update   orders
set BasicHours=0 where BasicHours is null

alter table orders 
add default(0) for BasicHours

alter table orders 
alter  column CleanBasicHours decimal(7,2) not null