회사에서 짤리고 싶을 때 쓰기에 좋은 쿼리

  • Post author:
  • Post category:
  • Post comments:4 Comments
  • Post last modified:November 9, 2007

현재 데이터베이스(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

This Post Has 4 Comments

  1. tomowind

    짤리는게 아니라 고발당할 수도…

  2. 최재훈

    제목 바꿀까요? “고발 당하고 싶을 때 쓰기에 좋은 쿼리” 

  3. kingori

    고발정도가 아니라 DBA에게 칼 맞고 승천할 수도 있을 것 같은데요

  4. 최재훈

    문명인끼리 말로 하면 안 될까요? 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.