I have a Microsoft SQL Server 2008 with many databases and most of them have a Logs table. I would like to be able to schedule a script to run and truncate the Logs table in every one of these databases (dynamically). I imagine I have to get the name of every user database then truncate the table Logs in the databases that contain a Logs table.
The statement I ended up using is:
EXEC sp_MSForEachDB 'Use [?]; IF EXISTS (SELECT * FROM sys.tables WHERE name = "Logs" and type="U")TRUNCATE TABLE Logs'