SQL SERVER – Simple Cursor to Select Tables in Database with Static Prefix and Date Created

Following cursor query runs through database and find all the table with certain prefixed (‘b_’,’delete_’). It also checks if the Table is more than certain days old or created before certain days, it will delete it. We can have any other opertation on that table like delete, print or reindex.

As you said that your querry is usefull for print or reindex,
Can u please tell me Wht is the adavntage and disadvantages of re-indexing and wht is the need to reinedxing. When to reindex your table and WHY???

Could we use INFORMATION_SCHEMA instead of sysobjects for the same?
I don’t know what object of INFORMATION_SCHEMA could be used to check the last modified date of a table. I believe we need to involve DMVs here. If there is a work around, please let me know.

Community Initiatives

About Pinal Dave

Pinal Dave is a Pluralsight Developer Evangelist. He has authored 11 SQL Server database books, 17 Pluralsight courses and have written over 3200 articles on the database technology on his blog at a http://blog.sqlauthority.com. Along with 11+ years of hands on experience he holds a Masters of Science degree and a number of certifications, including MCTS, MCDBA and MCAD (.NET). His past work experiences include Technology Evangelist at Microsoft and Sr. Consultant at SolidQ. Follow @pinaldave
Send Author Pinal Dave
an email at pinal@sqlauthority.com

Email Subscription

Enter your email address to subscribe to this blog and receive notifications of new posts by email.