Mysql
 sql >> Database >  >> RDS >> Mysql

Come gestire i ruoli utente in un database?

Utilizzi una tabella di join:role_id e permit_id per identificare quali autorizzazioni sono associate a quali ruoli

MODIFICA:

Tabelle di esempio

Tabella ROLE

Role_ID Role_Name
1       Standard User
2       Super User
3       Guest

Tabella PERMESSI

Permission_ID Permission_Name
1             View User List
2             Update Own User Account
3             Update Any User Account

Tabella ROLE_PERMISSION

Role_ID Permission_ID
1       1    // Role 1 (Standard User) grants View User List
1       2    //        and Update Own User Account
2       1    // Role 2 (Super User) grants View User List,
2       2    //        Update Own User Account,
2       3    //        and Update Any User Account
3       1    // Role 3 (Guest) grants View User List

Elenco delle autorizzazioni per un Role_ID specificato

select R.role_id,
       P.permission_id,
       P.permission_name
  from role R,
       permission P,
       role_permission RP
 where RP.permission_id = P.permission_id
   and RP.role_id = R.role_id
   and R.role_id = 1