How to Update and Delete Data Using Cursor in SQL
In this article I am going to explain how to update and delete data using cursor in SQL.
A cursor is a database object that points to a result set. We use cursor to fetch any specific row from result set. Most of time cursor is used by application programmer.
Implementation of cursor in SQL
- We can implement cursor through standard database APIs.
- We can implement cursor through Transact-SQL
SQL Statement used in cursor
- DECLARE : It is used to define a new cursor.
- OPEN : It is used to open a cursor
- FETCH : It is used to retrieve a row from a cursor.
- CLOSE : It is used to close a cursor.
- DEALLOCATE : It is used to delete a cursor and releases all resources used by cursor.
Update Data Using Cursor
We can update data using cursor in SQL.
set vendorname = 'manish'
where current of cur_invinfo
Delete Data Using Cursor
We can also delete data using cursor.
where current of invinfo_cur1