CREATE PROCEDURE sp_BuildIndexes
AS
DECLARE @TableName sysname, @msg varchar(100), @cmd varchar(100) --临时变量
DECLARE table_cur CURSOR FOR --声明游标
SELECT name FROM sysobjects WHERE type='u'
OPEN table_cur --打开游标
FETCH NEXT FROM table_cur INTO @TableName --得到数据
WHILE @@fetch_status = 0
BEGIN
IF @@fetch_status = -2 --不存在
CONTINUE
SELECT @msg = 'Delete for table'+@TableName+'…' --跟踪日志
PRINT @msg
select @cmd = 'truncate table '+@TableName --清空数据
exec(@cmd)
FETCH NEXT FROM table_cur INTO @TableName
END
DEALLOCATE table_cur
GO
EXEC sp_BuildIndexes
sql数据库批量操作
最新推荐文章于 2022-11-22 09:49:42 发布