Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting SCHEMABINDING and IsDeterministic for a CLR function

I have an existing C# CLR runtime function that I am using with SQL Server 2012. I would like to set the IsDeterministic and SCHEMABINDING options on this function so I can use it for persisting a computed column in a table.

Here is the alter statement:

ALTER FUNCTION [dbo].[authorityFromURI](@URI [nvarchar](4000))
RETURNS [nvarchar](4000) WITH EXECUTE AS CALLER
AS 
EXTERNAL NAME [KDPSqlServerProject].[UserDefinedFunctions].[authorityFromURI]

How should this alter statement be modified to set these options?

like image 223
JonnyBoats Avatar asked Jun 08 '26 08:06

JonnyBoats


1 Answers

You have to set the IsDeterminstic property within the function code itself, e.g

[SqlFunction(IsDeterministic = true, IsPrecise = true [...])]

To make it schemabinding:

RETURNS NVARCHAR(4000)
WITH SCHEMABINDING, EXECUTE AS CALLER

That said, I haven't tested these options together with persistence...

like image 162
Aaron Bertrand Avatar answered Jun 10 '26 17:06

Aaron Bertrand