Click here to Skip to main content
13,195,026 members (88,964 online)
Rate this:
Please Sign up or sign in to vote.
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?
Posted 17-Feb-13 20:04pm
Updated 17-Feb-13 21:36pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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[^].

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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]
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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171018.2 | Last Updated 15 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100