If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > any short cut for many insert into statements

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-09-11, 02:32
newbielgn newbielgn is offline
Registered User
 
Join Date: Jul 2011
Posts: 14
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
Reply With Quote
  #2 (permalink)  
Old 08-09-11, 02:38
pasthana@netlink. pasthana@netlink. is offline
Registered User
 
Join Date: Jul 2011
Location: India
Posts: 13
hi,
u can perform this task with single insert statement using loop also
Reply With Quote
  #3 (permalink)  
Old 08-09-11, 03:18
reeson reeson is offline
Registered User
 
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;
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On