2

I have a legacy db from an application that is no longer supported. I'm trying to deconstruct a stored procedure to make a modification, but I can't figure out where #tempimport is located. I've searched high and low through the schema, but I'm not finding anything close. This is how it's used:

 SET NOCOUNT ON;
 DECLARE @saleid UNIQUEIDENTIFIER
 SELECT TOP 1 @saleid = [sale_id] FROM #tempimport;

Is this a T-SQL specific thing, or can I actually find the data in this table somewhere?

Roger
  • 51
  • 4
  • Is there a procedure that calls the one you are trying to evaluate? You could try something like redgate's sql search to find where it is being created. – Sean Lange Apr 22 '16 at 17:03

3 Answers3

1

Tables that are prefixed with a # are temporary tables that are created in the tempdb system database.

Ola Ekdahl
  • 1,484
  • 1
  • 11
  • 21
1

Tables with the # preceding the name are temporary tables.

You can find them in the tempdb database under System Databases

Nathan Koop
  • 24,803
  • 25
  • 90
  • 125
0
  • try to find code of this table creation in you DB schema


select * from information_schema.routines
where object_definition(object_id(routine_name)) like '%#tempimport%'
  • try find #tempimport in schemas of neighboring DBs
  • try find #tempimport in your application sources if exists.
  • try to profile(SQL Profiler tool) your application and search #tempimport here.

Additional

  • #tempimport can be created by any connected application. Not only from your DB runnable code
  • you can research deeper and try to monitoring the moment of #tempimport creation. Example


select left(name, charindex('_',name)-1) 
from tempdb..sysobjects
where charindex('_',name) > 0 and
xtype = 'u' and not object_id('tempdb..'+name) is null
and left(name, charindex('_',name)-1)  = '#tempimport'

source: Is there a way to get a list of all current temporary tables in SQL Server?

Community
  • 1
  • 1
Alexey
  • 31
  • 4