Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 21:04pm
Edited 17-Feb-13 22:36pm
v3
Rate this: bad
good
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[^]

VB.Net Sub vs. Function
[^]
An Introduction to Functions and Subs[^]
And a lot more here[^].
 
--Amit
  Permalink  
v2
Rate this: bad
good
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]
  Permalink  
Comments
Jigar Sangoi at 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 at 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
good
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!
Smile | :)
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 255
2 Shweta N Mishra 216
3 Maciej Los 210
4 PIEBALDconsult 184
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,665


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 15 May 2013
Copyright © CodeProject, 1999-2014
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