Google News
logo
SQL Server - Interview Questions
What is a function in SQL Server?
Functions are part of SQL. A function in SQL Server is a group of statements that might take input, perform some task and return a result.
There are two types of function in SQL Server :
 
* System Defined Function : These functions are built-in ready-to-use and provided by SQL Server. Pass in input parameters if it takes one and get the result.

Example : Below code show min, max, and sum of ‘salary’ column values from ‘employee’ table
SELECT MIN(salary) AS MinSalary, MAX(salary) AS MaxSalary, SUM(salary) AS TotalSalary
FROM employee
 
* User Defined Function : These are the functions that are written by users.
CREATE FUNCTION getAverageSalary(@salary int)
RETURNS int
AS
BEGIN RETURN(SELECT @salary)
END
Advertisement