php - Send deleted rows to another table

964

Let's say that I have a table X and table Y. I wanted to delete rows from table X and I wanted to send the deleted rows to table Y. How would I do that? Can someone please help me. :( thanks a lot.

502

Answer

Solution:

Assuming Table X & Y are the exact structure

First:

insert into tableY select * from tableX where condition;

Then:

delete from tableX where condition;
955

Answer

Solution:

this may be help you

mysql> create table X(id int)
-> ;
Query OK, 0 rows affected (0.51 sec)


mysql> create table Y(id int)
-> ;
Query OK, 0 rows affected (0.34 sec)

mysql> delimiter |
mysql> create trigger on_delete before delete on X for each row begin 
       insert into Y set id =  OLD.id;
       end ;
       Query OK, 0 rows affected (0.06 sec)
mysql> insert into x (1),(2);

mysql> delete from X;

mysql> select * from Y;

      +------+
      | id   |
      +------+
      |    1 |
      |    2 |
      +------+
   2 rows in set (0.00 sec)

you can do this with mysql trigger.more reference learn about trigger

People are also looking for solutions to the problem: php - Laravel 4.2 Join Table and Pagination

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.