Insert/Update/Delete with function in SQL Server

Pankaj Agarwal picture Pankaj Agarwal · May 27, 2011 · Viewed 146.6k times · Source

Can we perform Insert/Update/Delete statement with SQL Server Functions. I have tried with but SQL Server error is occured.

Error:

Invalid use of side-effecting or time-dependent operator in 'DELETE' within a function.

AnyBody have any Idea why we can not use Insert/Update/Delete statements with SQL Server functions.

Waiting for your good idea's

Answer

Mitch Wheat picture Mitch Wheat · May 27, 2011

No, you cannot.

From SQL Server Books Online:

User-defined functions cannot be used to perform actions that modify the database state.

Ref.