tags:

views:

5541

answers:

4

Is there a way to tell SQL Server 2008 Express to log every query (including each and every SELECT Query!) into a file?

It's a Development machine, so the negative side effects of logging Select-Queries are not an issue.

Before someone suggests using the SQL Profiler: This is not available in Express (does anyone know if it's available in the Web Edition?) and i'm looking for a way to log queries even when I am away.

+1  A: 

You can log changes. SQL Server 2008 will make this especially easy with Change Data Capture. But SQL Server isn't very good at logging SELECTs.

It is theoretically possible with the profiler, but it will kill your performance. You might "get away with it" on your desktop, but I think you'll notice your machine acting slow enough to cause problems. And it definitely won't work after any kind of deployment.

One important point a couple others have missed already: unless they changed something for 2008 I didn't hear about, you can't trigger a SELECT.

Joel Coehoorn
Thanks. Well, this is a development machine, so Performance is not an issue if I can turn on/off that feature. Capturing Selects in Production environments seems like a recipe for disaster anyway.
Michael Stum
A: 

I would either use triggers or use a third party software such as Red Gate to check out your SQL log files.

Jason N. Gaylord
Red Gate Log Rescue only delivers inserts, updates and deletes.
Forgotten Semicolon
+15  A: 

SQL Server Profiler:

  • File->New Trace
  • The "General" Tab is displayed.
  • Here you can choose "Save to file:" so its logged to a file.
  • View the "Event Selection" Tab
  • Select the items you want to log.
  • TSQL->SQL:BatchStarting will get you sql selects
  • Stored Procedures->RPC:Completed will get you Stored Procedures.

More information from Microsoft: SQL Server 2008 Books Online - Using SQL Server Profiler

Update - Express Edition:

A comment was made that MS SQL Server Profiler is not available for the express edition.
Their does appear to be a free alternative: Profiler for Microsoft SQL Server 2005 Express Edition

KyleLanser
Thanks. Not available in Express though :-(
Michael Stum
I have not personally tried this, but here it is: Profiler for Microsoft SQL Server 2005 Express Edition http://sqlprofiler.googlepages.com/
KyleLanser
When I get to work tomorrow I will try out that alternative program against mssql 2008.
KyleLanser
The tool I Suggested does not currently support 2008, but I downloaded the source code, updated the project references to reference the 2008 sdk and then the application worked. I've emailed the maintainer to request he update the project.
KyleLanser
Update: (1.) The tool does not appear to support saving the log to a file. (2.) If you want help getting the source code, and updating the tool to work for you, email me at [email protected]
KyleLanser
I've tried the free tool and it doesn't seem to show me the actual SQL queries. Just how long they took. May be using it wrong though.
Richard
A: 

Seems that you can create traces using T-SQL

http://support.microsoft.com/kb/283790/

That might help.

Jason Glover