sql 遍历临时表(set rowcount 1 )

来源:互联网 发布:微信群成语接龙软件 编辑:程序博客网 时间:2024/06/05 02:00
--判断零时表是否存在,如果存在删除--  if exists (select * from tempdb.dbo.sysobjects where id = object_id(N'tempdb..#tempcitys') and type='U')drop table #tempcitys go--创建零时表create table #tempcitys(id int primary key identity(1,1),name nvarchar(50))go--插入数据insert into #tempcitys(name) values('上海');insert into #tempcitys(name) values('杭州');insert into #tempcitys(name) values('苏州');go--遍历零时表declare @city_name nvarchar(50)while exists(select name from #tempcitys)   begin   set rowcount 1   select @city_name=name from #tempcitys   set rowcount 0   delete from #tempcitys where name = @city_name  print  @city_nameend


 



原创粉丝点击