--定义游标查出结果集,打开游标
DECLARE Employee_Cursor CURSOR FOR
SELECT BBSID, BBSTitle FROM BBS
OPEN Employee_Cursor
--遍历结果集
declare @au_lname nvarchar(MAX)
declare @au_fname nvarchar(MAX)
FETCH NEXT FROM Employee_Cursor INTO @au_lname, @au_fname
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT 'Author: ' + @au_lname + ' ' + @au_fname
--在此处理这条纪录
FETCH NEXT FROM Employee_Cursor INTO @au_lname, @au_fname
END
--关闭并销毁游标
CLOSE Employee_Cursor
DEALLOCATE Employee_Cursor