MySQL Lists are EOL. Please join:

List:General Discussion« Previous MessageNext Message »
From:Christian Mack Date:March 30 1999 10:35am
Subject:Re: Copying records from a table and re-inserting them
View as plain text  
Mike Watson wrote:
> I'm using Perl DBI to manage a set of MySQL tables. I want to copy a set of
> records from a table and re-insert them with a new radio station id.
> Selecting the set of records is no problem, but there is no equivalent of
> the SELECT * for the insert command (INSERT INTO *). What I have done is
> used show columns to get a list of field names and from this built a string
> for the insert command. I don't want to change any timestamp values, which I
> don't because I reference those fields in the insert string. I have had to
> look at field types and escape special chars in text fields. Now I have hit
> another wrinkle. We use a seperate id field as a primary key so I don't want
> to insert this value, I want the data base automatically pick a value for
> this field. Again, I can do this.
> Is there an easier way?
> Thanks
> Michael Watson

Hi Michael

You can do this with plain SQL.
INSERT INTO tableName SELECT field1,field2,'newRadioStation',field4,NULL,field6 ...

INSERT INTO tableName VALUES (...)
Is what you call a INSERT INTO tableName * VALUES (...).
Be sure to use the correct data sequence.


Copying records from a table and re-inserting themMike Watson29 Mar
  • Re: Copying records from a table and re-inserting themChristian Mack30 Mar