Forward Only Cursors tidak mengizinkan pengguliran mundur. Satu-satunya opsi pengguliran yang kami miliki adalah FETCH NEXT.
Forward only Static Cursors tidak sensitif terhadap perubahan apa pun ( update, delete, insert) yang dilakukan pada sumber data asli setelah kursor dibuat.
Script untuk Forward_Only Static Cursor
--drop table dbo.CustomerCreate table dbo.Customer ( CustomerId Int Identity(1,1),CustomerName VARCHAR(100),StreetAddress VARCHAR( 100),City VARCHAR(100),State CHAR(2))go--Masukkan beberapa Record di Tabel ContohInsert into dbo.CustomerSelect 'Aamir shahzad','Test Street Address','Charlotte','NC'Union Select ' M Raza','Test Street Address','Charlotte','NC'Select * from dbo.Customer--Insert NEW RecordInsert into dbo.PelangganPilih 'John Smith','Test Street Address','New York City',' NY'--Hapus CatatanHapus dari dbo.CustomerWhere CustomerName in ('Aamir Shahzad','M Raza')--Update All RecordUpdate dbo.Customerset CustomerName='NO NAME'--Cursor ScriptDeclare @CustomerID INTDeclare @CustomerNAME VARCHAR (100) MENYATAKAN @StreetAdd ress VARCHAR(100)DECLARE @City VARCHAR(100)DECLARE @State CHAR(2)--DECLARE A CURSORDECLARE CUR CURSORForward_Only StaticFORSelect CustomerID,CustomerName,StreetAddress,City,State dari dbo.Pelanggan--OPEN CURSOR'OPEN CURSOR --FETCH NEXT RECORDFETCH NEXT DARI CUR INTO @CustomerID,@CustomerNAME,@StreetAddress,@City,@StateWHILE @@FETCH_STATUS=0BEGIN RAISERROR ('',0,1) DENGAN NOWAITWAITFOR DELAY '00:00:15'PRINT CONCAT( @CustomerID,' ',@CustomerNAme,' ',@StreetAddress,' ',@City,' ',@State)FETCH NEXT FROM CUR INTO @CustomerID,@CustomerNAME,@StreetAddress,@City,@StateENDCLOSE CURDEALLOCATE CUR
Tonton video Demo Cara Kerja Forward Only Static Cursors di SQL Server.