sql - How to assign 2 foreign keys to one row? -


i have tables roles , users. id roles foreign key of column role in table users.
there 2 roles: support , manager. how can specify, user peter assigned both of 2 roles?

roles

| id | role    | |----|---------| | 1  | support | | 2  | manager | 

users

| id | user     | pass  | role (fk) | |----|----------|-------|-----------| | 1  | peter    | hash1 | 1,2       | <-- 2 foreign keys | 2  | jennifer | hash2 | 2         | 

this classic many many relationship. 1 user can have many roles , 1 role can assigned many users. should need create new userrole table info this:

id userid roleid 1    1      1 2    1      2 3    2      2 4 ... 

if don't want surrogate keys, remove id , make userid+roleid primary key:

userid roleid   1      1   1      2   2      2 

Comments