Searched a bit and didn't see anything that really fit my needs (although I don't really understand SQL beyond the basic select statement so maybe I just missed it). Took a SQL class in school many moons ago.
I have:
- Virtual Windows Server 2008 R2 running SQL 2008 R2. I connect via MS SQL Server Management Studio
- 90-100 databases
- All DB's have the same table structure (each one is a different client)
I want to:
- Search all databases and return a list of all databases which have a table (TableName) that is larger than say, 5000 records.
- Some sort of script that I can schedule that will use that list and if it finds a DB that the TableName table is more than 5000 records, will delete anything older than x amount of days (say 30). Any kind of logging to know what happened over the last few days would be a bonus.
Any help would be appreciated. Thank you.
EDIT/UPDATE (2/24/15): Hiren Dhaduk provided a nice stored procedure that works. Thanks!