What is the difference between UDF and stored procedure in SQL? - ProProfs Discuss
Advertisement

What is the difference between UDF and stored procedure in SQL?

What is the difference between UDF and stored procedure in SQL?

Change Image    Delete

Asked by K. Parker, Last updated: Dec 19, 2024

+ Answer
Request
Question menu
Vote up Vote down

2 Answers

Jessica Rhodes

Jessica Rhodes

The economy is the basis of development, so I'd like to explore and share my knowledge more and more online and offline.

Jessica Rhodes
Jessica Rhodes, Economic advisor, Master of Economics (MEcon), Ohio

Answered May 19, 2020

The first notable thing that differentiates UDF (that is User Defined Function) and the stored procedure is that the user-defined function must return a value, while the factor for the stored procedure to return value depends on whether there is a value at all to return.

Another difference is that the stored procedure allows you to use, update, and manipulate both select statements and the DML statements, while the user-defined function can only allow you to read the select statements, but deny you from accessing the DML statements. In a stored procedure, you can be able to input and also have the output of parameters, while the user-defined function only allows for the input of parameters, but will not support the output of the same parameters.

The stored procedure allows transactions to happen within functions, but the UDF gives no allowance for this. In addition, store procedure allows the user of temporary table and table variables, while the UDF does not allow for the usage of table variables and temporary table.

upvote downvote
Reply 

K. Myers

K. Myers

K. Myers
K. Myers, Blogger, Chicago

Answered May 12, 2020

A lot of people may get confused about the difference between the two, but to help you out, you should remember a few things. First, the procedure can always return to n values (zero) while the function will return to the mandatory value. Second, the function will only have input parameters, while input will have input/output parameters.

Third, transaction management can be done in the procedure while in function, this is not possible. Fourth, the procedure can create a table but will not be able to return the table. This is different from functions that can make, create, delete, and so so many other things with the table. With these differences, it will be easier for you to know what to do.

upvote downvote
Reply 

Advertisement
Advertisement
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader
Image Preview
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader
Image Preview
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader

Email Sent
We have sent an email to your address "" with instructions to reset your password.