勤于思考:游标删除数据库所有表数据

使用游标删除库的所有表

DECLARE @tablename varchar(20) 

DECLARE CUR CURSOR FOR SELECT name FROM sysobjects WHERE type = 'U' 

OPEN CUR 

FETCH NEXT FROM CUR INTO @tablename

WHILE @@FETCH_STATUS=0

BEGIN

EXEC ('TRUNCATE TABLE ' + @tablename) 

FETCH NEXT FROM CUR INTO @tablename

END

CLOSE CUR;

DEALLOCATE CUR;

 

 

你可能感兴趣的:(删除数据)