From 2290f8e8bba120404290d2905eb5f84dac311f34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=97=AD=E4=B8=9C?= <1875779940@qq.com> Date: Wed, 25 Oct 2023 19:12:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=A8=E6=97=AD=E4=B8=9C=E7=9A=84=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...56\345\272\223\345\273\272\347\253\213.md" | 121 ++++++++++++++++++ .../20231016\347\264\242\345\274\225.md" | 43 +++++++ ...24\347\254\224\350\256\260\345\222\257.md" | 11 ++ 3 files changed, 175 insertions(+) create mode 100644 "55 \346\235\250\346\227\255\344\270\234/20230919\346\225\260\346\215\256\345\272\223\345\273\272\347\253\213.md" create mode 100644 "55 \346\235\250\346\227\255\344\270\234/20231016\347\264\242\345\274\225.md" create mode 100644 "55 \346\235\250\346\227\255\344\270\234/20231024\347\254\224\350\256\260\345\222\257.md" diff --git "a/55 \346\235\250\346\227\255\344\270\234/20230919\346\225\260\346\215\256\345\272\223\345\273\272\347\253\213.md" "b/55 \346\235\250\346\227\255\344\270\234/20230919\346\225\260\346\215\256\345\272\223\345\273\272\347\253\213.md" new file mode 100644 index 0000000..e179f0e --- /dev/null +++ "b/55 \346\235\250\346\227\255\344\270\234/20230919\346\225\260\346\215\256\345\272\223\345\273\272\347\253\213.md" @@ -0,0 +1,121 @@ +```MySQL +笔记 +RBAC:基于角色的访问权限管制模型(Role-Base Access Contral) + +RBAC中核心是角色,RBAC就是一种基调,一种基调 + +insert into 表名(字段名1,字段名2) select 数据1,字段名 from 表名 + +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2023-09-19 16:37:26 */ +/*==============================================================*/ + +create database hospital charset utf8; +use hospital; + +drop table if exists menu; + +drop table if exists menu_role; + +drop table if exists role; + +drop table if exists role_user; + +drop table if exists user; + +/*==============================================================*/ +/* Table: menu */ +/*==============================================================*/ +create table menu +( + menu_id int not null auto_increment, + menu_name varchar(20) not null, + primary key (menu_id) +); + + +insert into menu value +(1,'管理医生'), +(2,'监督医生'), +(3,'医治患者'); + + +/*==============================================================*/ +/* Table: menu_user */ +/*==============================================================*/ +create table menu_role +( + role_id int not null, + menu_id int not null, + primary key (role_id, menu_id) +); + +insert into menu_role value +(1,1), +(1,2), +(1,3), +(2,2), +(2,3), +(3,1); + +/*==============================================================*/ +/* Table: role */ +/*==============================================================*/ +create table role +( + role_id int not null auto_increment, + role_name varchar(20) not null, + role_tel char(11) not null, + primary key (role_id) +); + +insert into role value +(0,'主任医师',12345678901), +(0,'主治医师',1098765321), +(0,'医师',23456789012); + +/*==============================================================*/ +/* Table: role_user */ +/*==============================================================*/ +create table role_user +( + role_id int not null, + user_id int not null +); + +insert into role_user value +(1,1), +(2,2), +(3,3); + +/*==============================================================*/ +/* Table: user */ +/*==============================================================*/ +create table user +( + user_id int not null auto_increment, + role_name varchar(20) not null, + user_pwd char(5) not null, + primary key (user_id) +); + +insert into user value +(0,'张三',11111), +(0,'王五',11111), +(0,'李四',11111); + +alter table menu_user add constraint FK_menu_user foreign key (role_id) + references role (role_id) on delete restrict on update restrict; + +alter table menu_user add constraint FK_menu_user2 foreign key (menu_id) + references menu (menu_id) on delete restrict on update restrict; + +alter table role_user add constraint FK_role_user foreign key (role_id) + references role (role_id) on delete restrict on update restrict; + +alter table role_user add constraint FK_role_user2 foreign key (user_id) + references user (user_id) on delete restrict on update restrict; + +``` + diff --git "a/55 \346\235\250\346\227\255\344\270\234/20231016\347\264\242\345\274\225.md" "b/55 \346\235\250\346\227\255\344\270\234/20231016\347\264\242\345\274\225.md" new file mode 100644 index 0000000..973e611 --- /dev/null +++ "b/55 \346\235\250\346\227\255\344\270\234/20231016\347\264\242\345\274\225.md" @@ -0,0 +1,43 @@ +```MySQL +笔记 +索引的优点 + +提高数据检索的效率,降低数据库的IO成本 +通过索引列对数据进行排序,降低mysql对数据自动排序的成本,降低CPU的消耗 + +单列索引:一个索引建立在一个列上,一张表可以拥有多个单列索引 +普通索引:单纯地为了提高搜索效率 +唯一索引:unique,唯一索引只能够建立在数据不重复的列上 ,唯一约束 +主键索引:唯一性、非空,主键约束 +联合索引:可以同时为多个列创建一个索引 + +创建索引(普通索引) +1.直接在已有表中创建索引 +create index 索引名 on 表名(列名) -- 直接删除索引 drop index 索引名 on 表名; 这种不能用来创建主键索引 +2.修改表结构追加普通索引 +alter table 表名 add index 索引名(列名); -- 修改表结构删除索引 alter table 表名 drop index 索引名; +3.创建表的时候直接指定 +create table 表名( + aaa int primary key, + bbb varchar(20), + index 索引名 (列名) -- 以这种模式定义的索引,可以不指定索引名称。 + primary key(列名) +); + +查看表的索引 +show index from 表名; +删除索引 +drop index 索引名 on 表名; + +唯一索引 +create unique index 索引名 on 表名(列名); +在已存在的表上追加唯一索引 +alter table 表名 add unique 索引名 (列名) +删除主键 +alter table 表名 drop primary key; + +联合索引(执行最左原则) +create index 索引名 on 表名(列名1,列名2....) -- 普通的联合索引 +create unique index 索引名 on 表名(列名1,列名2....) -- 联合唯一索引 +``` + diff --git "a/55 \346\235\250\346\227\255\344\270\234/20231024\347\254\224\350\256\260\345\222\257.md" "b/55 \346\235\250\346\227\255\344\270\234/20231024\347\254\224\350\256\260\345\222\257.md" new file mode 100644 index 0000000..a559460 --- /dev/null +++ "b/55 \346\235\250\346\227\255\344\270\234/20231024\347\254\224\350\256\260\345\222\257.md" @@ -0,0 +1,11 @@ +```MySQL +笔记 +substring_index(str,'分界字符',n) -- 返回从字符串str截取到第n个分界符的字符串,当n大于1从左到右,小于1从右到左 +curdate() -- 返回当前日期 +curtime() -- 返回当前时间 +now() -- 返回当前时间日期 +year(date) -- 获取指定date的年份 +month(date) -- 获取指定date的月份 +day(date) -- 获取指定date的日期 +``` + -- Gitee