.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Interview Question >> Sql Server >> Post New Question Subscribe to Interview Questions

What is Difference between Function and Stored Procedure?

Posted By :Dhivakaran     Posted Date :October 25, 2010    Points :10   Category :Sql Server 
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. Inline UDF's can be thought of as views that take parameters and can be used in JOINs and other Rowset operations.

You can also find related Interview Question to What is Difference between Function and Stored Procedure?  below: 

Difference between Function and Stored Procedure?

  
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.
Inline UDF's can be though of as views that take parameters and can be used in JOINs and other Rowset operations.
(More...)

Database: Difference between Function and stored procedure?

  

Function can be used in sql statements anywhere in where/select/having etc. where as stored procedure cannot be.
(More...)

Difference between stored procedure and function

  

1.Function must return a value but Stored Procedure can return 0(Zero) or n values
2.Functions have only input parameters but Procedures can have either input or output or both parameters .
3.Function must have one input parameter which is mandatory but 4.Stored Procedure may take 0 (Zero) to n input parameters.
5.Functions can be called from Procedure whereas Procedures cannot be called from Function.
6.Procedure contains DML statement whereas function allows only select statement.
6.Exception handling can be done in stored Procedure only (More...)

What is the difference between stored procedure and function.

  
Below is main differences between two.
1) Procedure can return zero or n values whereas function can return one value which is mandatory.
2) Procedures can have input, output parameters for it whereas functions can have only input parameters.
3) Procedure allows select as well as DML statement in it whereas function allows only select statement in it.
4) Functions can be called from procedure whereas procedures cannot be called from function.
5) Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in a function.
6) We can go for transaction management in procedure whereas we can't go in function.
7) Procedures cannot be utilized in a select statement whereas function can be embedded in a select statement. (More...)

What is the difference between "dynamic SQL" and "stored procedure" ?

  
Dynamic sql is the bunch of statements that dynamically constructed at run time and not stored in database.
Where as Stored procedures are stored in data base in complied form. (More...)

whats the difference between a stroed procedure and a user defined function

  
udf ll return only one output parameter where as sp returns more(2100 not sure)

udf are called directly by their name in a pgm where as exec spname
is used to execcute an sp (More...)

Difference between Store Procedure and function?

  
S.No Store Procedure Function
1. Return Null or Value Return Value
2. Input,OutPut Parameter Input Parameter
3. Call independently Call SQL Statement
4. Not called from Function Called from Procedure (More...)

Database: Difference between stored procedure and trigger?

  
.Stored procedure are called explicitly where as trigger are called implicitly.
.Stored procedure are not attached to specific table where as triggers are attached to specific table.
.Stored procedure are called by invoking a CALL to it where this does not applies in case of trigger.


(More...)

What are the differences between Stored procedure and function.

  
Below are the main differences between stored procedure and functions-
1.Function has a return type but Stored procedure doesn't have a return type.
2.Stored Procedure supports IN/OUT/IN-OUT Parameters while function supports only IN parameters.
3.Stored procedure can contain all the DML(Select,update,insert,delete) statements but function can contain only select statement.
4.Function can be called from a stored procedure but stored procedure cannot be executed from a function.
5.For Exception Handling, the stored procedure can contain try---catch block but Function doesn't support try---catch block.
(More...)

What is a Stored Procedure?

  
Its nothing but a set of T-SQL statements combined to perform a single task of several tasks. Its basically like a Macro so when you invoke the Stored procedure, you actually run a set of statements. (More...)

Difference between a sub and a function.

  
A Sub Procedure is a method will not return a value
-A sub procedure will be defined with a "Sub" keyword
Sub ShowName(ByVal myName As String)
Console.WriteLine("My name is: " & myName)
End Sub
-A function is a method that will return value(s).
-A function will be defined with a "Function" keyword
Function FindSum(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
Dim sum As Integer = num1 + num2
Return sum
End Function (More...)

How to deal with return value of stored procedure when you are using DataReader ?

  
To deal with such scenario, you can find "ParameterDirection.ReturnValue" in .net
You can use this parameter direction to read the return value of the stored procedure.

Following example can make it more clearer.
In case, you have following or similar type of return statement somewhere in your stored procedure.
Return -999
To read this value, following code works,

Dim result As Integer = 0
Dim retValParam As New SqlClient.SqlParameter("@RETURN_VALUE", SqlDbType.Int)
retValParam.Direction = ParameterDirection.ReturnValue
dbCommand.Parameters.Add(retValParam)
database.ExecuteNonQuery(dbCommand)
result = retValParam.Value ' here the result must contain the returned value. In this case, it will be -999 (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

 
Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.


Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend