Home > Database > Mysql Tutorial > 清空所有表中的数据的存储过程

清空所有表中的数据的存储过程

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 18:00:51
Original
1541 people have browsed it

清空所有表中的数据的sql语句,需要的朋友可以参考下,利用了存储过程。

代码如下:
--*******************************************************
--* 清空所有表中的数据 *
--* 撒哈拉大森林 *
--* 2010-6-28 *
--*******************************************************

if exists (select * from sysobjects where type='P' and name=N'P_DeleteAllData' )
drop procedure P_DeleteAllData
go

CREATE PROCEDURE P_DeleteAllData
as
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL' --禁用约束
EXEC sp_MSForEachTable 'ALTER TABLE ? DISABLE TRIGGER ALL' --禁用触发器
EXEC sp_MSForEachTable 'DELETE FROM ?' --删除所有表中的数据
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL' --启用约束
EXEC sp_MSForEachTable 'ALTER TABLE ? ENABLE TRIGGER ALL' --启用触发器
go

--执行存储过程
--exec P_DeleteAllData --执行
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template