Click here to Skip to main content
15,942,710 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more: , +
difference between stored procedure and function or sub created in .vb or .cs file
basically stored procedure is used to perform the repeated task like insert,update query etc.
You can also perform this by creating sub or function in .vb or .cs file then what is difference between them?
Updated 17-Feb-13 21:36pm

Stored Procedures vs Functions:
• We can go for transaction management in procedure whereas we can't go in function.
• Procedure can return zero or n values whereas function can return one value which is mandatory.
• Procedures can have input/output parameters for it whereas functions can have only input parameters.
• Inline UDF's can be though of as views that take parameters and can be used in JOINs and other Rowsetoperations.
• Procedure allows select as well as DML statement in it whereas function allows only select statement in it.
• Functions can be called from procedure whereas procedures cannot be called from function.
• Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in a function.
• Procedures can not be utilized in a select statement whereas function can be embedded in a select statement.
• UDF can be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section where as Stored procedures cannot be.
• UDFs that return tables can be treated as another rowset. This can be used in JOINs with other tables.
• And a lot more here[^].

And a lots of differences are there between function and sub in vb. Refer the links below:
Sub Procedures and Functions in[^]

VB.Net Sub vs. Function
An Introduction to Functions and Subs[^]
And a lot more here[^].

Share this answer
Stored procedures and functions are built on the SQL language which is set based and operates on data in an imperative way meaning you say what you want and not how you want it and the database engine figures that out.

SQL is a powerful language for data manipulations, however I am against writing it at the database level since you will get locked down in a vendors engine and cannot easily move to another when needed. I believe you can get all the benefits if you write the SQL statements in your own code (which you can version check etc.). [DB vendors will sell you that it is more performant if you write SP's but in my experience this is not the case in modern DB's]
Share this answer
Jigar Sangoi 18-Feb-13 3:39am    
So you want to say that when we change database provider like sql to oracle etc. at that time function and sub in .vb or .cs file reusable because it not built with sql or any
other database provider
Mehdi Gholam 18-Feb-13 3:47am    
If you use ANSI SQL which is portable then yes, and generally you have more control in c# in this regard then trying to convert a TSQL SP to a PLSQL SP etc.
sub in VB = Method that performs set of operation and does not return anything

SQL Store procedure vs Function

adv. of function is can use in inline query

dis adv of function
function have limited err handling than sp
SP can use temp table but function can not
function can not call sp

Happy Coding!
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900