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, 2022 in Database by Vaani
• 7,020 points
18,365 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.

To know more about SQL, It's recommended to join SQL Course today.

answered Feb 17, 2022 by Neha
• 9,060 points

edited Feb 17, 2022 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, 2022 in Database by Kithuzzz
• 38,010 points
724 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, 2022 in Database by Kithuzzz
• 38,010 points
392 views
0 votes
0 answers

Search text in stored procedure in SQL Server

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

Aug 27, 2022 in Database by Kithuzzz
• 38,010 points
2,332 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, 2022 in Database by narikkadan
• 63,420 points
1,676 views
0 votes
1 answer

What is a stored procedure?

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

answered Feb 4, 2022 in Database by Neha
• 9,060 points
801 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, 2022 in Others by avinash
• 1,840 points
350 views
0 votes
0 answers

Loop in stored procedure in SQL server

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

Aug 28, 2022 in Database by Kithuzzz
• 38,010 points
1,400 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, 2022 in Database by Vaani
• 7,020 points
591 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, 2022 in Database by Neha
• 9,060 points
1,655 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, 2022 in Database by Neha
• 9,060 points
1,123 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