How to Insert JSON into a Table in SQL Server

If you have a JSON document that you need to insert into a table in a SQL Server database, the OPENJSON() function could be just what you need.

OPENJSON() is a table-valued function that returns JSON in tabular format. That is, it converts your JSON into a tabular result set consisting of rows and columns. Therefore, it enables you to insert it into a table.

Continue reading

Create a Schema Bound UDF in SQL Server

In SQL Server, it’s usually a good idea to schema bind your user-defined functions (UDFs).

Schema binding your UDF will ensure that the underlying tables can’t be changed in a way that would affect your function. Without schema binding, the underlying tables or other objects could be modified or even deleted. Doing this could break the function.

Continue reading

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