ODBC 错误: [Microsoft][ODBC SQL Server Driver][SQL Server]无法将 NULL 值插入列 'Online',表 'TEST.dbo.Tmp_Members';该列不允许空值。INSERT 失败。
[Microsoft][ODBC SQL Server Driver][SQL Server]语句已终止。表是几天前创建的,而且里面也已经有了数据。
现在要给该表增加一个不为空的字段,以前的数据项可以让该字段为0。
请问我怎样才能在给这张表增加字段,并且将以前数据项的该字段设为0.
[Microsoft][ODBC SQL Server Driver][SQL Server]语句已终止。表是几天前创建的,而且里面也已经有了数据。
现在要给该表增加一个不为空的字段,以前的数据项可以让该字段为0。
请问我怎样才能在给这张表增加字段,并且将以前数据项的该字段设为0.
if object_id('tempdb.dbo.#1') is not null drop table #1
create table #1([dd] int)
insert #1
select 1 union all
select 2 union all
select 3 select * from #1alter table #1
add tt varchar(2) not null default 0
两者之间的是矛盾的。
你的需求不太合理,由于是新增字段,你为什么不能为null呢。
解决方法:建立新表,将以前数据导入
e.g:
select a,b,c ----a,b,c表示以前字段
,0-----表示新增字段的默认值
from tb into newTB
add newcol int not null default 0
--add newcol varchar(50) not null default '0'