What is the difference between Stored Procedure and Functions (at least 3)?

Stored Procedures and Functions are both database objects used to encapsulate and execute a series of SQL statements. However, they have some key differences in terms of their purpose, usage, and return values. Here are at least three differences between Stored Procedures and Functions:


CREATE PROCEDURE proc_name

(@Ename varchar(50),

@EId int output)

AS

BEGIN

      INSERT INTO Employee (EmpName)

      VALUES (@Ename)

      SELECT @EId= SCOPE_IDENTITY() 

END

 

CREATE FUNCTION function_name

 (parameters) --only input parameter

RETURNS data_type AS

BEGIN

    -- SQL statements

      RETURN value

END; 

 

Post a Comment

Previous Post Next Post