· 8 years ago · Aug 28, 2018, 02:20 AM
1How to connect the users table to the roles table (using the table user_roles)?
2create table if not exists users (
3 id int unsigned not null auto_increment,
4 username varchar(100) not null,
5 password binary(60) not null,
6 primary key(id),
7 unique(username)
8);
9
10create table if not exists roles (
11 id int unsigned not null auto_increment,
12 role varchar(100) not null,
13 primary key(id),
14 unique(role)
15);
16
17create table if not exists user_roles (
18 user_id int unsigned not null,
19 role_id int unsigned not null,
20 unique(user_id, role_id),
21 index(user_id)
22);
23
24---- Users Table ---------
25ID | UserName | Password
26 1 | Test | *****
27--------------------------
28
29---- Roles Table ---------
30ID | Role
31 1 | Test_Role
32 2 | Another_Role
33--------------------------
34
35---- User Roles Table ---------
36UserID | RoleID
37 1 | 1
38 1 | 2
39-------------------------------