mysql - Adding a database record with foreign key -


let's there database 2 tables: 1 customer table , 1 country table. each customer row contains (among other things) countryid foreign key. let's assume populating database data file (i.e., not operator selecting country ui).

what best practice this?

  1. should 1 query database first , id's countries, , supply (now known) country id's in insert query? not problem 'country' example, if there large number of records in table being referred?

  2. or should insert query use sub query country id based on country name? if so, if record country not exist yet , has added?

  3. or approach? or depend? :)

i suggest using join in insert query country id based on country name. however, don't know if that's possible every sgbd , don't give more precision on 1 you're using.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -