0

I have a registration page where a user can register him/herself along with 20 other people. Now I can store all those values in fine, the question I have is how to identify in the table. So let's say John registers himself and 20 of his friends. In the table, I would label him and his group with an ID number of 1, but I would label his ID specifically with a star so I know that he's the one who registered everyone else.

That's the idea I'm trying to get at, but I don't know how to do that in practice. What is the best way and how do I really go about doing this? I think I can write the code but I just need some concepts to work off of.

4

4 回答 4

1

您可以为此创建三个表。其中UserList包含所有用户的所有记录。其中GroupList包含所有组和组的所有者。最后PersonGroup包含user_id和某个用户所属的组。

CREATE TABLE UserList
(
    ID INT AUTO_INCREMENT,
    FullName VARCHAR(50),
    -- ... other columns if you want ...
    CONSTRAINT ul_pk PRIMARY KEY (ID),
    CONSTRAINT ul_uq UNIQUE (FullName)
);

CREATE TABLE GroupList
(
    ID INT AUTO_INCREMENT,
    GroupName VARCHAR(25),
    OwnerID INT,
    -- ... other columns if you want ...
    CONSTRAINT gl_PK PRIMARY KEY (ID),
    CONSTRAINT gl_UQ UNIQUE(GroupName),
    CONSTRAINT gl_FK FOREIGN KEY (OwnerID) REFERENCES UserList(ID)
);

CREATE TABLE PersonGroup
(
    RecordID INT AUTO_INCREMENT,
    User_ID INT,
    GROUP_ID INT,
    CONSTRAINT pg_PK PRIMARY KEY (RecordID),
    CONSTRAINT pg_uq UNIQUE (User_ID, GROUP_ID),
    CONSTRAINT pg_FK1 FOREIGN KEY (User_ID) REFERENCES UserList(ID),
    CONSTRAINT pg_FK2 FOREIGN KEY (GROUP_ID) REFERENCES GroupList(ID)
);
于 2012-09-18T00:43:23.187 回答
0

这可能是@Adrian 所说的重复,但我并没有真正理解他的意思,所以......

当 John 注册时,他会得到一个 user_id,对吗?

向表中添加 registrar_id 列。

对于其他 20 条用户记录,将 John 的 user_id 放入 registrar_id 列。

于 2012-09-18T00:34:42.323 回答
0

有点难以完全准确,但也许记录用于注册的 ip,然后您通常会知道有多少帐户来自该 ip。

于 2012-09-18T00:22:46.457 回答
0

如果他们注册的是 NULL,那么添加一个 RegisteredByID 列怎么样,然后也很容易找到该组。

于 2012-09-18T00:24:03.523 回答