Function In SQL Server Part VIII

Function IN SQL Server

Function :
  • A function is a set of SQL statements that perform a specific task. 
  • Functions foster code reusability.
There are Two Type of Function :

A) System Defined Function :
  • System functions are built-in database functions. 
There are two types of system-defined functions in SQL Server :

1) System Scalar Functions :
  • Scalar are on single value and returns single value.
2) System Aggregate Functions :
  • Aggregates the values and return a single value.
B) User-Defined Function :
  • User-defined functions are create by a user.
There are three types of user-defined functions in SQL Server :

Table :
tblCustomer 

1) Scalar Function :
  • It is a function that takes one or more values but returns a single value.
Steps :

1) Select Function then Right click on Function and select new Scalar-valued Function in Programmability : 


2) Example - Create Scalar-valued Function :


3) Scalar-valued Function Created Successfully :

4) Output :

2) Inline Table-Valued Function :
  • It returns a table variable as a result of actions perform by function. 
  • The value of table variable should be derived from a single SELECT statement.
1) Select Function then Right click on Function and select new Inline Table-valued Function in Programmability : 


2) Example - Create Inline Table-valued Function :

3) Inline Table-valued Function Created Successfully :


4) Output :

3) Multi-Statement Table-Valued Function :
  • Multi-statement table-valued function returns a table variable as a result of actions perform by function. 
  • In this a table variable, must be explicitly declared and defined whose value can be derived from a multiple sql statements.
1) Select Function then Right click on Function and select Multi-statement Table-valued Function in Programmability : 
2) Example - Create Multi-statement Table-valued Function :

3) Multi-statement Table-valued Function Created Successfully :


4) Output :




Comments

Popular posts from this blog

Basic Concept In C Sharp Day 16

Understanding C Sharp Day 18

Concept In Angular Day 14