考虑以下代码
use tempdb
go
drop table if exists ImportTest1;
create table ImportTest1 (
Column1 int null,
Column2 int null,
NewColumn int null
);
insert into ImportTest1 select 1,2,3 union select 4,5,6;
select * from ImportTest1;
drop table if exists DestinationTest1;
create table DestinationTest1 (
Column1 int null,
Column2 int null
);
select * from DestinationTest1;
GO
CREATE OR ALTER VIEW TestView1 AS
SELECT Column1 AS Column1, Column2 AS Column2, NULL AS NewColumn FROM DestinationTest1
GO
如果我们运行这个
INSERT INTO TestView1 (Column1, Column2, NewColumn)
SELECT Column1, Column2, NewColumn FROM ImportTest1
它失败并出现错误
Update or insert of view or function 'TestView1' failed because it contains a derived or constant field.
但是,如果我通过 BCP 做同样的事情,它工作正常
BCP "SELECT Column1, Column2, NewColumn FROM tempdb..ImportTest1" QUERYOUT C:\BCPTest\test.txt -T -c -t,
BCP tempdb..TestView1 IN C:\BCPTest\test.txt -T -c -t,
这里发生了什么,允许 BCP 通过视图成功导入,但我们不能手动运行它?