Can we create scalar valued function in SQL Server

2019-07-31 09:16发布

问题:

Can we create a function in SQL Server to be deterministic and precise without CLR?

CREATE FUNCTION ufn_max_smalldatetime ()
RETURNS SMALLDATETIME
    WITH SCHEMABINDING
AS 
    BEGIN
        RETURN CAST('2079-06-06' AS SMALLDATETIME)
    END

回答1:

As far as I know SQL Server determines itself whether your function is deterministic and/or precise. Try running the following queries and see what you get:

SELECT OBJECTPROPERTYEX(OBJECT_ID('dbo.ufn_max_smalldatetime'), 'IsDeterministic')

SELECT OBJECTPROPERTYEX(OBJECT_ID('dbo.ufn_max_smalldatetime'), 'IsPrecise')