SQL SERVER 帮忙写一个存储过程

来源:百度知道 编辑:UC知道 时间:2024/07/04 09:49:59
删除数据库 mydb 中除表名为"abcde"的其他所有表

Create Proc Pr_DeleteTable
as
declare @Table varchar(20)
declare cr_cursor cursor --1.定义游标
for select name from dbo.sysobjects where xtype='U' and status>0 and name<>'abcde'
open cr_cursor --2.打开游标
fetch From cr_cursor into @Table --3.提取游标
while @@fetch_status=0
begin
exec('drop table '+@Table) --执行删除操作
fetch next From cr_cursor into @Table
end;
close cr_cursor --4.关闭游标
deallocate cr_cursor --5.释放游标

最后调用过程就用 EXEC Pr_DeleteTable

祝你好运! 如果还不行的话就给我发消息 呵呵