SQL Server 2008 – How to Validate Multiple SQL Statements for Correctness

sql-server-2008

I have about 150 reports generated from SQL statements. These reports are saved independently from the server. Some generated from sprocs, some from table-valued functions, but mostly just SQL statements.

Now the server goes through a big refactoring of tables and sprocs. And I need a way to validate that all the reports are still running, as it is possible the changes will break the reports.

One way to validate that all the reports are valid – run them and lookout for errors.

The problem – some of the reports are very heavy and include aggregation of of many tables with many joins with millions of records.

Is there a way to validate SQL statements without actually executing them?

I'm working with SQL Server 2008 and have ability to apply C# processing to the statements. Ideally I'd like a way to validate the reports often and without much effort, i.e. 10 times a day. So making a schema-only copy of DB is not an option.

Best Answer

There's the table sys.sysdepends which will help with your stored objects.

For embedded SQL you could SET ROWCOUNT for the batch. This will terminate the query after compilation (and hence name resolution and object binding) but before large quantities of data are processed.