[thelist] Q on table(s) INSERTs

Maximillian Schwanekamp anaxamaxan at neptunewebworks.com
Sun Mar 28 01:43:51 CST 2004

 I have 3 tables, each linked to the other...
   1) Event - evt_id
   2) Contact - contact_id
   3) Company - cpy_id

 Same goes for EVENT. How would you INSERT a new event, with a new contact,
 with a new company?
First question is, what RDBMS (Database Server) are you using?  SQL Server,
MySQL, or...?
Also, what scripting language are you using?  PHP,ASP,ColdFusion,VBScript,

But a general answer is that since you have a hierarchical relationship,
you'll do an insert first on Company and fetch the resulting cpy_id, then
insert into Contact with the cpy_id and then fetch the resulting contact_id,
and finally insert into Event with the contact_id.  That could be done with
a single query batch on MS SQL, or with three PHP statements on MySQL, or
with some other solution depending on your specifics.

Maximillian Von Schwanekamp
voice: 541-302-1438
fax: 208-730-6504

More information about the thelist mailing list