mysql 用戶角色權限表建立

建表sql

[sql] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. #創建表使用的數據庫  
  2. use springmvc;   
  3. #權限表   
  4. create table authoritys(    
  5.     id_ smallint unsigned primary key auto_increment,#權限id  
  6.   name_ varchar(24) not null unique,#權限名字  
  7.   remark_ varchar(200) #備註  
  8. );  
  9. #角色表    
  10. create table roles(  
  11.     id_ smallint unsigned primary key auto_increment, #角色id   
  12.     name_ varchar(24) not null unique,#角色名字    
  13.     remark_ varchar(200)#備註  
  14. );  
  15. #角色權限表    
  16. create table roleAuthority(    
  17.     role_id_ smallint unsigned,#角色id    
  18.     authority_id_ smallint unsigned,#權限id     
  19.     primary key(role_id_,authority_id_),#主鍵    
  20.     foreign key(role_id_ ) references roles(role_id_ ),#外鍵角色id 引用角色表角色id    
  21.     foreign key(authority_id_) references authoritys(authority_id_)#外鍵權限id 引用權限表權限id  
  22. );   
  23. #用戶表   
  24. create table users(    
  25.     id_ smallint unsigned primary key auto_increment,#用戶id  
  26.     name_ varchar(24) not null unique,#用戶名稱    
  27.     password_ char(20) not null,#密碼    
  28.     create_time_ datetime not null,#創建時間  
  29.     creator_id_ smallint unsigned, #創建者id      
  30.     remark_ varchar(200),#備註    
  31.     foreign key(creator_id_) references users(user_id_)#外鍵 創建者id 引用用戶表用戶id   
  32. );  
  33. #用戶角色表    
  34. create table userRole(  
  35.     user_id_ smallint unsigned,#用戶id    
  36.     role_id_ smallint unsigned,#角色id  
  37.     primary key(user_id_,role_id_),#主鍵 用戶id 角色id  
  38.     foreign key(userID) references users(user_id_),#外鍵用戶id 引用用戶表用戶id  
  39.     foreign key(roleID) references roles(role_id_)#外鍵角色id 引用角色表角色id   
  40. );  
  41. #菜單表  
  42. create table menus(  
  43.     id_ smallint unsigned primary key auto_increment,#菜單id  
  44.     name_ch_ varchar(100),#中文名字  
  45.     name_en_ varchar(200),#英文名字  
  46.     parent_id_ smallint unsigned,#父節點id   
  47.     order_id_ smallint unsigned,#同一父節點下的排序  
  48.     menu_auth_ varchar(200),#菜單對應的權限  
  49.     auth_id_ smallint unsigned,#權限對應id  
  50.     img_url_ varchar(200)#菜單圖片對應的鏈接  
  51. );  
  52. #外鍵一般去掉 用邏輯控制  


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章