FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Delete and insert records from one table to another table.





najubudeen
Hi, I am having two mysql tables "table1" and "table2". I want to delete the table1's records. At the same time, the deleted records from table1 should be inserted into table2. How cai i do this? Anybody help me please?

thanks in advance.
adri
One way to do it, is to loop through the first table and for every record, you insert it in the second table and then delete it in the first one.

You could also just insert it and in the end remove the whole first table. (DROP TABLE)
sonam
Maybe you can try to copy all datas from old table in new one. Is this new one empty? If is not then you need to protect the same ID's with IGNORE otherwise you will get replaced rows.

Code:
INSERT INTO second_table SELECT * FROM frist_table;


Sonam
Marcuzzo
Code:

SELECT * INTO table2 FROM table1



http://www.w3schools.com/sql/sql_select_into.asp
welshsteve
You could also use phpMyAdmin to achieve this very easily using the "Operations" tab on the the first table. This gives you an option to copy the data from one table into another table. Once this is done you can remove the first table.
Related topics
script backup database
How To : Secure Your PHP Website
PHP magic_quotes_gpc question
What is useful way in this php+mysql problem?
[PHP] phpbb registration - add to other db
NEED HELP IN VIEWS AND TRIGGERS
mySQL Query/PHP code - get the highest value...
MIcrosoft SQL Server- Help for deleting records
SQL vs mySQL
xls to mysql Converter
Database connection class!
MySQL Database Backup Using PHP
AUTO INCREMENT VALUE
what does constraint foreign key means when we create table
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.