Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert/Update/Delete with function in SQL Server

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

like image 313
Pankaj Agarwal Avatar asked May 27 '11 10:05

Pankaj Agarwal


People also ask

Can we use insert update delete in function in SQL?

No, you cannot. From SQL Server Books Online: User-defined functions cannot be used to perform actions that modify the database state.

How do I insert update delete?

Q #1) What is INSERT, UPDATE, and DELETE in SQL? Answer: The INSERT, UPDATE, and DELETE are commands in SQL which help to operate and update data. The INSERT statement inserts rows to a table. DELETE statement deletes rows from a table and the UPDATE statement updates values in the rows of the table.

Which method is used to insert update and delete SQL statement?

The following SQL stored procedure is used insert, update, delete, and select rows from a table, depending on the statement type parameter. Now press F5 to execute the stored procedure.


1 Answers

No, you cannot.

From SQL Server Books Online:

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

Ref.

like image 92
Mitch Wheat Avatar answered Sep 19 '22 14:09

Mitch Wheat