如果您在 SQL Server 中使用“插入”创建临时表,它会使用第一个插入来确定列是否接受空值。如果第一个插入具有空值,则该列可以为空,否则它将不可为空。
有没有办法使用“插入”来创建临时表来接受空值?
例子
这工作没有任何问题
Select 'one' as a , null as b
into #temp
insert into #temp
Select 'two' as a , 500 as b
但是,这会引发“无法将值 NULL 插入到列‘b’中”
Select 'one' as a , 500 as b
into #temp
insert into #temp
Select 'two' as a , null as b
我知道我可以做create Table
或alter column
声明,但我想在不重写数百个现有查询的情况下做到这一点。