日期:2014-05-18 浏览次数:20640 次
if object_id('tb','U') is not null
drop table tb
go
create table tb
(
id int identity(1,1),
name varchar(10),
age int not null default 10 --非空,默认值是10
)
go
------解决方案--------------------
如果说表字段中没有数据进入的时候添加默认值的话,用default就可以了。
但是字段有了default是不会出现null的情况的。
declare @t table (col varchar(1))
insert into @t
select 'a' union all
select 'b' union all
select null union all
select 'c' union all
select 'd' union all
select null
select col=isnull(replace(col,col,'1'),'0') from @t
/*
col
------
1
1
0
1
1
0
*/