English 中文(简体)
建立表格,储存每个记录的可变数量?
原标题:Set up Table to store variable number of fields per record?

如果我不了解我按记录居住的领域的数量,那么我应如何建立我的数据库/表格?

例如,如果我有一个网络形式,使用户能够进入他拥有的所有汽车,而且我不想将他限制在一定数目之内,那么我如何在数据库中储存这一点?

以上问题涉及类似情况,如储存用户订单(每批物品数量不变)。

最佳回答

相反,在相关数据库管理系统中,你在与上级实体(用户)联系的附属表格中制作儿童记录。 有一个称为数据库热化>的概念,目标是每个表格都包含单一类型的实体的数据。

因此,有<条码>用户。 用户信息表:

user_id | user_name | email             | ...
  1234  | User1     | user1@example.com | ...
  2356  | User2     | user2@example.com | ...

接下来是一份储存用户每辆汽车信息的表格:

user_car_id | user_id | car_label | make      | model | ...
          1 |   1234  | MyCar     | Ford      | 2011  | ...
          2 |   2356  | A Car     | Chevrolet | 2010  | ...
          3 |   1234  | MyOtherCar| BMW       | 2000  | ...

因此,不要在<条码>用户上储存汽车的内装。 表1. 按<代码>用户_id栏列出的与每个用户有关的信息。 这是一种单人关系的例子,在这种关系中,用户可以拥有许多相关的汽车。

问题回答

这是一个完整的议题:数据库的正常化。

答案很短,你的发言不止一个。

在你的例子中,你有一张个人桌子、一张汽车桌和一个把人与汽车联系起来的第三张汽车。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...