Function Vs Stored Procedure In SQL

SQL

I have recently started working on SQL, the function and Stored Procedure are seemed to be same. Can anyone tell whats the differences between Function and Stored Procedure?


If you want to unleash your potential in this competitive field, please visit the SQL course page for more information, where you can find the SQL tutorials and SQL frequently asked interview questions and answers as well.

1
Answers

Replies

In order to perform a task, data objects like stored procedures and functions are used in SQL. These data objects usually consists of the set of SQL statements.



Function: A function is a set of statements which is compiled and executed every time it is called. Data modification cannot take place and a function must return a value.



Stored procedures: Stored procedure is referred to as a pre-compiled object as this gets compiled for the first time and the compiled format will be saved as well, which will be executed as and when required whenever it is called.



In SQL, a function does not use transactions while the stored procedures do use the transactions. An exception can be handled by using a try-catch block in a procedure, however, it cannot be handled when used in a function. A function can be used in the SELECT statement while a stored procedure cannot be utilized in the SELECT statement. A function allows only a SELECT statement in it while  stored procedure allows all the DML statements that include INSERT, UPDATE, DELETE.

 
 

This topic has been locked/unapproved. No replies allowed

Login to participate in this discussion.

Leave a reply

Before proceeding, please check your email for a verification link. If you did not receive the email, click here to request another.
WhatsApp
To Top