SQL SERVER – Deterministic Functions and Nondeterministic Functions

Deterministic functions always returns the same output result all the time it is executed for same input values. i.e. ABS, DATEDIFF, ISNULL etc.

Nondeterministic functions may return different results each time they are executed. i.e. NEWID, RAND, @@CPU_BUSY etc. Functions that call extended stored procedures are nondeterministic. User-defined functions that create side effects on the database are not recommended.

Reference : Pinal Dave (http://blog.SQLAuthority.com)

6 thoughts on “SQL SERVER – Deterministic Functions and Nondeterministic Functions

  1. Pingback: SQL SERVER - Function Property - Deterministic or Non-Deterministic Journey to SQL Authority with Pinal Dave

  2. I’m working on loading data into tables using some stored-procedures as a model for doing so. In one stored-procedure is this variable assignment

    SELECT TOP 1 @RowD = RowID FROM NameofTable WHERE ReferenceID = @ReferenceID;

    Glancing over it I did not notice anything of significance. Then I put it into practice in the script that is loading data. When testing I immediately saw it was not returning what I was expecting it to return. Based on what the original SP was doing I was expecting it to return the highest ID. But it wasn’t Then I realized there is no ORDER BY clause. To me this is saying the SELECT statement is non-deterministic. When the tests were run the result was the same value, but that value was neither the lowest or highest value.

    I just though this is a good example of expecting something but not getting because of a missing ORDER BY clause


  3. select OBJECTPROPERTY(OBJECT_ID(‘dbo.AddNumbers’), ‘IsDeterministic’); return 0. The AddNumbers function simply adds two numbers. it is deterministic function. then why objectproperty function is returning zero instead of one.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s