Sql Server 删除所有表实现方法
2022-11-12 09:55:45
内容摘要
这篇文章主要为大家详细介绍了Sql Server 删除所有表实现方法,具有一定的参考价值,可以用来参考一下。
1)首先必须要清空所有表的外键 SQL代码如下:
DECLARE c1 cursor for
se
文章正文
这篇文章主要为大家详细介绍了Sql Server 删除所有表实现方法,具有一定的参考价值,可以用来参考一下。
1)首先必须要清空所有表的外键 SQL代码如下:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <code class = "sql" > 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 ---- 来自www.512pic.com </code> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <code class = "sql" > --清空数据库内所有的表 --注意替换数据库 use aqfk_2016_test 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 ---- 来自www.512pic.com </code> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <code class = "sql" > select identity(int,1,1) flag,[name] names into #tmp from sysobjects where xtype= 'v' declare @tb varchar(1000) ,@a int,@b int,@sql varchar(8000) select @a=min(flag),@b=max(flag) from #tmp while @a<=@b begin select @tb=names from #tmp where flag=@a set @sql= 'drop view "' +@tb+ '"' exec (@sql) set @a=@a+1 end DROP TABLE #tmp ---- 来自www.512pic.com </code> |
注:关于Sql Server 删除所有表实现方法的内容就先介绍到这里,更多相关文章的可以留意
代码注释