mysql 用户角色权限表建立

本文介绍了一种基于角色的访问控制系统的设计方案,包括权限表、角色表、用户表及其相互间的关系建立。通过SQL语句详细说明了如何创建这些表,并定义了各表字段的意义及表之间的关联。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

建表sql

#创建表使用的数据库
use springmvc; 
#权限表 
create table authoritys(  
	id_ smallint unsigned primary key auto_increment,#权限id
  name_ varchar(24) not null unique,#权限名字
  remark_ varchar(200) #备注
);
#角色表  
create table roles(
	id_ smallint unsigned primary key auto_increment, #角色id 
	name_ varchar(24) not null unique,#角色名字  
	remark_ varchar(200)#备注
);
#角色权限表  
create table roleAuthority(  
	role_id_ smallint unsigned,#角色id  
	authority_id_ smallint unsigned,#权限id   
	primary key(role_id_,authority_id_),#主键  
	foreign key(role_id_ ) references roles(role_id_ ),#外键角色id 引用角色表角色id  
	foreign key(authority_id_) references authoritys(authority_id_)#外键权限id 引用权限表权限id
); 
#用户表 
create table users(  
	id_ smallint unsigned primary key auto_increment,#用户id
  	name_ varchar(24) not null unique,#用户名称  
	password_ char(20) not null,#密码  
	create_time_ datetime not null,#创建时间
  	creator_id_ smallint unsigned, #创建者id    
	remark_ varchar(200),#备注  
	foreign key(creator_id_) references users(user_id_)#外键 创建者id 引用用户表用户id 
);
#用户角色表  
create table userRole(
	user_id_ smallint unsigned,#用户id  
	role_id_ smallint unsigned,#角色id
  	primary key(user_id_,role_id_),#主键 用户id 角色id
  	foreign key(userID) references users(user_id_),#外键用户id 引用用户表用户id
  	foreign key(roleID) references roles(role_id_)#外键角色id 引用角色表角色id 
);
#菜单表
create table menus(
	id_ smallint unsigned primary key auto_increment,#菜单id
	name_ch_ varchar(100),#中文名字
	name_en_ varchar(200),#英文名字
	parent_id_ smallint unsigned,#父节点id 
	order_id_ smallint unsigned,#同一父节点下的排序
	menu_auth_ varchar(200),#菜单对应的权限
	auth_id_ smallint unsigned,#权限对应id
	img_url_ varchar(200)#菜单图片对应的链接
);
#外键一般去掉 用逻辑控制


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

筱芙淘趣坊

为嗷嗷待哺的我助力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值