Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2011
    Posts
    14

    Unanswered: any short cut for many insert into statements

    create table id_table (
    id int(11) unsigned,
    PRIMARY KEY (id)
    );

    create table reference_TABLE (
    fk_id int(11) unsigned,
    ref_name varchar(100),
    PRIMARY KEY (fk_id,ref_name),
    FOREIGN KEY (fk_id) REFERENCES id_table (id)
    );

    Content of tables:
    1) Table:id_table has 100 entries
    1
    2
    3
    ...
    100

    2) Table:reference_TABLE is empty

    Now i want to insert in to reference_TABLE with reference name newbie,each id from id_table.
    As we can see above we have 100 entries in id_table. Should i write 100 'inset into' statements to fill reference_TABLE or is there any other short cut to achieve this.

    -Thanks

  2. #2
    Join Date
    Jul 2011
    Location
    India
    Posts
    13
    hi,
    u can perform this task with single insert statement using loop also

  3. #3
    Join Date
    May 2011
    Posts
    24
    it should be something like

    Code:
    insert into reference_TABLE (fk_id,ref_name) select id,'newbie' from id_table;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •