Question
Can I use a user-defined function (UDF) to populate an identity column?
Asked by: USER1211
71 Viewed
71 Answers
Answer (71)
No, using a UDF that returns a non-deterministic value to populate an identity column will result in error 18456. UDFs are evaluated each time they are called, and their output can change. Identity columns are meant to be auto-incrementing, and UDFs prevent this automatic behavior. The UDF must return a deterministic value if you absolutely must use one, but even then it's usually not the best approach.