I want to create a system of user groups that imitates group policy in instant messengers.
Each user can create as many groups as he wants, but they cannot have groups with duplicate names, and they can put as many friends as they want in any groups.
For example, John’s friend Jen can be in John’s “school” group and John’s “colleagues” at the same time. And it does not depend on how Jen puts John in her group.
I think of two possible ways to implement this in the database user_group table.
1.
user_group (
id INT PRIMARY KEY AUTO_INCREMENT,
user_id INT,
group_name VARCHAR(30),
UNIQUE KEY (user_id, group_name)
)
In this case, all groups belonging to all users will have a unique identifier. Thus, only an identifier can identify a user and group name.
2.
user_group (
user_id INT,
group_id INT AUTO_INCREMENT,
group_name VARCHAR(30),
PRIMARY KEY (user_id, group_id),
UNIQUE KEY (user_id, group_name)
)
group_id 0 , group_id s. pk (user_id, group_id) .
?
?
EDIT:
AUTO_INCREMENT group_id , , 0 user_id.
EDIT:
"" ...
- SELECT/INSERT/UPDATE , .
- , .
- .
-
-
- - .