码迷,mamicode.com
首页 > 数据库 > 详细

sql server 删除所有表、视图、存储过程

时间:2016-06-04 10:41:58      阅读:312      评论:0      收藏:0      [点我收藏+]

标签:

本文来自:http://www.cnblogs.com/yjss/articles/2065664.html

1.删除表

use 数据库名
declare mycur cursor local for select [name] from dbo.sysobjects where xtype=‘U‘
declare @name varchar(100)
 
OPEN mycur
 
FETCH NEXT from mycur into @name
 
WHILE @@FETCH_STATUS = 0 
 
BEGIN
exec(‘drop table ‘ + @name)
FETCH NEXT from mycur into @name
END
 
CLOSE mycur

 2.删除视图

use 数据库名
declare mycur cursor local for select [name] from dbo.sysobjects where xtype=‘V‘
declare @name varchar(100)
 
OPEN mycur
 
FETCH NEXT from mycur into @name
 
WHILE @@FETCH_STATUS = 0 
 
BEGIN
exec(‘drop VIEW ‘ + @name)
FETCH NEXT from mycur into @name
END
 
CLOSE mycur

  3.删除存储过程

use 数据库名
declare mycur cursor local for select [name] from dbo.sysobjects where xtype=‘P‘
declare @name varchar(100)
 
OPEN mycur
 
FETCH NEXT from mycur into @name
 
WHILE @@FETCH_STATUS = 0 
 
BEGIN
exec(‘drop PROCEDURE ‘ + @name)
FETCH NEXT from mycur into @name
END
 
CLOSE mycur

  

sql server 删除所有表、视图、存储过程

标签:

原文地址:http://www.cnblogs.com/jt789/p/5558236.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!