what is difference between function and stored procedure in sql?

Posted by Bageshkumarbagi under Sql Server on 11/7/2012 | Points: 10 | Views : 1556 | Status : [Member] | Replies : 5
hi
what is difference between function and stored procedure in sql? give some example and where we use function and where we use store procedure.

Thanks,
Bagesh Kumar Singh
Mark as answer if you have been satisfied



Responses

Posted by: Sandhyab on: 11/7/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
Please Refer this
http://www.dotnetfunda.com/forums/thread8939-difference-between-function-and-stored-procedure-in-sql-server.aspx

Thanks & Regards
Sandhya


Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naraayanan on: 11/7/2012 [Member] Starter | Points: 25

Up
0
Down
Hi ,
Refer this link
http://beginsql.wordpress.com/2012/06/16/difference-between-stored-procedure-and-user-defined-function-in-sql-server/

Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Saratvaddilli on: 11/8/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Function and stored procedure both are a set of statements which should be executed as unique i.e suppose if they are 3 statements create ,insert, select in the function/Store procedure . We can say our function/Store procedure executed successful if and only if all the above three statements executed successful as a unique
main differences
SP May return Zero or n Values as a result but function should return a single value as Output

Once Go through this Link

http://www.codeproject.com/Tips/286539/Difference-between-stored-procedure-and-function


Thanks and Regards
V.SaratChand
Show difficulties that how difficult you are

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Saratvaddilli on: 11/8/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi bageshkumarbagi
Please Mark as answer if it helps you

Thanks and Regards
V.SaratChand
Show difficulties that how difficult you are

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sravya on: 11/8/2012 [Member] Starter | Points: 25

Up
0
Down
A stored procedure is like a miniture program in SQL Server. It can be as simple as a select statement, or as complex as a long script that adds, deletes, updates, and/or reads data from multiple tables in a database. (Stored procedures can also implement loops and cursors which both allow you to work with smaller results or row by row operations on data.)

The SQL Server functions are option for doing certain operations in SQL Server. They can not be used to update, delete, or add records to the database. They simply return a single value or a table value. They can only be use to select records. However, they can be called very easily from within standard SQL, such as:

SELECT dbo.functionname('Parameter1')

OR

SELECT Name, dbo.Functionname('Parameter1') FROM sysObjects

For simple reusable select operations, functions can simply your code. Just be wary of using JOIN clauses in your functions. If your function has a JOIN clause and you call it from another select statement that returns multiple results, that function call with JOIN those tables together for EACH line returned in the result set. So though they can be helpful in simpling some logic, they can also be a performance bottleneck if they're not used properly.

Thanks & Regards
Sravya

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response