Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

The Voice of the DBA

Steve Jones is the editor of SQLServerCentral.com and visits a wide variety of data related topics in his daily editorial. Steve has spent years working as a DBA and general purpose Windows administrator, primarily working with SQL Server since it was ported from Sybase in 1990. You can follow Steve on Twitter at twitter.com/way0utwest

Deterministic Functions

Do you know what determinism is? It's something that comes up periodically in Books Online as various SQL objects require deterministic functions. Things like indexes views.

I ran across a question on this for our ASK site, and thought it was interesting. I started to reply, then had to double check myself and make sure by looking things up in Books Online. I was right, though I'm not sure I'd have been able to actually classify all functions correctly.

For example, RAND can be either deterministic or non-deterministic, depending on how it's used. If you have a seed value, it's deterministic. CAST and CONVERT are usually deterministic but it depends on the data type. There are some good exceptions spelled out in this BOL entry: Deterministic and Nondeterministic Functions

I knew that deterministic meant you could determine the output given the input, and that these are "predictable" functions. However I didn't realize that somethings, like GetDATE() wouldn't fit. It always returns the current time/date, but it's not based on input, or the database, so it doesn't count. It's a non-deterministic function.

Non-deterministic functions like the @@ ones (@@Connections, @@idle, etc.) are listed, and I'm not sure I'd have thought of them off the top of my head, but it was good to read them in the article. Next time I need to I should remember, or at least be able to easily scan code and decide if it's deterministic or not.

Comments

Posted by Robert Davis on 28 October 2009

Getdate() is non-deterministic because the value it outputs is affected by outside forces. For example, I can change the value returned by Getdate() by changing the time on the server.

Leave a Comment

Please register or log in to leave a comment.