How to Encrypt a User-Defined Function in SQL Server

When creating a user-defined function in SQL Server, you have the option of encrypting it.

To create a user-defined function with T-SQL, you use the CREATE FUNCTION syntax. To encrypt it, you add the WITH ENCRYPTION argument.

You can also use the same argument to encrypt an existing function when using ALTER FUNCTION.

Continue reading

Difference Between Multi-Statement Table-Valued Functions & Inline Table-Valued Functions in SQL Server

When you create a table-valued function (TVF) in SQL Server, you can either make it an inline table-valued function (ITVF) or a multi-statement table-valued function (MSTVF). There are differences between these function types, and they use a different syntax accordingly.

This article covers the difference between MSTVFs and ITVFs.

Continue reading

Introduction to Multi-Statement Table-Valued Functions (MSTVF) in SQL Server

In SQL Server, the multi-statement table-valued function is one of two types of Transact-SQL table-valued functions (the other type being the inline table-valued function).

Table-valued functions (TVF) are a type of user-defined function that return their results as a table. They can therefore be queried just like a normal table.

Continue reading

Introduction to Inline Table-Valued Functions (ITVF) in SQL Server

In SQL Server, the inline table-valued function is one of two types of Transact-SQL table-valued functions (the other type being the multi-statement table-valued function).

Table-valued functions (TVF) are a type of user-defined function that return their results as a table. They can therefore be queried just like a normal table.

Continue reading

Update Data via a Table-Valued Function in SQL Server

In SQL Server, it’s possible to update data via a table-valued function.

What I mean is, you can update data in the underlying tables that the function queries.

For example, if your function returns someone’s first name from a table, you can update their first name by running an UPDATE statement against the function instead of the table.

Note that this only works on inline table-valued functions (ITVFs). As far as I’m aware, it won’t work on multi-statement table-valued functions (MSTVFs).

Also, the columns you update will need to be valid columns in the function’s query.

Continue reading