요건.. 아래쪽에 있는 문장의 응용 버전이다.
테이블을 모두 지우기가 정말 귀찮을 경우에 사용하는 방법인데.. 사이트 나가서 실행하면 안된다.

select object_name(id) from sysindexes where id in
(select id from sysobjects where name like 'logins%') and indid in (0, 1)

select object_name(id) from sysindexes where id in
(select id from sysobjects where name like 'loginerrors%') and indid in (0, 1)

select object_name(id) from sysindexes where id in
(select id from sysobjects where name like 'logouts%') and indid in (0, 1)

select object_name(id) from sysindexes where id in
(select id from sysobjects where name like 'querys%') and indid in (0, 1)

select object_name(id) from sysindexes where id in
(select id from sysobjects where name like 'queryerrors%') and indid in (0, 1)

select object_name(id) from sysindexes where id in
(select id from sysobjects where name like 'responses%') and indid in (0, 1)

select object_name(id) from sysindexes where id in
(select id from sysobjects where name like 'results%') and indid in (0, 1)

-- 아래 FOR 이후 부분을 모두 이것으로 교체 해 주고 실행하면 된다.

declare @tablename varchar(128) , @SQL varchar(2000)

DECLARE cur_droptable CURSOR
READ_ONLY
FOR select object_name(id) from sysindexes where id in
(select id from sysobjects where name like 'logins%') and indid in (0, 1)

OPEN cur_droptable

FETCH NEXT FROM cur_droptable INTO @tablename
WHILE (@@fetch_status <> -1)
BEGIN
    IF (@@fetch_status <> -2)
    BEGIN

    SET @SQL = 'DROP TABLE ' + @tablename
   
    EXEC (@SQL)

    END
    FETCH NEXT FROM cur_droptable INTO @tablename
END

CLOSE cur_droptable
DEALLOCATE cur_droptable
GO

관련해서 나중에 파일 첨부 해 둬야겠지만.. 일단 위에 것 만으로도 사용이 가능하다 싶다.
Posted by hopi
,