Skip to main content

Posts

Showing posts from December, 2014

sp_msforeachtable - Quick counting table rows

i just starting to play along with SSIS and SSAS and i came up with this trick to show wether my data has been populate into staging or data warehouse table so here is the script EXEC sp_MSForEachTable " DECLARE @count AS INT SET @count=0 SELECT @count = ISNULL(SUM(1), 0) FROM ? PRINT ""?: "" + CONVERT(VARCHAR, @Count) , @whereand = "ORDER BY 1" "  until then

sp_msforeachtable - Delete data in all tables in SQL Server database

hi all, just remember to post this useful tips -- disable all constraints EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all" -- delete data in all tables EXEC sp_MSForEachTable "DELETE FROM ?" -- enable all constraints exec sp_msforeachtable "ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all" --if some of the tables have identity columns we may want to reseed them EXEC sp_MSforeachtable "DBCC CHECKIDENT ( '?', RESEED, 0)" see u then