What is the difference between a function and a stored procedure?

All topics about programming / development in T-SQL or other languages for SQL Server.
Post Reply
Laura1996
Posts: 17
Joined: Thu Jun 20, 2019 6:41 pm

Sat Jun 29, 2019 10:13 am

What is the difference between a function and a stored procedure?
Tilly
Posts: 8
Joined: Wed Jun 26, 2019 4:49 pm

Sat Jun 29, 2019 10:17 am

Hi @Laura1996 :)

A Function Must Return a Value, whereas a Stored Procedure doesn't have to return a value, it's optional.

Stored Procedures are pre-compile objects which are compiled for the first time and its compiled format is saved which executes (compiled code) whenever it is called, whereas a Function is compiled and executed every time when it is called.

A Function can Accept only Input Parameters, but a Stored Procedure Can Accept Both Input and Output Parameters.

Functions can be called from Procedure whereas Procedures cannot be called from Function.

Functions, like Views only Accept Data Select Statements It does not Allow the Permanent Storage of data so it does not allows DML statements like Insert , Update , Delete, but a Store Procedure Allows All type of DML statements like Insert , Update and also Select Statements.

Functions can be used in Select Statements like views to View data, whereas a Stored Procedure Cannot be Embedded in Select Statements.
Post Reply

Social Media