현재 데이터베이스(SQL Server 2005)에 있는 모든 테이블을 비워버린다. 테스트용으로 작성한 쿼리이니 실제 데이터베이스에서 쿼리를 실행시키고 원망 말기.

-- 데이터 날리기
DECLARE @deleteSql NVARCHAR(4000)
DECLARE @tableName NVARCHAR(128)

DECLARE tables_cursor CURSOR FOR
    SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES

OPEN tables_cursor

-- Perform the first fetch.
FETCH NEXT FROM tables_cursor
INTO @tableName

SELECT @deleteSql = N'TRUNCATE TABLE [' + @tableName + N'];
'

-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN
    -- This is executed as long as the previous fetch succeeds.
    FETCH NEXT FROM tables_cursor
    INTO @tableName
    SELECT @deleteSql = @deleteSql + N'TRUNCATE TABLE [' + @tableName + N'];
'
END

CLOSE tables_cursor
DEALLOCATE tables_cursor

PRINT N'--  DELETE SQL'
PRINT @deleteSql 

EXECUTE sp_executesql @deleteSql