Link to home
Start Free TrialLog in
Avatar of pinaldave
pinaldaveFlag for India

asked on

Script: How to delete Table created before some date

Hello,

I have Database named MyDatabase.
We have to create the tables for certain reasons. Though, we have to use those table for some days only. After that the table is considered as expired.
I want to delete the tables which are created before certain date. Example would be one month ago.
All our tables starts with "MyTmp_"?

How can I do using a script. I can write scheduled job which does this once a month.

Kindly guide me.

Regards,
Avatar of pinaldave
pinaldave
Flag of India image

ASKER

I have moved this question to MSSQL as it was in wrong TA.
I can use this syntax to retrive all the size of the table. Can I also retrive the datecreated of the table ?

EXEC       sp_msforeachtable 'sp_spaceused ''?'''      
u can get the datecreated from SYSOBJECTS crdate column
ASKER CERTIFIED SOLUTION
Avatar of pai_prasad
pai_prasad
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
change it to

and crdate <= dateadd(m,-1,getDate())
Wonderful Thank you :)