Explain the steps to use Transact-SQL Cursor?
Submitted by: AdministratorDeclare the cursor,
Open the cursor,
Fetch record row by row,
Close cursor,
Deallocate cursor.
Example of a cursor
Declare @EmpId int
Declare curEmp CURSOR READ_ONLY FOR SELECT EmpId FROM Employee
Open curEmp
Fetch next from curEmp into @EmpId
While @@FETCH_STATUS = 0
Begin
Print @EmpId
Fetch next from curEmp into @EmpId
End
Close curEmp
Deallocate curEmp
Submitted by: Administrator
Open the cursor,
Fetch record row by row,
Close cursor,
Deallocate cursor.
Example of a cursor
Declare @EmpId int
Declare curEmp CURSOR READ_ONLY FOR SELECT EmpId FROM Employee
Open curEmp
Fetch next from curEmp into @EmpId
While @@FETCH_STATUS = 0
Begin
Print @EmpId
Fetch next from curEmp into @EmpId
End
Close curEmp
Deallocate curEmp
Submitted by: Administrator
Read Online SQL Server Cursors Job Interview Questions And Answers
Top SQL Server Cursors Questions
☺ | What is cursor in MS SQL Server? |
☺ | Explain the cursor lock types? |
☺ | What is scrollable cursor? |
☺ | Do you know the capabilities of Cursors? |
☺ | Explain Temporary table VS Table variable by using Cursor alternative? |
Top New MS SQL Server Categories
☺ | SQL Server Database Administrator Interview Questions. |
☺ | SQL Server Service Broker Interview Questions. |
☺ | SQL Server Locks Interview Questions. |
☺ | SQL Server Constraints Interview Questions. |
☺ | MS SQL Data Mining Interview Questions. |