时间:2021-07-01 10:21:17 帮助过:2人阅读
set rowcount的作用是使 SQL Server在返回指定的行数之后停止处理查询。
输出结果:
实现表遍历:
declare @nameguid uniqueidentifier declare @name nvarchar(10) while exists (select * from nametable) begin set rowcount 1 select @nameguid = nameguid from nametable select @name = name from nametable where nameguid = @nameguid set rowcount 0 delete from nametable where nameguid = @nameguid print @name end
不过这样操作会删除表中的数据,可以在临时表中操作
select * into #nametable from nametable
sql不使用游标遍历表数据
标签: