gpt4 book ai didi

php - 关系数据库设计: User lists

转载 作者:行者123 更新时间:2023-11-29 23:01:34 26 4
gpt4 key购买 nike

背景

我正在设计一个数据库,该数据库将允许在我的网站上注册的人创建列表。这些列表将由用户组成。该功能类似于 Twitter Lists 。我正在使用 PHP 和 MySQL。

到目前为止我的尝试

到目前为止,我已经想出了两张表:

用户(用户 ID、名字、姓氏)

列表(list_id、标题、描述)

我现在意识到我需要第三个表来连接这两个表,但正在努力想出它应该具有的字段列表。我的第一个想法是我需要 idlist_iduser_id 字段,但不确定这是否是正确的方法。

我的问题

我需要在第三个表中创建哪些字段才能连接我的 USERSLISTS 表?

最佳答案

您需要的是数据透视表。您最终将得到您已经指定的三个表。

USERS(
user_id integer not null primary key,
first_name text not null,
last_name text not null
)

LISTS(
list_id integer not null primary key,
title text not null,
description text,
created_by integer references USERS
)

USERS_LISTS (
user integer not null references USERS,
list integer not null references LISTS,
unique (user, list)
)

USER_LISTS 是您完成这项工作所需的多对多粘合剂。 id 字段是不必要的。

关于php - 关系数据库设计: User lists,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28460979/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com