在Microsoft SQL Server中我们如何删除某个数据库中所有表,步骤如下:
1、打开SSMS - SQL Server Management Studio
2、选择需删除所有表的数据库 > 新建查询
3、查询窗口输入以下代码:
declare @CurrentTableName nvarchar(100) declare @CurrentTableObjectID int declare @deletetableSqlString nvarchar(1000) --select * from Sys.all_objects where type='U' ; declare tb cursor local for select name,object_id from Sys.all_objects where type='U' ; open tb fetch next from tb into @CurrentTableName,@CurrentTableObjectID while @@fetch_status=0 begin set @deletetableSqlString='drop table '+@CurrentTableName exec sp_executesql @deletetableSqlString; print '删除数据表'+@CurrentTableName +'完成' fetch next from tb into @CurrentTableName,@CurrentTableObjectID end close tb deallocate tb
4、确认无误后点击“执行”即可。
*此项操作将删除所选数据库的所有表单及数据,请谨慎操作!
声明:如需转载,请注明来源于www.webym.net并保留原文链接:http://www.webym.net/jiaocheng/610.html