插入到通过引用表连接到另一个表的表中? [英] Inserting into a Table joined to another Table by a reference table?
问题描述
我在通过 IRC 与许多人讨论后提出了这个数据库设计.
I came up with this database design after discussing it with many people over IRC.
在我的项目中,一个用户又名成员可以拥有许多团队"&他帐户上的项目",也可以是某些项目"的一部分.此外,团队"也可以有许多成员",包括创建它的成员.
In my project, a User aka Member can have many "Teams" & "Projects" on his account and can be part of some "Projects" as well. Moreover, "Teams" can have many "Members" as well including the Member who is creating it.
现在我的问题是,假设一个成员想要在他的帐户下创建一个项目或一个团队(稍后我想查看特定成员创建的所有项目),我可以做一个插入到在 PHP 中使用以下内容?
Now my question is, suppose, a Member wants to create a Project or a Team under his account (later on I want to see all projects created by a specific member), can I do a insert into the using following in PHP?
INSERT INTO projects VALUES(values) WHERE member_id = something
我猜我可以使用会话变量获取 member_id.
I can get the member_id using the session variable I guess.
推荐答案
使用常规 INSERT
创建 projects
或 teams
行,然后使用在那里创建的 ID 插入 projects_members
或 teams_members
.还要为您的表确定复数或单数名称(目前您有 team
而不是 teams
).
Use regular INSERT
to create the projects
or teams
row, then use the ID created there to insert into the projects_members
or teams_members
. Also settle on plural or singular names for your tables (currently you have team
not teams
).
这篇关于插入到通过引用表连接到另一个表的表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!