SQL server 中有什么函数可以为非空的值设置默认值?
coalesce可以为为空的列设置默认 coalesce(name,' ')
有什么函数是反过来,可以在非空的时候设置默认值?
[解决办法]
if object_id('tb','U') is not null drop table tbgocreate 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 @tselect 'a' union allselect 'b' union allselect null union allselect 'c' union allselect 'd' union allselect nullselect col=isnull(replace(col,col,'1'),'0') from @t/*col------110110*/