Execute SQL on Multiple Tables/Columns - New Feature in SQL Server 2000 (Page 1 of 6 )
The base idea of this article is to leverage the running of SQL Statements, Stored Procedures, User Defined Functions or a set of SQL Statements on every/required tables and on every/required columns in the Database.
You may have had a requirement in which you needed to add/edit/delete/search data in column(s) on more than one table using a single SQL statement; perhaps you ended up writing a procedure/function for achieving just that. Now you can be equipped with the SP_execSQLonDB stored procedure that runs the SQL Statement(s)/Procedure/Function on every finding of required tables/columns in the Database.
Accept Table name filter, Column name filter, SQL, Include_NTI (i.e. whether to include Ntext, Text, Image data types during stored procedure execution, usually these data types give errors during data comparison) parameters.
Check whether to include TEXT, NTEXT and IMAGE data types. Check whether to include Table and column filters.
Fetch a Result Set that contains the Table and Column names with associated owner name by querying on SQL SERVER System Tables based on the input parameters.
Loop through the Result Set
Execute the supplied SQL for each row in the result set