-----此处不用truncate是因为truncate必须得删除外键,如果不考虑外键的话最好用truncate
----禁用当前数据库中所有表的约束、触发器
exec sp_msforeachtable 'ALTER TABLE ? DISABLE TRIGGER all'
exec sp_msforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT all'
go
----清空除employee、department、account外的所有表中的记录
begin
declare crsr cursor ------定义游标取回用户建立的表
for SELECT [name] FROM DBO.SYSOBJECTS
WHERE OBJECTPROPERTY(ID,N'IsTable')=1 and type = 'U' and ([name] <> 'dtproperties'
and [name] <> 'account' and [name] <> 'employee' and [name]<>'department' )
declare @tblName sysname ------用户表名
open crsr
fetch crsr into @tblName
EXEC(' delete from dbo.'+@tblName)
print @tblName
while @@fetch_status=0
begin
fetch next from crsr into @tblName
exec('delete from dbo.'+@tblName)
print @tblName
end
close crsr
deallocate crsr
end
go
----启用当前数据库中所有表的约束、触发器
exec sp_msforeachtable 'ALTER TABLE ? enable TRIGGER all'
exec sp_msforeachtable 'ALTER TABLE ? CHECK CONSTRAINT all'
----禁用当前数据库中所有表的约束、触发器
exec sp_msforeachtable 'ALTER TABLE ? DISABLE TRIGGER all'
exec sp_msforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT all'
go
----清空除employee、department、account外的所有表中的记录
begin
declare crsr cursor ------定义游标取回用户建立的表
for SELECT [name] FROM DBO.SYSOBJECTS
WHERE OBJECTPROPERTY(ID,N'IsTable')=1 and type = 'U' and ([name] <> 'dtproperties'
and [name] <> 'account' and [name] <> 'employee' and [name]<>'department' )
declare @tblName sysname ------用户表名
open crsr
fetch crsr into @tblName
EXEC(' delete from dbo.'+@tblName)
print @tblName
while @@fetch_status=0
begin
fetch next from crsr into @tblName
exec('delete from dbo.'+@tblName)
print @tblName
end
close crsr
deallocate crsr
end
go
----启用当前数据库中所有表的约束、触发器
exec sp_msforeachtable 'ALTER TABLE ? enable TRIGGER all'
exec sp_msforeachtable 'ALTER TABLE ? CHECK CONSTRAINT all'
本文深入探讨了数据库管理与优化的关键技术,包括数据结构、算法、索引理论、事务管理等核心概念。重点阐述了如何通过合理的设计、高效的数据结构选择和优化的查询策略来提升数据库性能。此外,还介绍了现代数据库系统中的高级特性,如并发控制、事务一致性、备份策略等,旨在为读者提供全面的数据库管理与优化知识。
6422

被折叠的 条评论
为什么被折叠?



