zgkhoo Posted December 10, 2007 Share Posted December 10, 2007 how to duplicate table? eg now i got one table name "testing123" and i wanna another copy of this table and using different name .."testing456"...how to do that? thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/80962-how-to-duplicate-table/ Share on other sites More sharing options...
btherl Posted December 10, 2007 Share Posted December 10, 2007 If you just want to copy the data, you can use CREATE TABLE foo SELECT * FROM bar If you want an exact copy including indexes and so on, I can't help you there. Quote Link to comment https://forums.phpfreaks.com/topic/80962-how-to-duplicate-table/#findComment-410814 Share on other sites More sharing options...
fenway Posted December 10, 2007 Share Posted December 10, 2007 If you just want to copy the data, you can use CREATE TABLE foo SELECT * FROM bar If you want an exact copy including indexes and so on, I can't help you there. Actually there's a "create table like" option to get the structure... and then you can simply insert into... select where 1=1. Quote Link to comment https://forums.phpfreaks.com/topic/80962-how-to-duplicate-table/#findComment-411090 Share on other sites More sharing options...
zgkhoo Posted December 10, 2007 Author Share Posted December 10, 2007 how to copy the structure and also the data too? use SELECT INTO or? thanks Quote Link to comment https://forums.phpfreaks.com/topic/80962-how-to-duplicate-table/#findComment-411120 Share on other sites More sharing options...
trq Posted December 10, 2007 Share Posted December 10, 2007 Read the replies above. Quote Link to comment https://forums.phpfreaks.com/topic/80962-how-to-duplicate-table/#findComment-411122 Share on other sites More sharing options...
zgkhoo Posted December 10, 2007 Author Share Posted December 10, 2007 If you just want to copy the data, you can use CREATE TABLE foo SELECT * FROM bar If you want an exact copy including indexes and so on, I can't help you there. wat is meant by indexes? thanks Quote Link to comment https://forums.phpfreaks.com/topic/80962-how-to-duplicate-table/#findComment-411124 Share on other sites More sharing options...
fenway Posted December 10, 2007 Share Posted December 10, 2007 If you just want to copy the data, you can use CREATE TABLE foo SELECT * FROM bar If you want an exact copy including indexes and so on, I can't help you there. wat is meant by indexes? thanks Seriously? Then read all the stickies first before posting anything else or ever working on a database. Quote Link to comment https://forums.phpfreaks.com/topic/80962-how-to-duplicate-table/#findComment-411147 Share on other sites More sharing options...
zgkhoo Posted December 23, 2007 Author Share Posted December 23, 2007 If you just want to copy the data, you can use CREATE TABLE foo SELECT * FROM bar If you want an exact copy including indexes and so on, I can't help you there. how to show the progress bar? eg 1% to 100% ? Quote Link to comment https://forums.phpfreaks.com/topic/80962-how-to-duplicate-table/#findComment-421654 Share on other sites More sharing options...
zgkhoo Posted December 23, 2007 Author Share Posted December 23, 2007 $sql = "CREATE TABLE $new_table SELECT * FROM template"; it wont set the primary key in the duplicate table ......how to solve it? set it manually ? thanks? Quote Link to comment https://forums.phpfreaks.com/topic/80962-how-to-duplicate-table/#findComment-421656 Share on other sites More sharing options...
zgkhoo Posted December 23, 2007 Author Share Posted December 23, 2007 and it also wont copy the engine....still myisam engine :-\ Quote Link to comment https://forums.phpfreaks.com/topic/80962-how-to-duplicate-table/#findComment-421670 Share on other sites More sharing options...
fenway Posted December 23, 2007 Share Posted December 23, 2007 If you just want to copy the data, you can use CREATE TABLE foo SELECT * FROM bar If you want an exact copy including indexes and so on, I can't help you there. how to show the progress bar? eg 1% to 100% ? Progress bar in mysql? $sql = "CREATE TABLE $new_table SELECT * FROM template"; it wont set the primary key in the duplicate table ......how to solve it? set it manually ? thanks? I didn't realize that was possible, to make a new table and copy the data in one step.... and it also wont copy the engine....still myisam engine :-\ Since I don't know that original table looks like, it's hard to guess. Quote Link to comment https://forums.phpfreaks.com/topic/80962-how-to-duplicate-table/#findComment-421996 Share on other sites More sharing options...
zgkhoo Posted December 24, 2007 Author Share Posted December 24, 2007 $sql = "CREATE TABLE pyrmain ( PID integer(10), Serialnum varchar(10), UplineSerial varchar(10), UplinePID integer(10), Downleft integer(10), LeftSerial varchar(10), Downright integer(10), RightSerial varchar(10), RowNum integer(10), ColumnPosi integer(10), ColumnTotal integer(10), DownlineAmount integer(10), Initial varchar(10), ActivateTime datetime, Status varchar(10), UserID varchar(10), ExpiredDate datetime, CreateDate datetime, Golden varchar(10), Primary Key (PID) )engine=innodb"; how to duplicate the primary key and the engine as well? thanks Quote Link to comment https://forums.phpfreaks.com/topic/80962-how-to-duplicate-table/#findComment-422167 Share on other sites More sharing options...
btherl Posted December 24, 2007 Share Posted December 24, 2007 I don't know if this helps for what you want to do, but "SHOW CREATE TABLE tablename" will give you the command to create a table. Then you can just edit the name and execute that command. Quote Link to comment https://forums.phpfreaks.com/topic/80962-how-to-duplicate-table/#findComment-422172 Share on other sites More sharing options...
zgkhoo Posted December 24, 2007 Author Share Posted December 24, 2007 mysql_query("ALTER TABLE $new_table ADD Primary Key (PID)"); can this work? Quote Link to comment https://forums.phpfreaks.com/topic/80962-how-to-duplicate-table/#findComment-422194 Share on other sites More sharing options...
fenway Posted December 25, 2007 Share Posted December 25, 2007 I don't know if this helps for what you want to do, but "SHOW CREATE TABLE tablename" will give you the command to create a table. Then you can just edit the name and execute that command. There's a CREATE TABLE LIKE command. Quote Link to comment https://forums.phpfreaks.com/topic/80962-how-to-duplicate-table/#findComment-422969 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.