[T-SQL] 游标使用方法

 

USE Northwind
GO

--第一步:声明游标
DECLARE Employee_Cursor CURSOR FOR
SELECT LastName, FirstName
  FROM Northwind.dbo.Employees
 WHERE LastName like 'B%'

--第二步:打开游标
OPEN Employee_Cursor

--第三步:FETCH游标
FETCH NEXT FROM Employee_Cursor
WHILE @@FETCH_STATUS = 0
    BEGIN
	    FETCH NEXT FROM Employee_Cursor
    END

--第四步:关闭游标
CLOSE Employee_Cursor

--第五步:释放游标
DEALLOCATE Employee_Cursor

 

你可能感兴趣的:(t-sql)