我想删除模式中的所有表和存储过程,任何人都知道如何做到这一点?如果可能的话,我想避免丢弃整个数据库.
您可以使用一系列删除迭代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)
是的,这需要游标,它会有点慢,但它应该几乎擦干数据库.
更多信息: