last day (14 days later) » 

7:57 AM
0
A: Fastest way to insert Data into MySQL in multiple Tables in C#

LoathingCan you break the CSV into two files? E.g. Suppose your file has the following columns: ... A ... | ... B ... a0 | b0 a0 | b1 a0 | b2 <-- data a1 | b3 a1 | b4 So one set of A might have multiple B entries. After you break it apart, you get: ... A ... a0 a1 ... B ... b0 b1 b2 b3 b4 Th...

 
sure i can split the CSV-File into two but how to set the Relationship e.g. a0:b0?
 
Based on the primary keys of Table A. If there are no primary keys then decide which columns form a unique A.
 
you don't know that primary key 123 from table A belongs to primary key 30001 from table B when i leave the FK-column during bulk insert empty
 
So you have auto-increment columns that are your primary keys?
 
sure. otherwise i would have to check if this pk is already in use or manage the duplicate error - for each row
 
7:57 AM
Are the tables truncated before the bulk insert? Or is the csv appended to existing data?
 
i need to append the data each time - probably i should edit the question :)
hey :)
 
It sounds like your CSV file comes with pre-populated primary key values. Correct?
 
no unfortunately not :(
table1 is like: userid, username, ...
 
Oh. Then how do you identify a unique 'A' record, because it will have multiple 'B' records.
 
table2 is like: user-property1, user-property2, ... user-property1000
yes
 
8:02 AM
Username is the unique identifier?
*unique column for A
 
no a autoincremeting userid-col
 
But your CSV file doesn't have userid values yet.
 
correct
 
So your file might look like:
 
username, firstname, lastname,...
username, firstname, lastname,user-property1, user-property2, ... user-property1000
 
8:05 AM
And table B has a userid column, correct?
 
yes
user-propertyid, userid, propertyname
 
ok, in a few minutes I'll post an idea
 
ty
 
Sorry, one more question. The primary key is userid, but is username constrained to be unique?
 
 
3 hours later…
11:05 AM
should be but i can't rely on it
can you post your answer to my question so i can mark it
 

last day (14 days later) »