[英]How to design a database where I can add unsettled number of items
I have a form in which I fill following things: 我有一个填写以下内容的表格:
Nick: SbsNick;
Item: SomeItem1; Price: PriceOfItem1
Item: SomeItem2; Price: PriceOfItem2
Item: SomeItem3; Price: PriceOfItem3
................................
And I can add items with varying number of inputs. 而且我可以添加输入数量不同的项目。 It means that each Nick can have different number of items.
这意味着每个尼克可以拥有不同数量的物品。
I want to create the database where I can query 我想创建可以查询的数据库
SELECT ? FROM items WHERE Item="SomeItem"
and receive all nicks and prices of SomeItem, ie I want to end up with the table like that: 并获得SomeItem的所有刻痕和价格,即我想以这样的表格结束:
Nick |Price
-------------
Jack |20
BlackB |18
Karl |25
.............
I have a problem with designing such database, cause I feel that I lack of one additional dimension. 我在设计这样的数据库时遇到问题,因为我觉得我缺少一个额外的维度。 If I want to fix ammount of tables I see that I need unlimited amount of columns in some table.
如果我想修复大量的表,我会发现某些表中的列数不受限制。 If I want to bound ammount of tables and columns I see that cells must behave like array.
如果要绑定大量的表和列,我会看到单元格的行为必须类似于数组。
Is there a clever way to design such database? 有设计这种数据库的聪明方法吗?
I think that you need to study about Relational Data Bases. 我认为您需要研究关系数据库。 I can not understand what is your exact problem.
我不明白您的确切问题是什么。
You need three tables: USERS, ITEMS, PURCHASES
. 您需要三个表:
USERS, ITEMS, PURCHASES
。 One for representing the users, another for the items and the last for representing the relation between both of them. 一个代表用户,另一个代表项目,最后一个代表两者之间的关系 。
USERS(ID_USER, NAME, NICK, REGISTER_DATE)
ITEMS(ID_ITEM, DESCRIPTION, PRICE)
PURCHASES(ID_PURCHASE, ID_USER, ID_ITEM, PRICE, PURCHASE_DATE)
I have used the name PURCHASES because I personally don't know the exact nature of the relation between users and items in your problem, be free to name that third table whatever you want. 我之所以用PURCHASES作为名称,是因为我个人不知道问题中用户和项目之间关系的确切性质,因此可以随意命名第三个表。
There is no need for extra new columns for each purchase that the user does in table USERS nor in table ITEMS, you only have to insert a new row in table PURCHASES. 用户在表USERS或表ITEMS中进行的每次购买都不需要额外的新列,只需在表PURCHASES中插入新行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.