日期:2014-05-16  浏览次数:20526 次

清除数据库里面的所有表数据(转)
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[deldata] 
AS
BEGIN
	DECLARE tables_cursor CURSOR  
	   FOR  
	   SELECT name FROM sysobjects WHERE type = 'U' ---选择用户表名  
	OPEN tables_cursor --打开游标连接  
	 
	DECLARE @tablename sysname   -- 定义变量  
	FETCH NEXT FROM tables_cursor INTO @tablename   --结果集中一行一行读取表名  
	WHILE (@@FETCH_STATUS <> -1) --//判断游标状态   
	BEGIN  
	 
	   EXEC ('DELETE from ' + @tablename)   ---清空表中的数据  
	   FETCH NEXT FROM tables_cursor INTO @tablename --下一行数据  
	END  
	 
	DEALLOCATE tables_cursor --//关闭游标
END