数据类型相当于数据库中的 SET?
我想为我的数据库使用 SET
数据类型。这样该类型的字段就可以包含该数据类型的一个或多个值。
但我有以下两个问题:
Q1。 SET
在数据库中用作数据类型是否正确?我认为并非所有数据库都支持它。
Q2。如果SET
不是一个好的选择,那么我可以用什么来代替SET
?
I want to use a SET
datatype for my databse. So that a field of that type can contain one or more values from that data type.
But I have following two questions:
Q1. Is SET
is correct to use as a datatype in a database? I think that its not supported by all the databases.
Q2. If SET
is not a good option, then what can I use in place of SET
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,您应该使用带有外键的表:
例如,您将拥有如下数据:
以便该类型的字段可以包含该数据类型的一个或多个值
我不会推荐这个。最佳实践是每个“字段”仅存储一个值。在单个字段中存储多个值违反了数据库规范化的原则,并且会导致问题你尝试从“集合”中取出特定的项目。最好将每个值拆分为自己的行,这意味着更改表设计。提供有关您尝试存储的数据的更多信息,我可以为您推荐一个表结构。You should use a table for this with a foreign key:
So for example, you'd have data like this:
as for the
So that a field of that type can contain one or more values from that data type
I would not recommend this. It is best practice to store only one value per "field". Storing multiple values in a single field is against the principle of Database normalization and will result in issues when you try to pull particular items out of the "set". It is best to split each value into its own row, which means changing your table design. Supply more information about the data you are trying to store and I can recommend a table structure for you.