ForBeginner

8-4. MSSQL(Function과 Stored Procedure의 차이)

정착유목민 2021. 5. 4. 11:05

Following are the main differences between functions and procedures:

 

Functions Procedures. 
A function has a return type and returns a value. A procedure does not have a return type. But it returns values using the OUT parameters.
You cannot use a function with Data Manipulation queries. Only Select queries are allowed in functions. You can use DML queries such as insert, update, select etc… with procedures.
A function does not allow output parameters A procedure allows both input and output parameters.
You cannot manage transactions inside a function. You can manage transactions inside a function.
You cannot call stored procedures from a function You can call a function from a stored procedure.
You can call a function using a select statement. You cannot call a procedure using select statements

 

프로시저는 서버에서 실행 되고, 함수는 클라이언트에서 실해 되기 때문에, 프로시저의 속도가 더 빠르다. 

프로시저 사용자 정의 함수
업무를 맡기는 목적 로직을 도와주는 목적
SP 안에 트랜잭션을 사용할 수 있음 사용자 정의 함수 안에 트랜잭션을 사용할 수 없음
파라미터 형식이 입,출력임 입력 파라미터만 가능
프로시저 안에서 다른 프로시저를 호출할 수 있음 사용자 정의 함수 안에서 프로시저를 호출할 수는 없음
SELECT, WHERE, HAVING 절에 프로시저를 사용할 수 없음 SELECT, WHERE, HAVING 절에 사용자 정의 함수를 사용할 수 있음