OUTPUT output in MySQL

Is there any way to simulate an OUTPUT clause in MySQL, since we have an OUTPUT clause in SQL Server.

Here is the question I have

UPDATE employee SET empage = 10 OUTPUT INSERTED.empid WHERE (empage < 10) 

Since I need to have this functionality for a MySQL server database too.

Please suggest the best way to achieve this functionality.

+19
sql mysql
Apr 28 '11 at 10:50
source share
1 answer
  • You can create a trigger and paste the desired values ​​into another table.
  • I'm not sure, but for MYISAM tables, you can lock the employee table, select and paste values ​​into another table, and then update and unlock the employee table.

EDIT:

I tried one script with InnoDb table, it seems to work -

 START TRANSACTION; SELECT * FROM table WHERE id = 1 FOR UPDATE; -- lock rows -- Or call this select to insert and lock rows -- INSERT INTO table_output SELECT * FROM table WHERE id = 1 FOR UPDATE; -- Make modifications UPDATE table SET column1 = '111' WHERE id = 1; COMMIT; 

SELECT statement (for an UPDATE clause)

+12
Apr 28 2018-11-11T00:
source share



All Articles