Function vs Stored Procedure in SQL Server

0 votes
I've been learning Functions and Stored Procedure for quite a while but I don't know why and when I should use a function or a stored procedure. They appear to be the same to me, which might be due to the fact that I am new to this.

Could someone perhaps explain why?
Feb 17 in Database by Vaani
• 7,020 points
812 views

1 answer to this question.

0 votes
Functions are calculated values that cannot make lasting modifications to SQL Server's environment (i.e., no INSERT or UPDATE statements allowed).

If a function provides a scalar value, it may be used inline in SQL queries; if it returns a result set, it can be joined on.

Functions must return a value and cannot change the data they receive as parameters, as defined by computer science (the arguments). Functions can't modify anything and must have at least one parameter. They also have to return a result. Stored procedures don't need a parameter, may modify database objects, and don't have to return a result.

Stored procedures are used to connect SQL queries in a transaction and to communicate with the outside world. ADO.NET and other frameworks can't call a function directly, but they can call a stored procedure.
answered Feb 17 by Neha
• 8,940 points

edited Feb 17 by Neha

Related Questions In Database

0 votes
0 answers

If else in stored procedure sql server

I have created a stored procedure as ...READ MORE

Aug 22 in Database by Kithuzzz
• 20,660 points
105 views
0 votes
0 answers

What is the syntax to drop a Stored Procedure in SQL Server 2000?

In SQL Server 2000, how do you ...READ MORE

Aug 25 in Database by Kithuzzz
• 20,660 points
80 views
0 votes
0 answers

Search text in stored procedure in SQL Server

I want to search all of my ...READ MORE

Aug 27 in Database by Kithuzzz
• 20,660 points
87 views
0 votes
1 answer

How to Execute SQL Server Stored Procedure in SQL Developer?

You don't need EXEC clause. Simply use: proc_name ...READ MORE

answered Sep 16 in Database by narikkadan
• 37,660 points
174 views
0 votes
1 answer

What is a stored procedure?

A stored procedure is a set of ...READ MORE

answered Feb 4 in Database by Neha
• 8,940 points
292 views
0 votes
0 answers

What is a stored procedure?

119 What is a "stored procedure" , how do they work? What ...READ MORE

May 27 in Others by avinash
• 1,840 points
51 views
0 votes
0 answers

Loop in stored procedure in SQL server

Writing a stored procedure that calls another ...READ MORE

Aug 28 in Database by Kithuzzz
• 20,660 points
303 views
0 votes
1 answer

How do I UPDATE from a SELECT in SQL Server?

MERGE INTO YourTable T USING ...READ MORE

answered Feb 3 in Database by Vaani
• 7,020 points
167 views
0 votes
1 answer

LEFT JOIN vs. LEFT OUTER JOIN in SQL Server

At the top level there are mainly ...READ MORE

answered Feb 4 in Database by Neha
• 8,940 points
276 views
0 votes
1 answer

SQL Server replaces LEFT JOIN for LEFT OUTER JOIN in view query

You are getting the joins confused and ...READ MORE

answered Feb 4 in Database by Neha
• 8,940 points
289 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP