sqlserver 2005 利用游标解决标量值函数主键自增id批量导入数据问题

declare @NewsTitle nvarchar(255)





declare mycursor cursor for

select title FROM lc_Article where t_id=1

open mycursor

fetch next from mycursor into @NewsTitle

While(@@Fetch_Status = 0)

begin 

     INSERT INTO tb_News (NewsTitle) VALUES(@NewsTitle)

     fetch next from mycursor into @NewsTitle

  end

close mycursor

deallocate mycursor

tb_News的主键自增id为标量值函数生成的id

游标用来解决从查询结果中逐行取出数据并处理的问题。

你可能感兴趣的:(sqlserver)