使用以下查询,我试图理解为什么我能够在一个视图上获取ident_current,而不是另一个视图。
以下是一些示例数据:
create table temptable1 (id int identity(1,1), name varchar(100), [type] int)
insert into temptable1 values
( 'apple', 1),
( 'banana', 1),
( 'cake', 3)
create table temptable2 (id int identity(1,1), name varchar(100))
insert into temptable2 values
( 'fruit'),
( 'vegetable'),
( 'pastry')
exec ('
create view dbo.identcurrentworks
as
select
t1.id as t1id
,t1.name as t1name
,t1.type as t1type
from temptable1 t1
')
--drop view dbo.identcurrentworks
exec ('
create view dbo.identcurrentdoesnotwork
as
select
t1.id as t1id,
t1.name as t1name,
t1.type,
t2.id as t2id,
t2.name as t2name
from temptable1 t1
join temptable2 t2 on t1.type=t2.id
')
--drop view dbo.identcurrentdoesnotwork
select * from dbo.identcurrentworks
select IDENT_CURRENT('dbo.temptable1')
select IDENT_CURRENT('dbo.identcurrentworks')
select * from dbo.identcurrentdoesnotwork
select IDENT_CURRENT('dbo.temptable2')
select IDENT_CURRENT('dbo.identcurrentdoesnotwork')
--drop table temptable1
--drop table temptable2
我不确定为什么我可以在视图dbo.identcurrentworks上获取ident_current而不是另一方面。有什么想法吗?