使用 SELECT * INTO 时收到不可为 NULL 的警告
Getting a non-NULL-able warning when using SELECT * INTO
当我执行以下过程时,我收到此警告:
Attempting to set a non-NULL-able column's value to NULL.
USE [DbTwo]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
alter proc [dbo].[TEST_warning_proc]
as
IF OBJECT_ID('MySchema..vitals', 'U') IS NOT NULL DROP TABLE MySchema..vitals
IF OBJECT_ID('MySchema..order_list', 'U') IS NOT NULL DROP TABLE MySchema..order_list
select * into MySchema..vitals
from DbOne..vitals
where FacilityID in
(select FacilityID from DbTwo..MySchemaFacilities)
select * into MySchema..order_list
from DbOne..order_list
where FacilityID in
(select FacilityID from DbTwo..MySchemaFacilities)
这怎么可能,因为我正在做 SELECT * INTO?难道不应该创建一个完全反映原始 table 的新 table 吗?
我试过设置:
SET ANSI_WARNINGS OFF
但这并没有帮助。
我怀疑您的 table 没有被丢弃--maybe there is a block going on 因为这个辅助函数。您可以通过在尝试删除它后立即放置 select top 1 * from vitals
来验证该理论。使用 sys.objects
可以避免这种情况。
使用sys.objects
create table dbo.vitals (c1 int not null)
insert into vitals
values
(1)
if exists(SELECT 1 FROM sys.objects WHERE name = N'vitals')
begin
drop table vitals
end
select null as c1 into vitals
select * from vitals
我发现了问题...
当我 "sanitizing" 在这里发帖时,我使用了名字
from DbOne..vitals
和
from DbOne..order_list
这两个对象实际上是 views 而不是 tables。我从视图的定义中尝试 运行 原来的 SELECT 并得到:
Null value is eliminated by an aggregate or other SET operation.
糟糕...抱歉。
当我执行以下过程时,我收到此警告:
Attempting to set a non-NULL-able column's value to NULL.
USE [DbTwo]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
alter proc [dbo].[TEST_warning_proc]
as
IF OBJECT_ID('MySchema..vitals', 'U') IS NOT NULL DROP TABLE MySchema..vitals
IF OBJECT_ID('MySchema..order_list', 'U') IS NOT NULL DROP TABLE MySchema..order_list
select * into MySchema..vitals
from DbOne..vitals
where FacilityID in
(select FacilityID from DbTwo..MySchemaFacilities)
select * into MySchema..order_list
from DbOne..order_list
where FacilityID in
(select FacilityID from DbTwo..MySchemaFacilities)
这怎么可能,因为我正在做 SELECT * INTO?难道不应该创建一个完全反映原始 table 的新 table 吗?
我试过设置:
SET ANSI_WARNINGS OFF
但这并没有帮助。
我怀疑您的 table 没有被丢弃--maybe there is a block going on 因为这个辅助函数。您可以通过在尝试删除它后立即放置 select top 1 * from vitals
来验证该理论。使用 sys.objects
可以避免这种情况。
使用sys.objects
create table dbo.vitals (c1 int not null)
insert into vitals
values
(1)
if exists(SELECT 1 FROM sys.objects WHERE name = N'vitals')
begin
drop table vitals
end
select null as c1 into vitals
select * from vitals
我发现了问题...
当我 "sanitizing" 在这里发帖时,我使用了名字
from DbOne..vitals
和
from DbOne..order_list
这两个对象实际上是 views 而不是 tables。我从视图的定义中尝试 运行 原来的 SELECT 并得到:
Null value is eliminated by an aggregate or other SET operation.
糟糕...抱歉。