Databases :: MySql :: mysql move old records to new table |
|||
| By: Bernard |
Date: 10/06/2007 08:43:13 |
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 | 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 |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








