删除指定数据库所有表
2014-06-01 14:42
316 查看
无主外键关系的表
use sq_mstfr715164 GO declare @sql varchar(8000) while (select count(*) from sysobjects where type='U')>0 begin SELECT @sql='drop table ' + name FROM sysobjects WHERE (type = 'U') ORDER BY 'drop table ' + name exec(@sql) end
如果有主外键关系的,需先删除主外键,再删除所有表
use sq_mstfr715164 DECLARE c1 cursor for select 'alter table ['+ object_name(parent_obj) + '] drop constraint ['+name+']; ' from sysobjects where xtype = 'F' open c1 declare @c1 varchar(8000) fetch next from c1 into @c1 while(@@fetch_status=0) begin exec(@c1) fetch next from c1 into @c1 end close c1 deallocate c1 --再来删除表,会删除该数据库(例test)下所有表 DECLARE c2 cursor for select 'drop table ['+name +']; ' from sysobjects where xtype = 'u' open c2 declare @c2 varchar(8000) fetch next from c2 into @c2 while(@@fetch_status=0) begin exec(@c2) fetch next from c2 into @c2 end close c2 deallocate c2
相关文章推荐
- 删除sqlserver指定数据库的所有表的数据
- oracle 强制删除指定schema及相关的所有数据库的对象
- mysql 查询指定数据库所有表, 指定表所有列, 指定列所有表 所有外键及索引, 以及索引的创建和删除
- 删除数据库中所有表中指定的字段
- SQLServer2005如何删除指定数据库的所有表
- mysql删除指定数据库所有的表
- Oracle导入导出及删除指定用户下所有数据库脚本
- 删除Mysql指定数据库下所有表
- 删除指定数据库中的所有表
- sqlserver2005删除指定数据库里的所有用户表【转摘】
- sqlserver2005 删除指定数据库里的所有用户表
- 进入织梦DedeCms数据库删除指定IP的所有评论
- 删除数据库的所有存储过程、主键、外键、索引等
- 一段删除某个数据库下所有数据的好脚本
- 删除数据库的所有存储过程、主键、外键、索引等(转)
- 清空数据库中的所有用户表(删除数据库中的表)
- SQL Server 清空或删除所有数据库表中的数据
- c#将指定数据库中所有数据由简体转换为繁体
- 还原Wss3.0内容数据库时遇到:"ComputerName\Microsoft##SSEE 上的 WSS_Content 包含用户定义的架构。数据库在能够使用之前必须为空。请删除所有表、存储过程以及其他对象,或使用其他数据库。 " 的提示,无法加载内容数据库