Tuesday 15 January 2013

sql server 2008 r2 - Drop tables in bulk without using cursor -



sql server 2008 r2 - Drop tables in bulk without using cursor -

i want drop tables coming query.there can multiple tables.

this query homecoming tables names of stage database.

select name sys.objects create_date < getdate()-7

how can drop tables without using cursor ?

assuming want obtain names of tables 7 days older or more..

select name sys.tables datediff(day,create_date,getdate()) >= 7

sys.objects not tables objects should utilize sys.tables

and cursorless deletion..

use @ own risk

begin tran declare @droptables nvarchar(max) set @droptables = '' select @droptables = @droptables + 'drop table '+name+char(10) sys.tables datediff(day,create_date,getdate()) >= 7 exec(@droptables) rollback

sql-server-2008-r2

No comments:

Post a Comment