Interesting.
I modified the supplied code to get the # of tempdb objects, and all tempdb table names:
use AdventureWorks
go
select count(*) from tempdb.sys.objects
select name from tempdb.sys.tables --where name like '%tableA%'
declare @tableA TABLE(col1 int, col2 int)
--stmt 1
select name from tempdb.sys.tables --where name like '%tableA%'
--stmt 2
select name from tempdb.sys.columns where name like 'col1%'
select count(*) from tempdb.sys.objects
and I find that there are no new tables or objects between the two selects from sys.tables.
So I modified the sys.columns select to:
select sc.name [ColName], st.name [TableName]
from tempdb.sys.columns sc
INNER JOIN tempdb.sys.tables st ON st.object_id = sc.object_id
where sc.name like 'col1%'
What I'm seeing is that the tablename for this table is already in use before the table is declared. I've even tried stopping and restarting the sql service for this instance.
What's up with this?
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes