SQLite - 存储多个值 [英] SQLite - storing multiple values

查看:30
本文介绍了SQLite - 存储多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 SQLite 数据库中存储和检索同一列同一行的多个值?

how can I store and retrieve in SQLite database multiple values for the same row of the same column?

即我有一个产品栏,另一栏是商店,我把所有商店都放在那里,在那里可以买到这个产品:

i.e. I have a product column and another column is stores, where I put in all the stores, where it is possible to get this product:

Product: iLamp;
Stores: River's; McWay; Lonnie's; ...

我该如何实施?

提前致谢.

推荐答案

就像其他人提到的,你可以把它存储为逗号分隔的字符串,然后把它放在你的数据库中,但就像 ocdecio 提到,你现在拥有表格的方式是糟糕的设计.您应该考虑执行一些操作,例如添加另一个表,例如具有两列的 PRODUCT_TO_STORE 表,其中一个列包含产品的键,另一列包含商店的键.然后是产品和商店之间的关系,有助于规范您的数据,这在大多数情况下是一件好事.然后,当您需要查找产品所在的所有商店时,您只需对该 PRODUCT_TO_STORE 表执行查询即可.

like others have mentioned, you could store it as a comma separated string, and then put that in your database, but like ocdecio mentioned, the way you have your tables right now is bad a design. You should consider doing something like adding another table, like a PRODUCT_TO_STORE table that has two columns, one has the key of a product, and the other column has the key to a store. Then there is a relationship between products and stores, and helps normalize your data, which in most cases, is a good thing. Then when you need to find all the stores a product is in you could just perform a query on that PRODUCT_TO_STORE table.

这篇关于SQLite - 存储多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆