mysql 用户角色权限表建立

来源:互联网 发布:matlab2013a软件激活 编辑:程序博客网 时间:2024/05/20 05:30

建表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. #外键一般去掉 用逻辑控制  


0 0
原创粉丝点击