定义一个游标,取出除table1,table2,table3,table4表外的所有表名,在游标循环体里逐一删除

解决方案 »

  1.   

    我只能给出Oracle的一个示例:declare
      cursor get_table is
        select tname from tab
        where tname not in('TABLE1',TABLE2','TABLE3','TABLE4');
    begin
      for temp_cursor in get_table loop
        delete from temp_cursor.tname;
        (or:truncate table temp_cursor.tname;)
      end loop;
    end;
      

  2.   

    利用sysobjects表,实现这个功能很简单。
      

  3.   

    create procedure DropTable as
    declare @TableName varchar(100),
    @SQL nvarchar(100)
    declare curGetTable cursor for
    select name from sysobjects where type='u'
    open curGetTable
    fetch next from curGetTable into @TableName
    while @@fetch_status=0
    begin
    if @TableName not in('aaa','bbb','pic2db')
    begin
    set @SQL='drop table '+@TableName
    --print @sql
    execute sp_executesql @SQL
    end
    fetch next from curGetTable into @TableName
    end
    close curGetTable
    deallocate curGetTable==========================
    以上代码在SQL SERVER 7.0通过
      

  4.   

    http://www.wzjcw.net/vbgood/taishan/index.html