sql - Mysql tables link with each other -
i create 3 tables in mysql:
movies: id-name-country tv-series: id-name-country artists: id-name-country
instead of entering country info these tables seperately, planning create table:
countries: id-country
and create first 3 tables take country info countries table. (so that, if name of 1 country misspelled, easy right in 1 place. info in other tables updated automatically.
can "foreign keys"? is right approach?
your approach far correct, only if "country" in tv-series , artist mean country id , not value. , yes can utilize foreign keys (country id in tv-series , artist foreign key linking countries);
edit: side note: looking @ edit sense obliged point out if planning link movie/tv-show artist need 4th table maintain normalization you've got far.
edit2: usual way decide whether need tables check kind of connection 2 tables or values have.
if it's 1 many (like artist country of origin), fine. if have many many, film artist 1 artist can in multiple movies , 1 film can have multiple artists need linking table. if have 1 1 relation (like customer_id , passport details in banking system, stored separately in client , passport tables, joining them makes more sense because banks hold details of 1 valid passport each client , 1 passport can used 1 person) can merge tables (at risk of not meeting normalization 3 criteria) mysql sql
No comments:
Post a Comment