What is function in SQL Server?
What is function in SQL Server?
I completed my post-graduation in 2013 in the engineering field. Engineering is the application of science and math to solve problems. Engineers figure out how things work and find practical uses for scientific discoveries. Scientists and inventors often get the credit for innovations that advance the human condition, but it is engineers who are instrumental in making those innovations available to the world. I love pet animals such as dogs, cats, etc.
Ashutosh Kumar Verma
16-Nov-2021SQL Function:
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.
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:
Execute of the above function,