Actually the question is why it cannot be used in functions and a group of other similar non-deterministic functions (for example, Rand ())?

Is this some kind of MS SQL feature or is it similar in other DBMS?

From the side, I see no reason for the ban.

    1 answer 1

    Workaround:

    create view getNewID as select newid() as new_id create function myfunction () returns uniqueidentifier as begin return (select new_id from getNewID) end 

    Why - maybe NEWID () changes the state of the database:

    • Modify the database state.
    • Does newid () somehow change the state of the database? - iluxa1810
    • @ iluxa1810, perhaps (I saw the answers in the English SO, where they claimed they were changing), I can’t say for sure - MaxU
    • And Rand? Does he change something too? It's just, I can't believe it ... - iluxa1810
    • @ iluxa1810, look at this answer - MaxU
    • And in other DBMS the same situation? - iluxa1810