Interview Question
Qus: What are differences between function and stored procedure in .Net programming language?
1. The procedure allows SELECT as well as DML(INSERT/UPDATE/DELETE) statement in it whereas Function allows only SELECT statement in it.
2. Procedures cannot be utilized in a SELECT statement whereas Function can be embedded in a SELECT statement.
3. Stored Procedures cannot be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section whereas Function can be.
4. An exception can be handled by try-catch block in a Procedure whereas try-catch block cannot be used in a Function.
5. We can use Transactions in Procedure whereas we can't use Transactions in Function.
Answers (2)
o Function returns only one value but procedure can return one or more than one value.
o Function can be used in select statements but procedure cannot be used.
o Function has only input parameters while Procedure can have an input and output parameters.
o Exceptions can be handled by try catch block in procedures but that is not possible in function.
2. Procedures cannot be utilized in a SELECT statement whereas Function can be embedded in a SELECT statement.
3. Stored Procedures cannot be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section whereas Function can be.
4. An exception can be handled by try-catch block in a Procedure whereas try-catch block cannot be used in a Function.
5. We can use Transactions in Procedure whereas we can't use Transactions in Function.