使用以下查询,我试图了解为什么我能够在一个视图上获取 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 而不是在另一个上。有任何想法吗?