June 18, 2008 at 11:59 pm
hello.
is there a way to get the Global TempTable names created in the session.
..>>..
MobashA
June 19, 2008 at 2:24 am
[font="Verdana"]Such temporary objects gets stored into TempDB database. you will get it from there.
Select * From sysobjects where Name = '{temp table name}'
Mahesh[/font]
MH-09-AM-8694
June 19, 2008 at 3:47 am
????
if u know the temptableName '{temp table name}'
then i dont need to search for the temptableName '{temp table name}'
..>>..
MobashA
June 19, 2008 at 4:09 am
Hi
Try use this query:
select name from tempdb..sysobjects where name LIKE '#%'
This should select all temptables in the session.
June 19, 2008 at 9:40 am
this wont help cos i need to get the user name or the session id for the user how created this temp table.
..>>..
MobashA
June 19, 2008 at 10:08 am
From a best practices standpoint, I'd shy away from using global temp tables. They cause more headaches than help. What exactly are you trying to do? Can you give us a little more background on the purpose of the table, how it is getting created, what you are planning on doing with it?
June 19, 2008 at 10:22 am
i have a system our company use, and i need to do some modifications in the backround.
the system create a temptable named dynamiclly.
so i need to get the temptable created by the user session....
..>>..
MobashA
June 19, 2008 at 10:42 am
Well, here's the catch. You can't create a global temporary table without explicitly using the CREATE TABLE ## statement. So how, when they create the table, do they come up with the name? They've got to be using some sort of pattern or algorithm to come up with the name. If you can't somehow narrow down the name to ensure that you grabbing the correct global temp table, you're in trouble.
June 19, 2008 at 1:56 pm
i really wish if i could do so, but i have spent soo much time on it, i just solved 10% from it..
u know, i dont post something here unless i found no solution.
thanks...
..>>..
MobashA
June 20, 2008 at 9:30 am
I understand that you've only posted this becuase you've ran into a roadblock. All I'm saying is that in order to find the table, you have to be able to identify which table to grab. If you had 10 sessions open to the database that all had global temp tables open, how to you know that you are getting the right one?
The processes that create these tables have to intellegently name them so that another process does not attempt to create a global temp table with the same name. So there must be a method or pattern that they are using to create the name and in order for you to make sure that you are getting the right global temp table, you too must have some way to identify the table.
Have you tried to run Profiler against the application and pick up the CREATE TABLE ## statement? If you were to run the app and wait until it reached the point to where it uses the table and run a SELECT * FROM tempdb..sysobjects WHERE xtype = 'U' what would that return?
June 20, 2008 at 3:19 pm
Try this to determine if it gives you enough information, using any database on the server (preferably a development db NOT a production db
CREATE TABLE ##MyTempTable (cola INT PRIMARY KEY)
INSERT INTO ##MyTempTable VALUES (1)
WAITFOR DELAY '0:05'; -- delay for 5 minutes for testing
In ANOTHER query window in SSMS execute the following T-SQL:
USE Tempdb
GO
SELECT * FROM sys.sysobjects WHERE Type = 'U'
Check BOL for the definition of the columns returned.
June 20, 2008 at 3:44 pm
Using BOL partial definition of column in sys.sysobjects
Name Type Descripition
uid smallint Schema ID of the owner of the object.
For databases upgraded from an earlier
version of SQL Server, the schema ID is
equal to the user ID of the owner.
June 20, 2008 at 10:16 pm
Mobasha,
I'm pretty sure what you ask cannot be done. You would have to capture the session name at the time of creation of the global temp table or something similar. Sorry...
--Jeff Moden
Change is inevitable... Change for the better is not.
June 21, 2008 at 4:11 am
althoug u have said that i cant, but it is a good sanwer i will use.
thanks
..>>..
MobashA
June 21, 2008 at 8:14 am
Mobasha,
To be true, there is a UID (User ID) column in the TempDB..SysObjects comapatibility view of SQL Server 2005... it's not the ID of the person that made it, though... it's the ID of the table owner. If you have an application where everyone is considered to be "SA" or "DBO" it won't do you much good. You can see all of the ## and # objects there... I just don't see anything to identify a SPID or anything else that relates to a session that created the table.
I know the system knows because it has to so it knows when to drop it... I'm just pretty sure there's no way for us to know programatically.
I'll keep looking...
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 15 posts - 1 through 14 (of 14 total)
You must be logged in to reply to this topic. Login to reply