Monday 15 February 2010

mysql - Creating a many to many relationship with uploaded data -



mysql - Creating a many to many relationship with uploaded data -

i've looked around internet, examples i've come across explain how form relationship user input. i'm looking below:

table 1

-----id--------name----------- 1 bill smithers 2 steve oneguy 3 mike michaels -------------------------------

table 2

----id------number--------charges------ 1 111-111-1111 $1.01 2 111-111-1111 $2.00 3 222-222-2222 $3.00 4 333-333-3333 $ .50 5 111-111-1111 $2.50 6 222-222-2222 $1.75 ----------------------------------------

result after joining tables this:

-----name-------------number-------------charges----- bill smithers 111-111-1111 $1.01 bill smithers 111-111-1111 $2.00 steve oneguy 222-222-2222 $3.00 mike michaels 333-333-3333 $ .50 bill smithers 111-111-1111 $2.50 steve oneguy 222-222-2222 $1.75 -------------------------------------------------------

now know there needs 3rd table holds relation, without manually entering relationship in, i'm not sure how 2 tables match accordingly. assume 3rd table needs this:

-----name_id-----------data_id--------- 1 1 1 2 2 3 3 4 1 5 2 6 ---------------------------------------

the source info comes in looking this:

-----name-------------number-------------charges----- bill smithers 111-111-1111 $1.01 bill smithers 111-111-1111 $2.00 steve oneguy 222-222-2222 $3.00 mike michaels 333-333-3333 $ .50 bill smithers 111-111-1111 $2.50 steve oneguy 222-222-2222 $1.75 -------------------------------------------------------

but want add together optimization because table going become much larger.

your application should have info in single glob, correct? each time person adds amount, utilize phone number? in way, can have application submit info person, phone/payment, getting id's both, can send insert 3rd table. alternately, submit pieces sp , have sp utilize output ids because application doesn't care.

this isn't how i'd arrange (as phone numbers can alter given person, making them poor identifiers), if looking solution, have each instance passed sp, , have sp duplicate checking name, inserting donation, , (using both ids) setup relationship.

mysql sql database database-design relational-database

No comments:

Post a Comment