Difference between Function and Procedure-in general?

Answer Posted / s.chandrahasan

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.

Is This Answer Correct ?    4 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is the difference between openrowset and openquery?

769


How you provide security to cube? : sql server analysis services, ssas

743


Difference between Sql server reporting services and Crystal reports?

139


query processing

1931


What is use of except clause? How it differs from not in clause?

769


Which are the third-party tools used in sql server and why would you use them?

667


What is the use of set nocount on/off statement?

833


How do I find query history in sql server?

685


Can you explain important index characteristics?

700


How can you know if the row fetched from cursor is still valid in underlying table?

771


How you can move data or databases between servers and databases in sql server?

779


What are the pre-defined functions in the sql server?

706


How do I find the size of a sql server database?

660


What are click through reports?

118


Explain transaction server explicit transaction?

686