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 > copying multiple rows into the same table with new primary key supplied?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-23-08, 23:45
syntaxerror syntaxerror is offline
Registered User
 
Join Date: Apr 2006
Posts: 157
copying multiple rows into the same table with new primary key supplied?

ei guys,


question, how do i insert multiple rows, (around 40, perhaps) into the same table)
with new primary keys eg.

existing rows

(primary keys being field 1 and field 2)

field 1 field2 field 3

00 a data1
00 b data2
00 c data3

rows to insert to look like this

01 a data1
01 b data2
01 c data3
__________________
Only quitters quit!
Reply With Quote
  #2 (permalink)  
Old 01-24-08, 06:49
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
not sure i understand the question

just go ahead and do the insert as normal
Code:
INSERT
  INTO yourtable
     ( field1, field2, field3 )
VALUES
     ( 01, 'a', 'data1' )
   , ( 01, 'b', 'data2' )
   , ( 01, 'c', 'data3' )
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 01-27-08, 19:17
syntaxerror syntaxerror is offline
Registered User
 
Join Date: Apr 2006
Posts: 157
I just felt there must be some way for me to copy something like a thousand rows, with 8 - 10 fields each

into a new set of thousand rows with different primary keys from the previous, but exactly the same value in other fields
__________________
Only quitters quit!
Reply With Quote
  #4 (permalink)  
Old 01-27-08, 19:50
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
yes, it's possible, but where would the different primary key values come from?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 01-28-08, 01:40
syntaxerror syntaxerror is offline
Registered User
 
Join Date: Apr 2006
Posts: 157
i can just append something to the existing primary key... but i'm confused as to how the form of this query would be... hope you won't mind giving me that?
__________________
Only quitters quit!
Reply With Quote
  #6 (permalink)  
Old 01-28-08, 07:35
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
try this --
Code:
INSERT
  INTO yourtable
     ( field1
     , field2
     , field3 )
SELECT 01
     , field2
     , field3
  FROM yourtable
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 01-28-08, 18:15
syntaxerror syntaxerror is offline
Registered User
 
Join Date: Apr 2006
Posts: 157
aha, i think i see where my problem was

i was using INSERT INTO table () values (SELECT ...);

many thanks, i guess i'm still a big baby with query manipulation, bad dragdown habits from MSAccesss still here
__________________
Only quitters quit!
Reply With Quote
  #8 (permalink)  
Old 01-28-08, 18:32
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
you cannot say INSERT INTO table () values (SELECT ...) in msaccess either
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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