English 中文(简体)
无法图示正确的数据库设计
原标题:Unable to figure out correct database design

我正在设计一个数据库,用于与“跟踪者”和“跟踪”特征(如前线)的社会网络网站。 有些关系是整个圈子,即我跟随的人和我的追随者所共有的。 我的桌子是紧接的1和2。 附录A如下:A和C。 它将有类似条目。

uid1 uid2
A      B
B      A
B      C

现在需要第三个外地关系 载于同一表格中,该表应有别于A在B或B之后的A类。

uid1 uid2  relationId
A     B      1
B     A      1
B     C      2 

so that i can use relationId as foreign key in another table to store features common to whole circle of a user. One thing immediately comes to mind is if there can be a commutative formula to fetch a unique number( relationId) given two numbers(uid1 and uid2). But what it can be?

Edit


我也有一个疑问。 由于我数据库中的用户名称是独一无二的。 因此,应当把用户名称作为整个数据库的主要关键,或者我们是否通过使用一些数据作为我用一个表格解决所建和用户名称的主要关键,来获得业绩效益?

最佳回答

I would do it similar to the way you have it:

Follows
-------
follower followed
A        B
B        A
B        C

这显然可以有如下信息:followDate,在这两个方向都有意义。

Then you can also have:

Connected
-----------------
relationId uid1 uid2
x          2    3

<代码>relation Id 人造钥匙(可以是INTTOINCREMENT, GUID, 等)

但是,连接会有一个制约因素(如果你能够在 d层执行,取决于你的系统),即<代码>uid1 < uid2。 显然,这也意味着你永远不会有两种方式。

这相对简单,容易盘问,并且应当具有良好的综合独特指数,即<代码>uid1和uid2。 在寻找有关关系的非直接信息时,你不必研究这两个方向的指数。

EDIT:我建议对用户使用人为钥匙。 即使你现在不允许用户名称发生变化,你可能希望以后这样做。

EDIT2:根据this,你可以拒绝在。 两个小孩都应是NOT NUL,因此,如果uid1 >=uid2,你就可以把一个孩子交给全国人民代表大会。

问题回答

暂无回答




相关问题
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 ...

热门标签