---
title: "What is function in SQL Server?"  
description: "What is function in SQL Server?"  
author: "Steilla Mitchel"  
published: 2021-11-15  
updated: 2021-11-15  
canonical: https://www.mindstick.com/forum/156839/what-is-function-in-sql-server  
category: "mssql server"  
tags: ["sql server", "sql"]  
reading_time: 2 minutes  

---

# What is function in SQL Server?

What is [function in SQL](https://www.mindstick.com/forum/159039/is-there-a-max-function-in-sql-server-that-takes-two-values-like-math-max-in-dot-net) [Server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over)?

## Replies

### Reply by Ashutosh Kumar Verma

**SQL [Function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server):**

A function is a sequence of statement that accepts values as input, processing them and provide result as output. A function must have a unique name and a function name can not starts with special character like- @, #, $, … and so on.

## Types of Function:

There are generally two types of function used in [SQL server](https://www.mindstick.com/articles/12999/what-is-table-valued-function-in-sql-server).

1- Predefined function.

2- User defined function.

## Predefined Function:

This function is also called system function which are created automatically by the system.

## User Defined Function:

A user defined function is created by developer. It is create for a specific task according to needs. The main advantage of this function is that we are not limited just like predefined function. We can write our own function for out need or simplify the SQL code. The return type of a function is a scalar values or a table.

A SQL function is must return a value and it works with input parameter. Function is compile every time, try and catch statement are not used in function.

## Example:

![What is function in SQL Server?](https://www.mindstick.com/mindstickforums/80a053c9-64c3-4436-ab98-e1f23b54c1bd/images/36a29abc-9f9f-4fa0-b86b-2858a10dee7a.png) **\**

Execute of the above function,

![What is function in SQL Server?](https://www.mindstick.com/mindstickforums/80a053c9-64c3-4436-ab98-e1f23b54c1bd/images/658df6de-b69c-441d-a8cc-6575a00460ca.png)

![What is function in SQL Server?](https://www.mindstick.com/mindstickforums/80a053c9-64c3-4436-ab98-e1f23b54c1bd/images/83eb373b-6966-43a7-a195-56e042007e71.png)

\


---

Original Source: https://www.mindstick.com/forum/156839/what-is-function-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
