Thursday, December 17, 2009

Delete All Tables from Database

Declare @sql Varchar(500)
Declare @get_table varchar(100)
DECLARE s_gettable CURSOR FOR SELECT name FROM sys.objects where type_desc ='USER_TABLE'
OPEN s_gettable
FETCH NEXT FROM s_gettable INTO @get_table
WHILE @@FETCH_STATUS = 0
BEGIN
BEGIN
Set @sql='drop table dbo.'+@get_table
exec(@sql)
END
FETCH NEXT FROM s_gettable INTO @get_table
END
CLOSE s_gettable
DEALLOCATE s_gettable

No comments:

Post a Comment