[英]Mysql tables link with each other
I will create 3 tables in mysql: 我将在mysql中创建3个表:
Movies: id-name-country
Tv-Series: id-name-country
Artists: id-name-country
Instead of entering country information into these tables seperately, i am planning to create another table: 我计划不另外将国家/地区信息输入到这些表中,而是打算创建另一个表:
Countries: id-country
And i will make my first three tables take country data from Countries table. 我将使我的前三个表从“国家”表中获取国家数据。 (So that, if the name of one country is misspelled, it will be easy just to correct in one place. Data in other tables will be updated automatically. (因此,如果一个国家/地区的名称拼写错误,只需在一个地方更正即可。其他表格中的数据将自动更新。
Your approach so far is correct, ONLY IF by "country" in Tv-Series and Artist you mean country ID and NOT a value. 到目前为止,您的方法是正确的, 只有在电视连续剧和演出者中按“国家/地区”表示您的意思是国家/地区编号而不是值。 And yes you can use foreign keys (country id in tv-series and artist is a foreign key linking to Countries); 是的,您可以使用外键(电视系列中的国家/地区ID,而Artist是链接到国家/地区的外键);
Edit: Side note: looking at your edit I feel obliged to point out that If you are planning to link Movie/TV-Show with artist you need a 4th table to maintain normalization you've got so far. 编辑:旁注:查看您的编辑,我不得不指出,如果您打算将Movie / TV-Show与artist链接,则需要第4张表来保持标准化。
Edit2: The usual way to decide whether you need tables is to check what kind of connection 2 tables or values have. Edit2:决定是否需要表的通常方法是检查2个表或值具有哪种连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.