---
title: "What is Difference between Function and Stored Procedure?"  
description: "What is Difference between Function and Stored Procedure?"  
author: "Oasge Christiansen"  
published: 2017-11-20  
updated: 2024-07-18  
canonical: https://answers.mindstick.com/qa/30982/what-is-difference-between-function-and-stored-procedure  
category: "technology"  
tags: ["database", "database programming", "stored procedure"]  
reading_time: 3 minutes  

---

# What is Difference between Function and Stored Procedure?

What is [Difference](https://www.mindstick.com/blog/398/difference-between-object-type-and-var-type) between [Function](https://www.mindstick.com/articles/43970/purchase-suitable-wedding-dresses-for-your-wedding-function) and [Stored Procedure](https://www.mindstick.com/articles/202/the-detailed-concept-of-stored-procedure-in-sql-server)?

## Answers

### Answer by Amartya Singh

## Overview:

![Stored Procedure Vs Function in SQL Server](https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTbPui6NC6VHTRR4yvVZBuuguAZbyyBOqTwRg&s)

## Reason:

Function: Basically, it is used to register a value and bring it back. Capabilities can be utilized in [**SQL**](https://www.mindstick.com/articles/336409/optimize-sql-server-for-high-concurrency-workloads) questions.

[Stored](https://www.mindstick.com/interview/644/where-is-the-output-of-explain-stored) [Procedure](https://www.mindstick.com/blog/304484/explain-the-sql-stored-procedures): Intended to play out a particular undertaking, which can incorporate various tasks like supplement, update, erase, or complex estimations.

## Use in SQL articulations:

Function: Can be called from a SQL proclamation (e.g., SELECT, WHERE, or JOIN provisions).

Stored Procedure: Can't be called straightforwardly from SQL proclamations. They are executed utilizing the Executive or EXECUTE order.

## Boundaries:

Function: Just permits input boundaries.

Stored Procedure: Permits info, result, and info yield boundaries.

## Exchanges:

Function: Can't contain exchange the board proclamations (e.g., Start Exchange, Commit, Rollback).

Stored Procedure: Can incorporate exchange on the board to guarantee information respectability.

## Blunder dealing with:

Function: Restricted blunder dealing with abilities. Utilization of attempt CATCH blocks isn't permitted in all data sets.

Stored Procedure: Improved mistake taking care of with Attempt CATCH blocks.

## Execution:

Function: By and large, it is quicker for straightforward estimations and can be streamlined by the data set motor.

Stored Procedure: Can be advanced for complex tasks and different proclamations. Put away systems are precompiled, which can further develop execution.

## Secondary effects:

Function: Should be liberated from secondary effects, meaning it shouldn't change the condition of the information base (no additions, refreshes, or erases).

Stored Procedure: Can have side impacts by adjusting the data set state by performing DML tasks.

## Code Reusability:

Function: High reusability inside SQL inquiries because of their capacity to straightforwardly bring values back.

Stored Procedure: High reusability for performing explicit errands that require numerous tasks or complex business rationale.

## Execution:

Function: Executes inside the setting of a SQL proclamation and returns a value straightforwardly to the assertion.

Stored Procedure: Executes as a different bunch and doesn't straightforwardly return a value to the calling SQL proclamation.

## Settling and recursion:

Function: Can be settled and called recursively, dependent upon information base cutoff points.

Stored Procedure: Can call different strategies and themselves (recursion), considering complex tasks.

By understanding these distinctions, [**designers**](https://en.wikipedia.org/wiki/Designer) can pick the most fitting development in light of the particular prerequisites of their data set tasks and application rationale.

Read more: [How does Google's Cloud SQL manage relational databases in the cloud](https://answers.mindstick.com/qa/102683/how-does-google-s-cloud-sql-manage-relational-databases-in-the-cloud)


---

Original Source: https://answers.mindstick.com/qa/30982/what-is-difference-between-function-and-stored-procedure

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
