SQL删除所有表数据

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

posted on 2013-04-22 11:19  AndyCai  阅读(169)  评论(0编辑  收藏  举报

导航