このようなものが欲しいですか?
osql
スクリプトの使用とスクリプトを次のように印刷するだけの場合
DECLARE @schema VARCHAR(255)
DECLARE @table VARCHAR(255)
DECLARE PrintOutputCursor CURSOR LOCAL FAST_FORWARD FOR
SELECT [TABLE_SCHEMA], [TABLE_NAME]
FROM INFORMATION_SCHEMA.TABLES
OPEN PrintOutputCursor
FETCH NEXT FROM PrintOutputCursor INTO @schema, @table
WHILE @@FETCH_STATUS = 0 BEGIN
PRINT 'DROP TABLE ['+ @schema + '].[' + @table + '];'
FETCH NEXT FROM PrintOutputCursor INTO @schema, @table
END
CLOSE PrintOutputCursor
DEALLOCATE PrintOutputCursor
このスクリプトを使用してスクリプトを実行する場合osql
(非推奨)
DECLARE @schema VARCHAR(255)
DECLARE @table VARCHAR(255)
DECLARE @exec VARCHAR(4000)
DECLARE PrintOutputCursor CURSOR LOCAL FAST_FORWARD FOR
SELECT [TABLE_SCHEMA], [TABLE_NAME]
FROM INFORMATION_SCHEMA.TABLES
OPEN PrintOutputCursor
FETCH NEXT FROM PrintOutputCursor INTO @schema, @table
WHILE @@FETCH_STATUS = 0 BEGIN
SET @exec = 'DROP TABLE ['+ @schema + '].[' + @table + '];'
-- Uncomment the following to execute the dynamic statement
-- EXEC (@exec)
FETCH NEXT FROM PrintOutputCursor INTO @schema, @table
END
CLOSE PrintOutputCursor
DEALLOCATE PrintOutputCursor