And the SQL parser, optimizer and data engine rely heavily on the assumption that functions cannot cause changes in the database while they are being invoked. Almost all of the restrictions in UDF revolve around insuring that this is the case.
And one of the reasons for that is so that the optimiser is free to pick execution plans without worrying about how many times the function will be executed.
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)SQL In The Wild
: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter
We stand on the bridge and no one may pass