存储SET大于64的最佳方式 [英] Best way to store a SET bigger than 64
问题描述
我的网站有一个电影数据库,我正在重新设计,以提高效率。
电影
表有一个名为 countries
的字段。此时,使用csv将值存储在 varchar
中。例如:
西班牙,法国,德国
这是非常缺乏。例如,很难从
法国
中选择所有电影。
我不能使用
set
,因为有超过64个不同的国家。
我可以创建一个表格的国家和另一个表链接id_country
与id_movie
。但是,我需要另一个加入
来获取电影数据(像我对演员o导演)。
任何建议?
解决方案从我的角度来看,一个SET归一化解)使事情更复杂。
使用JOIN不是符合复杂性的东西,它是为数据库制作和擅长的。
如果您需要维护元素的已定义顺序,则必须向该查找表添加一个额外的排序列。
I have a database of movies for my website and I'm redesigning it to make it more efficient.
The
movies
table has a field calledcountries
. In this moment, the values are stored invarchar
, using csv. For example:Spain,France,Germany
This is very inneficient. For example, It's hard to select all movies from
France
.I can't use a
set
because there are more than 64 different countries. I could make a table of countries and another table that linksid_country
withid_movie
. But then I need to make anotherjoin
to get the movie data (like I do with actors o directors).Any suggestions? Which could be the best way to store the countries information?
解决方案From my point of view a SET (which is a non-normalized solution) makes things more complicated.
Using a JOIN is not something that qualifies as "complexity", it's what databases are made for and are good at.
If you need to maintain a defined order of the elements you will have to add an extra "sort" column to that lookup table.
这篇关于存储SET大于64的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!