向sql添加多个值
假设我有一列定义为地址。另外,我有一张唱片,我们就叫它鲁迪的吧。现在 Rudy's 有多个地址,所以我需要包含多个地址,以便它们都可以搜索。使用 SQL 解决方案的最佳方法是什么?
say i have a column defined as Address. also, I have a record, let's call it Rudy's. now Rudy's has multiple addresses, so I need to include multiple address so that they are all searchable. what is the best way to approach a solution in SQL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该添加一个带有地址列的子表。您将拥有一对多关系,其中地址存储在子表中。您可以根据需要为每个用户添加任意数量的地址。您还可以添加额外的信息,例如地址类型(家庭、工作或主要、次要等)。
我不会选择一列地址。如果这是邮政地址,最好有更多列,例如街道、城镇、门牌号等。然后,您可以享受在列上使用索引的优势。
You should add a child table with an Address column. You will have one to many relation where address is stored in a child table. You can add as many addresses per user as you want. Also you can add extra info like address type (home, work or primary, secondary ect.)
I wouldn't go for one column for address. If this is a postal address it is better to have more columns such as street, town, house number ect. Then you can have an advantage of using indexes on your columns.
您可以尝试这样的操作:
当然,您可以将其设置为您想要的复杂程度,并遵循之前存储地址类型等的建议。
从 http://sqlserversamples.codeplex.com/ 并遵循他们的最佳实践。
You could try something like this:
Of course you can have it as complex as you want and follow the previous advice for storing address types etc.
It might help to download MS examples from http://sqlserversamples.codeplex.com/ and follow their best practices.