Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server Query log for failed/incorrect queries?

I am using SQL Server 2008 and I would like to know if there's a way to find invalid SQL queries that have been executed in a database. For example:

SELECT * FROM NonExistingTable

...where the database didn't exist or a SELECT/INSERT/UPDATE with incorrect syntax.

like image 336
Joe Avatar asked Sep 14 '11 12:09

Joe


People also ask

Which SQL Server logs shows informational and error events?

The Application event log is used to log application-specific events, such as Internet Information Server or SQL Server. You can find the Event Viewer tool under the Start menu in Windows, under the Administrative Tools option.


1 Answers

SQL Server doesn't keep a log of these things, so if you want to capture them you'll have to do so using a server-side trace with a filter to only capture statements with errors. It will be quite an expensive trace, and you'll get some false positives if you do things like RAISERROR WITH NOWAIT... I guess it's easier than implementing TRY/CATCH everywhere and logging the errors yourself?

There may be ways to do it with SQL Server Audit (depending on your edition) or Extended Events but I haven't tried to do this specific thing with either...

like image 56
Aaron Bertrand Avatar answered Oct 05 '22 23:10

Aaron Bertrand