sybase:如果可能,我如何删除所有表和存储过程?

Pau*_*ald 2 sql sybase

我想删除模式中的所有表和存储过程,任何人都知道如何做到这一点?如果可能的话,我想避免丢弃整个数据库.

Jea*_*ean 7

您可以使用一系列删除迭代sysobjects表,并系统地删除您想要的所有对象.

declare tables cursor 
for select name from sysobjects where type='U'
go
declare @name varchar(255)
open tables
fetch tables into @name
while (@@sqlstatus = 0)
begin
exec("drop table "+ @name)
fetch tables into @name
end
close tables
deallocate cursor tables
Run Code Online (Sandbox Code Playgroud)

是的,这需要游标,它会有点慢,但它应该几乎擦干数据库.

  • 对于表,您需要使用type ='U'并在循环中使用drop table
  • 对于存储过程,您将拥有P或XP并在循环中使用drop procedure

更多信息: