Alternatively, deallocation of a cursor frees up all of the assets related to the cursor, together with the cursor identify. You simply can not reuse a cursor identify by closing it, you could deallocate it. By the way in which, when you deallocate an open cursor, it is will get closed mechanically.
Btw, in case you are new to the SQL world, it is higher to begin with a complete SQL course like these SQL and Database programs for inexperienced persons. That can make it easier to to study SQL higher and faster, and these sorts of articles may also make extra sense upon getting some SQL information underneath your belt.
Cursor – Shut vs Deallocate in SQL
Other than the principle distinction between shut and deallocate Cursor, listed here are a few extra factors to recollect:
1) Deallocating a cursor mechanically closes it, the reverse just isn’t true.
3) You possibly can reopen an in depth cursor and may carry out the fetch operation on that, this isn’t doable when you deallocate a cursor. For instance, the next is authorized :
shut employee_cursor
open employee_cursor
You possibly can then fetch from employee_cursor, as a usually opened cursor. In Sybase Adaptive Server, any situations related to a cursor, stay in impact, even after reopening a closed cursor.
fetch employee_crsr
emp_id emp_name age
----------- ------------------- ---------------
16032243 John 31
16032243 Johnny 32
16032243 Robin 33
deallocate employee_cursor
4) In Microsoft SQL Server, when the final cursor reference is deallocated, the info buildings comprising the cursor are launched.
That is all on the distinction between closing or deallocating a Cursor in SQL. It is SQL greatest apply to not solely shut but in addition deallocate any opened cursor so that every one the related useful resource may be launched and reused. By the way in which, cursor needs to be prevented if doable as they usually present poor efficiency.
- 12 Database Index Questions from interviews (index questions)
- Tips on how to discover the second highest wage in a desk? (answer)
- 5 Programs to study Database and SQL Higher (programs)
- Distinction between View and Materialized View in Database? (reply)
- Prime 5 Web sites to study SQL on-line for FREE? (useful resource)
- Write a SQL question to repeat or backup a desk in MySQL (answer)
- 5 Programs to study Oracle and Microsoft SQL Server database (programs)
- Tips on how to migrate SQL queries from Oracle to SQL Server 2008? (reply)
- What’s the distinction between UNION and UNION ALL in SQL? (reply)
- Prime 5 Books to study Superior SQL and Database Design (books)
- Distinction between clustered and non-clustered indexes in SQL? (reply)
- 5 Free Programs to study T-SQL and SQL Server for Freshmen (Programs)
- 5 Greatest PostgreSQL Programs for Freshmen (on-line programs)
- Distinction between char and varchar in SQL (char vs varchar)
- 10 Free SQL and Database Programs for Freshmen (free programs)
- Distinction between the Distinctive and Major keys within the desk? (reply)
- Prime 5 Programs to study MySQL Database for Freshmen (Programs)
Thanks for studying this text thus far. Should you like these SQL Interview query solutions then please share them with your mates and colleagues. When you have any questions or suggestions then please drop a notice.
P.S. – If you’re new to SQL and keen on studying Microsoft SQL Server in
depth and searching for greatest assets to begin your journey then you possibly can
additionally checkout these Microsoft SQL Server on-line programs to study T-SQL and SQL Server in depth.