Author - Mohamed Basha

How to apply or execute a T-SQL command to every database in your server

We talked before on How to  apply or execute a T-SQL command to every tables in your database. Now we are going to have a quick look on the same but for databases not tables … There is a handy undocumented stored procedure that allows you to do this without needing to set up a cursor...

How to execute a T-SQL command to every table in SQL Server database

sp_MSforeachtable is a stored procedure that is mostly used to apply a T-SQL command to every table, iteratively, that exists in the current database. Examples on how to use it: 1-Perform an unconditional reindex over all tables in the database: EXEC sp_MSforeachtable 'DBCC DBREINDEX(''?'')' 2-Truncate all tables in the database: EXEC sp_MSforeachtable 'TRUNCATE TABLE ?' 3-Get the information about the...