2012-09-24 2 views
1

데이터베이스를 삭제하지 않고 Sybase ASE의 데이터베이스에있는 모든 테이블을 완전히 삭제하는 가장 좋은 방법은 무엇입니까? 스크립트를 사용하고 있습니다 : from this question하지만 참조 무결성으로 인해 데이터베이스에있는 모든 테이블을 삭제하려고하면 오류가 발생합니다. MySQL의에서제약 조건이있는 테이블을 포함하여 Sybase ASE의 모든 테이블 삭제

나는 사이베이스 ASE이 할 수있는 방법이 있나요 SET FOREIGN_KEY_CHECKS = 0

사용할 수 있습니다 또는 스크립트는 위의 제약 조건을 통해 루프를 확장 할 수 있는가?

답변

2

먼저 당신이 제약 조건을 삭제해야합니다 :

declare cur cursor 
for 
    select SOR.Name as constraint, SOT.Name as table 
    from sysreferences SR 
    join sysobjects SOR on SOR.id = SR.constrid 
    join sysconstraints SC on SC.constrid = SR.constrid 
    join sysobjects SOT on SOT.id = SC.tableid 
go 
declare @constraint varchar(500) 
declare @table varchar(500) 
declare @SQL varchar(500) 

open cur 
fetch cur into @constraint,@table 
    while (@@sqlstatus = 0) 
    begin 

    select @SQL = 'alter table '[email protected]+' drop '[email protected] 
    exec(@SQL) 
    fetch cur into @constraint,@table 

    end 
close cur 
deallocate cursor cur 

가 옆 테이블을 놓을 수 있습니다.

0

위의 논리는 맞지만 쿼리가 잘못되어 "제약 조건"및 "테이블"키워드에 문제가 발생할 수 있습니다. 3

  • 쿼리는 "제약"없는 라인 constriantName 및 TABLENAME 같은

    1. 사용하는 것이 올바른 쿼리 '변경 테이블'+ @table + '드롭 제약'+ @ 제약
  • 1

    수락 된 대답의 모든 제약 조건을 삭제하는 절차가 저에게 효과적이지 않았습니다. 여기 내 ASE16에서 작동하는 수정 된 버전이 있습니다.

    BEGIN 
    declare cur cursor 
    for 
        select o.name, t.name from sysreferences r 
        join sysobjects o on o.id = r.constrid 
        join sysconstraints c on c.constrid = r.constrid 
        join sysobjects t on t.id = c.tableid 
    END 
    GO 
    -- 
    declare @constraint varchar(500) 
    declare @table varchar(500) 
    declare @SQL varchar(500) 
    -- 
    open cur 
    fetch cur into @constraint,@table 
        while (@@sqlstatus = 0) 
        begin 
        -- 
        select @SQL = 'alter table '[email protected]+' drop constraint '[email protected] 
        exec(@SQL) 
        fetch cur into @constraint,@table 
        -- 
        end 
    close cur 
    deallocate cursor cur 
    
    관련 문제