visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Databases :: MySql :: mysql move old records to new table


By: Bernard France  Date: 10/06/2007 08:43:13  English  Points: 20 Status: Answered
Quality : Excellent
Using mysql , I want to move old records to new table.

How ?
By: VGR Date: 10/06/2007 09:35:32 English  Type : Answer
hummm classical problem again :D

if you use a front-end scripting language, the solution below applies.

let's stay at the "mysql console" level and let's suppose you're using a mysql user that has enough privileges (drop/create table in particular)

what I would do if I were you :

create table table2 like table1; insert into table2 select * from table1 WHERE your_where_clause; delete from table1 WHERE your_where_clause; (optional) OPTIMIZE TABLE table1;



Caveat : your index structure will NOT be copied correctly to table2 using the "create table like" command ; on the other side, the IDs (primary key) values will be copied over "as is". This solution is thus very good for making static extractions to reduce a table size, while retaining the extracted rows in backup tables. Because of this, you can always re-insert the extracted lines directly with :

insert into table1 select * from table2;



If you need fully identical and functional tables, then you need to apply an ALTER TABLE statement on table2 to reproduce excatly the PRI, INDEX etc structure of table1.

regards

Do register to be able to answer

EContact
browser fav
page generated in 736.964940 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page