现在的位置: 首页 > 综合 > 正文

SQL删除所有表数据

2012年08月27日 ⁄ 综合 ⁄ 共 307字 ⁄ 字号 评论关闭

use xxx -- 数据库名
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 ('TRUNCATE TABLE ' + @tablename)  
   FETCH NEXT FROM tables_cursor INTO @tablename
END 
 
DEALLOCATE tables_cursor

抱歉!评论已关闭.