Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Using Profiler to capture database name and object

 
   Database Help (Home) -> Tools RSS
Next:  cant see one of my databses when logging in as sa..  
Author Message
Snake

External


Since: Jan 21, 2007
Posts: 27



(Msg. 1) Posted: Mon Dec 01, 2008 2:45 pm
Post subject: Using Profiler to capture database name and object
Archived from groups: microsoft>public>sqlserver>tools (more info?)

I need to setup profiler to capture which databases are being used and which
tables in those databases are being accessed. For the life of me I can not
get profiler to cough-up this info! It should be easy!!!! But Databasename
and object name are always blank.

Any suggestions?

 >> Stay informed about: Using Profiler to capture database name and object 
Back to top
Login to vote
Andrew J. Kelly

External


Since: Sep 01, 2003
Posts: 551



(Msg. 2) Posted: Mon Dec 01, 2008 9:12 pm
Post subject: Re: Using Profiler to capture database name and object [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Use the database ID not the name but the Object Id is not that simple. What
object do you expect it to show? What if you are joining 10 tables? The
way to tell what is being accessed is to use the Index related DMV's such as
sys.dm_db_index_usage_stats & ys.dm_db_index_operational_stats. Here are a
few examples:

DECLARE @dbid INT
SELECT @dbid = DB_ID()

SELECT OBJECT_NAME(s.object_id) AS [objectname], s.object_id, i.name AS
[indexname], i.index_id
, user_seeks, user_scans, user_lookups, user_updates
FROM sys.dm_db_index_usage_stats AS s INNER JOIN sys.indexes AS i
ON i.object_id = s.object_id AND i.index_id = s.index_id
WHERE database_id = @dbid AND OBJECTPROPERTY(s.object_id,'IsUserTable') = 1
ORDER BY (user_seeks + user_scans + user_lookups + user_updates) ASC

DECLARE @dbid INT

SELECT @dbid = DB_ID()

SELECT objectname=OBJECT_NAME(s.object_id), indexname=i.name, i.index_id
, reads=range_scan_count + singleton_lookup_count
, 'leaf_writes'=leaf_insert_count+leaf_update_count+
leaf_delete_count
, 'leaf_page_splits' = leaf_allocation_count
, 'nonleaf_writes'=nonleaf_insert_count + nonleaf_update_count +
nonleaf_delete_count
, 'nonleaf_page_splits' = nonleaf_allocation_count
FROM sys.dm_db_index_operational_stats (@dbid,NULL,NULL,NULL) s,
sys.indexes i
WHERE OBJECTPROPERTY(s.object_id,'IsUserTable') = 1
AND i.object_id = s.object_id
AND i.index_id = s.index_id
ORDER BY reads DESC

--
Andrew J. Kelly SQL MVP
Solid Quality Mentors


"Snake" wrote in message

>I need to setup profiler to capture which databases are being used and
>which
> tables in those databases are being accessed. For the life of me I can not
> get profiler to cough-up this info! It should be easy!!!! But
> Databasename
> and object name are always blank.
>
> Any suggestions?
>
>

 >> Stay informed about: Using Profiler to capture database name and object 
Back to top
Login to vote
Snake

External


Since: Jan 21, 2007
Posts: 27



(Msg. 3) Posted: Tue Dec 02, 2008 8:46 am
Post subject: Re: Using Profiler to capture database name and object [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

I appoligize for not stating that I am using SS2000, so the fine query below
does not work. I am trying to use profiler to do a similar thing. My gut
feeling is that since all the "name" fields in profiler are always blank that
I just have to live with it. But I still need to report to my boss which
databases and tables are being accessed.

Thanks

"Andrew J. Kelly" wrote:

> Use the database ID not the name but the Object Id is not that simple. What
> object do you expect it to show? What if you are joining 10 tables? The
> way to tell what is being accessed is to use the Index related DMV's such as
> sys.dm_db_index_usage_stats & ys.dm_db_index_operational_stats. Here are a
> few examples:
>
> DECLARE @dbid INT
> SELECT @dbid = DB_ID()
>
> SELECT OBJECT_NAME(s.object_id) AS [objectname], s.object_id, i.name AS
> [indexname], i.index_id
> , user_seeks, user_scans, user_lookups, user_updates
> FROM sys.dm_db_index_usage_stats AS s INNER JOIN sys.indexes AS i
> ON i.object_id = s.object_id AND i.index_id = s.index_id
> WHERE database_id = @dbid AND OBJECTPROPERTY(s.object_id,'IsUserTable') = 1
> ORDER BY (user_seeks + user_scans + user_lookups + user_updates) ASC
>
> DECLARE @dbid INT
>
> SELECT @dbid = DB_ID()
>
> SELECT objectname=OBJECT_NAME(s.object_id), indexname=i.name, i.index_id
> , reads=range_scan_count + singleton_lookup_count
> , 'leaf_writes'=leaf_insert_count+leaf_update_count+
> leaf_delete_count
> , 'leaf_page_splits' = leaf_allocation_count
> , 'nonleaf_writes'=nonleaf_insert_count + nonleaf_update_count +
> nonleaf_delete_count
> , 'nonleaf_page_splits' = nonleaf_allocation_count
> FROM sys.dm_db_index_operational_stats (@dbid,NULL,NULL,NULL) s,
> sys.indexes i
> WHERE OBJECTPROPERTY(s.object_id,'IsUserTable') = 1
> AND i.object_id = s.object_id
> AND i.index_id = s.index_id
> ORDER BY reads DESC
>
> --
> Andrew J. Kelly SQL MVP
> Solid Quality Mentors
>
>
> "Snake" wrote in message
>
> >I need to setup profiler to capture which databases are being used and
> >which
> > tables in those databases are being accessed. For the life of me I can not
> > get profiler to cough-up this info! It should be easy!!!! But
> > Databasename
> > and object name are always blank.
> >
> > Any suggestions?
> >
> >
>
>
 >> Stay informed about: Using Profiler to capture database name and object 
Back to top
Login to vote
Erland Sommarskog2

External


Since: May 30, 2004
Posts: 2061



(Msg. 4) Posted: Tue Dec 02, 2008 2:28 pm
Post subject: Re: Using Profiler to capture database name and object [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Snake (Snake@discussions.microsoft.com) writes:
> I appoligize for not stating that I am using SS2000, so the fine query
> below does not work. I am trying to use profiler to do a similar thing.
> My gut feeling is that since all the "name" fields in profiler are
> always blank that I just have to live with it. But I still need to
> report to my boss which databases and tables are being accessed.

For the database, use DatabaseID as Andrew mentioned.

To get the tables, you will have to parse the queries.

You are probably better off running a server-side trace and then use
fn_trace_gettable to read the trace file. You can easily get the script
for a server-side trace by exporting what you have in Profiler.


--
Erland Sommarskog, SQL Server MVP, esquel.DeleteThis@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
 >> Stay informed about: Using Profiler to capture database name and object 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
SQL 2005 profiler : how to specify particular database in .. - In SQL 2005 profiler, how to specify particular database on the server box to trace?

SQL Profiler - I have about 1000 profiler trace files that I need to load into a table. Is there any way to do a mass load? I know I can open each trace and do a "save as" and then save it to a table. I want to do more than one table at a time.

SQL Profiler - I can never seem to get the filters to work in SQL Profiler. I've tried to set HOSTNAME and NTUSERNAME to mine however when I run the trace all connection request are shown. Am I missing something??? Thanks -- ____________________________________..

Basic Profiler question - Not too familiar with SQL Profiler in SQL2000 sp4. Our issue is that the CPU is spiking on our SQL Server and slow response time for one database in particular. I've run some profiler traces capturing execution plans and filtering for a particular..

Need help from Gurus: Profiler columns - Please help me understand "duration", "starttime", and "endtime" columns in trace tables. The most confusing part is that the duration does not match with starttime and endtime. I started a proviler and had results stored ...
   Database Help (Home) -> Tools All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]