회사에서 짤리고 싶을 때 쓰기에 좋은 쿼리
현재 데이터베이스(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
.(JavaScript must be enabled to view this email address) on 11.09.2007 at 01:32 PM
짤리는게 아니라 고발당할 수도...
최재훈 on 11.09.2007 at 01:50 PM
제목 바꿀까요? “고발 당하고 싶을 때 쓰기에 좋은 쿼리”
kingori on 11.10.2007 at 08:05 PM
고발정도가 아니라 DBA에게 칼 맞고 승천할 수도 있을 것 같은데요
최재훈 on 11.10.2007 at 08:20 PM
문명인끼리 말로 하면 안 될까요?