How To Drop Tables Together With Query In MSSqlServer

Hello Friends Often you try to do How to drop all table into your database together with a single query
Then I give u solution for this Which I Needed

SELECT name INTO #tables from sys.objects where type = ‘U’
while (SELECT count(1) FROM #tables)>0
declare @sql varchar(max)
declare @tbl varchar(255)
SELECT top 1 @tbl = name FROM #tables
SET @sql = ‘drop table ‘ + @tbl
DELETE FROM #tables where name = @tbl
DROP TABLE #tables;

SELECT *FROM #tables;

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s