Page 1 of 1
Automate copying tables?
Posted: Sat Jun 06, 2009 5:23 am
by HansieV
Hi all,
Is there a piece of code to perform following actions;
For several tables
-Copy table to <tablename_thisyear>
- Empty original table
Would be great...

Re: Automate copying tables?
Posted: Sat Jun 06, 2009 5:37 am
by Darhazer
You can use CREATA TABLE ... SELECT syntax to create a table from a SELECT Command
Re: Automate copying tables?
Posted: Sat Jun 06, 2009 5:42 am
by HansieV
Thanks Darhazer for your quick reply..
Unfortunately I'm not that good in writing php..
That's why I asked if there is a piece of code someone has lying around..
Sorry for being a noob..

Re: Automate copying tables?
Posted: Sat Jun 06, 2009 8:22 am
by Weirdan
Darhazer wrote:You can use CREATA TABLE ... SELECT syntax to create a table from a SELECT Command
Unfortunately in MySQL it won't copy any indexes.
Re: Automate copying tables?
Posted: Sat Jun 06, 2009 8:31 am
by onion2k
HansieV wrote:Thanks Darhazer for your quick reply..
Unfortunately I'm not that good in writing php..
That's why I asked if there is a piece of code someone has lying around..
Sorry for being a noob..

Learn.
Or pay someone.
Re: Automate copying tables?
Posted: Sat Jun 06, 2009 9:00 am
by HansieV
onion2k wrote:
Learn.
Or pay someone.
What kind of an answer is that..? I thought a Forum is a place where people helped other people..
Of course I can pay and buy scripts, of course I can subscribe for a study and learn..
But for your info, I'm trying to help (for free!) some other people with their website, which is in php.
If you don't have anything constructive to say, I don't (and I guess a lot of other 'help requesters') appreciate your interferance with my post.
Re: Automate copying tables?
Posted: Sat Jun 06, 2009 11:21 am
by onion2k
HansieV wrote:onion2k wrote:Learn.
Or pay someone.
What kind of an answer is that..? I thought a Forum is a place where people helped other people..
This is a forum where people help each other ... to learn. Just giving someone a script doesn't help anyone learn, so we're against it.
If you want help writing a script to achieve want you want then we'll give whatever help we can, but if you're asking for a solution to just be given to you for free (which is what you are doing) we won't help.
Re: Automate copying tables?
Posted: Sat Jun 06, 2009 3:01 pm
by Darhazer
Weirdan wrote:Darhazer wrote:You can use CREATA TABLE ... SELECT syntax to create a table from a SELECT Command
Unfortunately in MySQL it won't copy any indexes.
You are right, the better option is CREATE TABLE ... LIKE and then use INSERT INTO ... SELECT

On the other hand, it seems that the goal is to archive data, so creating the table with the same indexes may be not needed, and with the second option I'm afraid we can run in foreign key problems... never done it actually.
P.S.
HansieV may be you can just use a database management tool to perform this task?
Re: Automate copying tables?
Posted: Sat Jun 06, 2009 3:57 pm
by HansieV
Hi Darhazer,
I got the SQL queries running with Create Table, then truncate the original table.
What my original thought was, that I could create a button somewhere to perform these tasks with php.
Why? Like I said earlier, I am helping other people with their website, and want to make it as easy as possible for them to do this.
So maybe you can point me to a similair script or something.
Thanks for your assisting.
Re: Automate copying tables?
Posted: Sat Jun 06, 2009 4:41 pm
by Darhazer
HansieV wrote:Hi Darhazer,
I got the SQL queries running with Create Table, then truncate the original table.
What my original thought was, that I could create a button somewhere to perform these tasks with php.
Why? Like I said earlier, I am helping other people with their website, and want to make it as easy as possible for them to do this.
So maybe you can point me to a similair script or something.
Thanks for your assisting.
phpMyAdmin have this option. Just select the table, go to operations and choose copy table.