[VIEWED 3473
TIMES]
|
SAVE! for ease of future access.
|
|
|
the_hareeb
Please log in to subscribe to the_hareeb's postings.
Posted on 09-29-10 4:07
PM
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
I need to track some client program's query for index recommendations from Database Tuning advisor. For that I am using SQL server Profiler and exporting the table to Database Tuning Advisor.
How do I get the SPID of my client program so that I can filter that client program in profiler.
thanks for help.
|
|
|
|
alwayshappy
Please log in to subscribe to alwayshappy's postings.
Posted on 09-29-10 5:16
PM [Snapshot: 12]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
You might want to run the query below in your client's db SELECT @@SPID AS 'ID', SYSTEM_USER AS 'Login Name', USER AS 'User Name' Hope that is what you are looking for...
|
|
|
virusno1
Please log in to subscribe to virusno1's postings.
Posted on 09-29-10 5:22
PM [Snapshot: 18]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
AlwaysHappy, Your query is not correct. @@SPID gives you the current SPID of the user. So You will give only one spid always. Here is the complete query.
IF EXISTS (SELECT * FROM tempdb.sys.objects WHERE object_id = Object_id('Tempdb.dbo.#cLIENTsPID')) DROP TABLE #clientspid
CREATE TABLE #clientspid ( spid VARCHAR(10), [status] VARCHAR(20), [login] VARCHAR(100), [hostname] VARCHAR(100), blkby VARCHAR(10), dbname VARCHAR(100), command VARCHAR(100), cputime INT, diskio INT, lastbatch VARCHAR(100), programname VARCHAR(100), spid1 INT, requestid INT)
INSERT INTO #clientspid EXEC Sp_who2
SELECT spid, hostname, ProgramName FROM #clientspid WHERE hostname NOT IN (' .',@@SERVERNAME)
Last edited: 29-Sep-10 05:26 PM
|
|
|
the_hareeb
Please log in to subscribe to the_hareeb's postings.
Posted on 09-29-10 11:16
PM [Snapshot: 68]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
thanks guys.. will try this tomorrow.
virus,a quesitron for you.. IF EXISTS (SELECT * FROM tempdb.sys.objects WHERE object_id = Object_id('Tempdb.dbo.#cLIENTsPID')) DROP TABLE #clientspid
what does this do? Since we have '#', this means the table #cLIENTsPID will be dropped automatically once the session is over right? so why do we need to drop it. also what does this if exists section do.
if i understand it correctly, your script just creates a table from sp_who2. Please help me understand. Your help is appreciated. Sorry I am new to DBA.
thanks
|
|
|
virusno1
Please log in to subscribe to virusno1's postings.
Posted on 09-30-10 10:39
AM [Snapshot: 96]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
hareeb, If exists with condition makes sure that temp table is not created already. This is the best practice while creating any temp table. and Yes temp table is a session label variable. It will be destroyed when your session close. I dropped the table table because what if you need to run that command again and again (like with 10 minute interval). Write a extra few extra lines for code doesn't harm at all :). Well, you will soon understand the importance of if Exist when you write a big queries for production dbs and best of luck for that
|
|
|
the_hareeb
Please log in to subscribe to the_hareeb's postings.
Posted on 09-30-10 1:27
PM [Snapshot: 108]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
thanks for the clarification virus. I am new to this, do you suggest any books, tutorials? I am currently looking at index tuning, fill factors etc.
|
|