pinaldave
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,
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,
ASKER
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 ''?'''
EXEC sp_msforeachtable 'sp_spaceused ''?'''
u can get the datecreated from SYSOBJECTS crdate column
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
change it to
and crdate <= dateadd(m,-1,getDate())
and crdate <= dateadd(m,-1,getDate())
ASKER
Wonderful Thank you :)
ASKER