Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By qqboy on
We see there is 3 tables
- users
- role
- users_roles
May I ask where there is 3 table, but why not 2 tables, and put uid in role table, and rid in users table ?
Can some one make it clear for us. Thanks.
May i know what reason behind this design structure?
May I know how many records for a normally-designed database table can be called a 'big data', or how many bytes of data can be called 'big data' which result a 'slow query'?
Thanks.
Comments
Users defines user. Ex:
Users defines user. Ex:
* Jaypan (uid 1)
* qqboy (uid 2)
Roles defines roles. Ex:
* admin (rid 3)
* moderator (rid 4)
users_roles connects the two. Ex:
UID | RID
1 | 3 (Jaypan is an admin)
1 | 4 (Jaypan is a moderator)
2 | 4 (qqboy is a moderator)
This structure allows for multiple users to have multiple roles. It's called a many-to-many relationships.
If the uid was in the role table, only one UID could be given for each role. This means only one person could be assigned to each role.
If you put rid in users table, it means each user could only be assigned one role. This means that users could not have multiple roles.
If the uid was in the role
Not exactly, for example, you can put rid of 1 and 2 to one user by rid 1-2-58-12 what ever what as you like.
What do you think ?
https://www.drupal.org/project/image_captcha_indicator
https://www.drupal.org/project/ext_js
You mean multiple values in a
You mean multiple values in a single column?
yes
yes
then
is that any problem ?
https://www.drupal.org/project/image_captcha_indicator
https://www.drupal.org/project/ext_js
All sorts of problems. For
All sorts of problems. For example, if I want to remove the admin role from Jaypan, I would use:
How would you do that if multiple values were packed in the same column? I'm not even sure it could be done in a single query.
And what about selecting all users of a role? This wouldn't work:
because you'd get users with role 3, 33, 333 etc.
And this wouldn't work:
SELECT uid FROM {users} WHERE role LIKE "%-3-%"
because if your column looked like3-4-5
, it would not find it.Also, you couldn't index the column on the role. So even if you found a query that allowed you to select all users of a given role, you couldn't index the column properly to ensure that query worked quickly.
There are many other issues too. It's a bad practice to store multiple values in a single column.
Hopefully that clears it up for you!
ok
ok
what you said is reasonable.
Thanks.
You are so gooooooooooooood.
https://www.drupal.org/project/image_captcha_indicator
https://www.drupal.org/project/ext_js
Thanks :)
Thanks :)
Database Normalization
You may want to familiarize yourself with database normalization: https://en.wikipedia.org/wiki/Database_normalization
--
Read more at iRolo.net
called database normalization
called database normalization seems not very applicable in drupal.
i think there always a contradiction between redundancy and less query.
if no database reduncy, there will be many table query.
how would you balance it ?
thanks and regards.
https://www.drupal.org/project/image_captcha_indicator
https://www.drupal.org/project/ext_js