I've made an attempt to generate a complete repro (i.e. everything created from scratch), but it does not reproduce the issue. Note that object ids are generated in the same sequence (based on the starting point in model) in newly created databases, so creating two new databases and creating a new object in each will result in the same object ids. Although creating a view seems to increment by 2 values, so I actually have to create 2 views in DB1 and 1 view in DB2 to get the same values.
I tried with statement cache both on and off, and on 15.7 SP100 and 122 Solaris.
Mike, you might see if you can reproduce the behavior on your system using this script (or with any modifications you see fit.
Obviously alter the script if you really have databases named DB1 or DB2.!
Cheers,
-bret
use master
go
drop database DB1
go
drop database DB2
go
create database DB1
create database DB2
go
use DB1
go
-- dummy necessary to align object ids.
create procedure dummy as print "dummy"
go
create procedure p1 as print "p1"
go
select object_id("p1")
go
use DB2
go
create view view_name as select top 2 name from sysobjects
go
select object_id("view_name")
go
use tempdb
go
drop procedure ValidateData
go
create procedure ValidateData
@DBName varchar(32),
@TableName varchar(32),
@sqlWhereClause varchar(200)
as
begin
declare @TableFullNameSource varchar(1000),
@sqlStart varchar(1000),
@sqlFrom varchar(1000)
select @TableFullNameSource= @DBName + ".." + @TableName
select @sqlStart = 'select * ',
@sqlFrom = ' from ' + @TableFullNameSource
+ ' ' + coalesce(@sqlWhereClause, '')
print "%1!, %2!", @sqlStart, @sqlFrom
exec (@sqlStart + @sqlFrom)
end
go
execute ValidateData "DB2", 'view_name' , null
go
select @@version
go