清除数据库表、外键、存储过程SQL
2014-03-31 10:52
429 查看
1.删除所有外键
DECLARE c1 cursorfor
select'alter table ['+object_name(parent_obj) +'] drop constraint ['+name+']; '
from sysobjects
where xtype ='F'
open c1
declare@c1varchar(8000)
fetchnextfrom c1 into@c1
while(@@fetch_status=0)
begin
exec(@c1)
fetchnextfrom c1 into@c1
end
close c1
deallocate c1
2.删除所有表
use 数据库
declare@tnamevarchar(8000)
set@tname=''
select@tname=@tname+ Name +','from sysobjects where xtype='U'
select@tname='drop table '+left(@tname,len(@tname)-1)
exec(@tname)
3.删除所有存储过程
declare @procName varchar(500)
declare cur cursor
for select [name] from sys.objects where type = 'p'
open cur
fetch next from cur into @procName
while @@fetch_status = 0
begin
if @procName <> 'DeleteAllProcedures'
exec('drop procedure ' + @procName)
fetch next from cur into @procName
end
close cur
deallocate cur
DECLARE c1 cursorfor
select'alter table ['+object_name(parent_obj) +'] drop constraint ['+name+']; '
from sysobjects
where xtype ='F'
open c1
declare@c1varchar(8000)
fetchnextfrom c1 into@c1
while(@@fetch_status=0)
begin
exec(@c1)
fetchnextfrom c1 into@c1
end
close c1
deallocate c1
2.删除所有表
use 数据库
declare@tnamevarchar(8000)
set@tname=''
select@tname=@tname+ Name +','from sysobjects where xtype='U'
select@tname='drop table '+left(@tname,len(@tname)-1)
exec(@tname)
3.删除所有存储过程
declare @procName varchar(500)
declare cur cursor
for select [name] from sys.objects where type = 'p'
open cur
fetch next from cur into @procName
while @@fetch_status = 0
begin
if @procName <> 'DeleteAllProcedures'
exec('drop procedure ' + @procName)
fetch next from cur into @procName
end
close cur
deallocate cur
相关文章推荐
- 创建数据库、表、主外键、各种约束、存储过程、视图、索引、事务使用、触发器、创建登录账号、数据库用户 Sql语句示例
- 清除SQL 2000数据库注释小工具(存储过程,视图,用户函数)
- 数据库到底用不用外键、触发器、索引、视图、存储过程
- SqlParameter参数方式操作数据库(存储过程)
- ms sql server 2005数据库日志文件过大,需要清除或者清空
- 数据库中Sql语句,存储过程,触发器对性能影响的理解
- 记录数据库sql和存储过程相关
- SQL删除数据库中所有用户数据表外键
- ms sqlserver 清除数据库日志脚本
- 一条SQL语句查询数据库中的所有表、存储过程、触发器 (sysobjects表信息)
- SQL 数据库 学习 009 通过SQL命令 建表 和 主外键约束
- SQL Server 2005 导出包含(insert into)数据的SQL脚本 (使用存储过程) 分类: 数据库
- 数据库 day62 Oracle(pl/sql,存储过程,触发器)
- 一条SQL语句查询数据库中的所有表、存储过程、触发器 (sysobjects表信息)
- 拿来主义:分享给大家,关于SQL中数据库设置,约束、外键、主键等
- 数据库--sql作业,执行自动备份的存储过程
- MS sql server 数据库日志文件清除(压缩)和恢复日志文件的方法
- SQL删除数据库中所有用户数据表外键
- 使用SQL脚本创建数据库,操作主键、外键与各种约束(MS SQL Server)
- sql编程 存储过程 之动态添加数据库表列并更新数据库表数据