Register now or log in to join your professional community.
A cursor in SQL server is a variable which can hold records from a select statement (in other words a cursor is a recordset). Use cursor when we need to loop through a select resultset.
Stored procedures are reusable code blocks which is saved as a database object in the SQL Database. It can be compared to subroutines in any programming language(C#, VB.NET, etc). SPs can be used to validate the data, or perform complex and repeated tasks against the database. Use Stored procedures when you have to use same query over and over against the database.
Functions in SQL Server can be compared to functions in any programming language. Function can return values, and can be used as part of select statements in SQL Server queries. A function can return values from any simple type to complex CLR data types.
Cursor is a sophisticated way of performing loops in sql; when need to apply operations on whole table records.