当前位置:网站首页>Hospital management system database, course design, SQLserver, pure code design
Hospital management system database, course design, SQLserver, pure code design
2022-07-31 10:18:00 【xiaoweiwei99】
首先创建数据库,并建立各个表之间的主外键约束等,并插入数据.
create database 医院信息管理系统
on(
name=医院信息管理系统,
filename='D:Database course design of hospital information management system of hospital information management system.mdf',
size=5,
filegrowth=1
)
log on
( name=医院信息管理系统_log,
filename='D:Database course design of hospital information management system of hospital information management system_log.ldf',
size=2,
maxsize=30,
filegrowth=10%
)
use 医院信息管理系统
go
create table 医生表
(医生编号 char(15) not null primary key,
姓名 char(10) not null unique,
性别 char(5) null,
年龄 int null,
职称 char(11) null,
科室号 char(20) null)
go
alter table 医生表
add constraint ys_zc default '医师' for 职称
go
alter table 医生表
add constraint fk_ks foreign key(科室号) references 科室表(科室号)
go
create table 科室表
(科室号 char(20) not null primary key,
科室名 char(10) not null ,
科室地址 char(20) null,
科室电话 char(10) null,
科室主任 char(10) null)
go
create table 病人表
(病历号 char(15) not null primary key,
姓名 char(10) not null,
性别 char(5) null,
年龄 int null,
病房号 char(15) null,
医生姓名 char(10) null,
血型 char(4) null,
确诊结果 char(10)null,
科室号 char(20) null)
go
alter table 病人表
add constraint fk_ksh foreign key(科室号) references 科室表(科室号)
go
create table 病房表
(病房号 char(15) not null primary key,
床位数 int null,
病房地址 char(20) null,
科室号 char(20) null)
go
alter table 病人表
add constraint fk_bfh foreign key(病房号) references 病房表(病房号)
go
alter table 病房表
add constraint fk_sk foreign key(科室号) references 科室表(科室号)
go
create table 护士表
(护士编号 char(15) not null primary key,
姓名 char(10) not null,
性别 char(5) null,
年龄 int null,
科室号 char(20) null)
go
alter table 护士表
add constraint fk_skh foreign key(科室号) references 科室表(科室号)
go
create table 分配表
( 病房号 char(15) not null,
护士编号 char(15) not null,
primary key (病房号,护士编号),
foreign key(病房号) references 病房表(病房号),
foreign key(护士编号) references 护士表(护士编号))
go
insert into 科室表(科室号,科室名,科室地址,科室电话,科室主任)
values('101','内科','A1101','10001','高飞'),
('102','外科','A1102','10002','李想'),
('103','儿科','A1103','10003','邓杨'),
('104','妇科','A1104','10004','刘宇'),
('105','神经科','A1105','10005','白皓'),
('201','脑外科','A1201','20001','宋思琪'),
('202','泌尿科','A1202','20002','孙怡'),
('203','骨科','A1203','20003','杨子龙'),
('204','内分泌科','A1204','20004','张子怡'),
('205','口腔科','A1205','20005','郭易曼'),
('301','眼科','A1301','30001','王陆明'),
('302','耳喉鼻科','A1302','30002','韩子琦'),
('303','皮肤科','A1303','30003','徐若鸿'),
('304','心脏外科','A1304','30004','李丽'),
('305','胸外科','A1305','30005','陈若玉')
go
insert into 医生表(医生编号,姓名,性别,年龄,职称,科室号)
values('101001','高飞','男','30','主任医师','101'),
('101002','杨蕾','女','24','住院医师','101'),
('101003','齐风','男','27','主治医师','101'),
('101004','李想','女','45','主任医师','102'),
('101005','朱珠','女','30','主治医师','102'),
('101006','陆风','男','35','主治医师','102'),
('101007','邓杨','男','30','主治医师','103'),
('101008','程悦','女','28','副主治医师','103'),
('101009','刘宇','女','40','副主任医师','104'),
('101010','刘子怡','女','34','主治医师','104'),
('101011','白皓','男','58','主任医师','105'),
('101012','苏楠','女','32','主治医师','105'),
('101013','宋思琪','女','50','主任医师','201'),
('101014','陆大明','男','24','住院医师','201'),
('101015','孙怡','女','33','主治医师','202'),
('101016','刘楠','男','33','主治医师','202'),
('101017','杨子龙','男','35','主治医师','203'),
('101018','焦丹','女','23','住院医师','203'),
('101019','张子怡','女','38','副主任医师','204'),
('101020','李娟','女','32','主治医师','204'),
('101021','郭易曼','女','35','主治医师','205'),
('101022','刘晓','男','22','住院医师','205'),
('101023','王陆明','男','36','主治医师','301'),
('101024','张珍','女','29','副主治医师','301'),
('101025','韩子琦','男','31','主治医师','302'),
('101026','乔芳','女','31','主治医师','302'),
('101027','徐若鸿','男','49','主任医师','303'),
('101028','陆磊','男','31','主治医师','303'),
('101029','李丽','女','51','主任医师','304'),
('101030','高涛','男','31','主治医师','304'),
('101031','陈若玉','女','39','副主任医师','305'),
('101032','刘思雨','女','30','主治医师','305')
go
insert into 病房表(病房号,床位数,病房地址,科室号)
values('001','4','B1001','101'),
('002','5','B1002','101'),
('003','1','B1003','102'),
('004','2','B1004','102'),
('005','0','B1005','103'),
('006','3','B1006','103'),
('007','2','B1007','104'),
('008','3','B1008','105'),
('009','1','B1009','105'),
('010','2','B1010','201'),
('011','1','B1011','201'),
('012','3','B1012','202'),
('013','2','B1013','203'),
('014','2','B1014','204'),
('015','1','B1015','204'),
('016','5','B1016','205'),
('017','2','B1017','301'),
('018','1','B1018','302'),
('019','3','B1019','303'),
('020','1','B1020','303'),
('021','2','B1021','304'),
('022','1','B1022','304'),
('023','3','B1023','305'),
('024','2','B1024','305')
go
select *
from 科室表
go
select *
from 医生表
go
select 医生表.姓名 , 科室名
from 医生表 join 科室表
on 医生表.科室号=科室表.科室号
go
use 医院信息管理系统
go
insert into 病人表(病历号,姓名,性别,年龄,病房号,医生姓名,血型,确诊结果,科室号)
values('21101','王胜安','男','31','001','齐风','A','肺炎','101'),
('21102','蔡壮保','男','54','002','高飞','B','慢性气管炎','101'),
('21103','易江伟','男','28','003','陆风','O','自发性气胸','102'),
('21104','张顺谷','男','32','004','朱珠','AB','胆道结石','102'),
('21105','李鑫灏','男','8','006','邓杨','A','细菌性痢疾','103'),
('21106','梁澄静','女','8','006','程悦','A','诺如腹泻','103'),
('21107','时党舒','女','26','007','刘宇','B','宫颈炎','104'),
('21108','何刚名','男','66','008','白皓','O','脑梗塞','105'),
('21109','严席华','男','58','008','苏楠','B','脑出血','105'),
('21110','刘鲜发','男','32','010','宋思琪','A','脑积水','201'),
('21111','何毅','男','35','010','陆大明','O','脑脓肿','201'),
('21112','唐宸禹','男','38','011','宋思琪','B','颅脑外伤','201'),
('21113','张顺联','男','50','012','刘楠','A','泌尿结石','202'),
('21114','汤青','女','29','012','孙怡','B','急性肾炎','202'),
('21115','柯纤栩','女','34','013','焦丹','AB','腰间盘突出','203'),
('21116','夏莱','女','30','014','张子怡','B','电解质紊乱','204'),
('21117','杜鹃','女','28','015','李娟','A','内分泌紊乱','204'),
('21118','张洪赫','男','25','016','郭易曼','B','慢性牙周炎','205'),
('21119','池慕颖','女','26','016','刘晓','AB','口腔白斑','205'),
('21120','齐芬霞','女','69','017','王陆明','O','白内障','301'),
('21121','卢全旭','男','66','017','张珍','A','青光眼','301'),
('21122','卓互知','男','45','018','韩子琦','AB','中耳炎','302'),
('21123','元感奇','男','16','019','徐若鸿','O','扁平疣','303'),
('21124','秦长乐','男','32','020','陆磊','B','皮肤癣','303'),
('21125','丘寸心','男','48','021','李丽','O','血胸','304'),
('21126','路从风','男','18','022','高涛','B','漏斗胸','304'),
('21127','王浩','男','29','023','陈若玉','A','胸部异物','305'),
('21128','潘奕','女','30','024','刘思雨','AB','胸腔积液','305')
go
insert into 护士表(护士编号,姓名,性别,年龄,科室号)
values('110101','夏一柳','女','25','101'),
('110102','席梦荣','女','28','101'),
('110103','李文倩','女','22','102'),
('110104','绕詹林','男','24','102'),
('110105','吴申萌','女','29','103'),
('110106','田甜','女','23','103'),
('110107','高悦然','女','25','104'),
('110108','刘子诺','女','21','104'),
('110109','张以诺','女','22','105'),
('110110','赵佳宇','女','22','105'),
('110111','张怡铭','女','35','201'),
('110112','蒋欣芹','女','26','201'),
('110113','马航钰','女','30','202'),
('110114','苏芷璇','女','25','202'),
('110115','王晓甜','女','24','203'),
('110116','陈子媛','女','26','203'),
('110117','董璇','女','21','204'),
('110118','孙玉','女','23','204'),
('110119','李婉婷','女','28','205'),
('110120','宋雨涵','女','31','205'),
('110121','邓梦琪','女','24','301'),
('110122','崔佳玉','女','26','301'),
('110123','郭星瞳','女','24','302'),
('110124','郭思羽','女','23','302'),
('110125','王雨橙','女','28','303'),
('110126','刘子琳','女','27','303'),
('110127','李雨霏','女','29','304'),
('110128','陆嘉晨','女','24','304'),
('110129','张馨予','女','23','305'),
('110130','刘欣悦','女','27','305')
go
insert into 分配表(病房号,护士编号)
values('001','110101'),
('002','110102'),
('003','110103'),
('004','110104'),
('005','110105'),
('006','110106'),
('007','110107'),
('007','110108'),
('008','110109'),
('009','110110'),
('010','110111'),
('011','110112'),
('012','110113'),
('012','110114'),
('013','110115'),
('013','110116'),
('014','110117'),
('015','110118'),
('016','110119'),
('016','110120'),
('017','110121'),
('017','110122'),
('018','110123'),
('018','110124'),
('019','110125'),
('020','110126'),
('021','110127'),
('022','110128'),
('023','110129'),
('024','110130')
go
此时数据库已经建立好了,下面进行数据库的基本操作.
use 医院信息管理系统
insert into 病人表(病历号,姓名,性别,年龄,病房号,医生姓名,血型,确诊结果)
values('21129','张淦','男','25','024','刘思雨','O','胸腔积液')
go
delete
from 病人表
where 病历号='21129'
go
update 护士表
set 年龄='26'
where 姓名='夏一柳'
go
select 病历号,病人表.姓名,病人表.性别,病人表.年龄,病房号,血型,医生姓名,职称,医生表.科室号
from 病人表 join 医生表
on 病人表.医生姓名=医生表.姓名
where 确诊结果='脑积水'
go
select 科室号,COUNT(护士编号) as '护士人数'
from 护士表
group by 科室号
go
select 科室号,COUNT(病房号) as '病房数'
from 病房表
group by 科室号
having(COUNT(病房号))>1
go
select AVG(年龄) as '全体医生平均年龄'
from 医生表
go
select 姓名,年龄
from 病人表
order by 年龄 desc
go
select 护士编号,姓名,YEAR(GETDATE())-年龄 as '出生日期'
from 护士表
go
select 护士表.护士编号,病房号,姓名
from 护士表 join 分配表
on 护士表.护士编号=分配表.护士编号
go
select 病历号,病人表.姓名,病人表.性别,血型,病房号,医生姓名,职称,医生表.科室号,科室表.科室名,科室表.科室地址
from 病人表 join 医生表
on 病人表.医生姓名=医生表.姓名
join 科室表
on 医生表.科室号=科室表.科室号
go
create view v_pyk
as
select 病历号,病人表.姓名,病人表.性别,血型,病房号,医生姓名,职称,医生表.科室号,科室表.科室名,科室表.科室地址
from 病人表 join 医生表
on 病人表.医生姓名=医生表.姓名
join 科室表
on 医生表.科室号=科室表.科室号
go
select *
from v_pyk
go
update v_pyk
set 病房号='021'
where 病历号='21126'
go
create proc pr_inf @pr varchar(20)
as
select 病人表.姓名,病人表.性别,血型,医生姓名,医生编号,确诊结果
from 病人表 join 医生表
on 病人表.医生姓名=医生表.姓名
where 病人表.姓名 like @pr
go
exec pr_inf '张%'
use 医院信息管理系统
go
alter proc hs_bf @hno char(6),@bno char(10) output ,@bed varchar(10) output
as
select @bno=分配表.病房号,@bed=床位数
from 分配表 join 病房表
on 病房表.病房号=分配表.病房号
where 护士编号 [email protected]
set @bed=convert(varchar,@bed)
go
declare @bno1 char(10),@bed1 varchar(10)
exec hs_bf '110101',@bno1 output ,@bed1 output
print '病房号'[email protected]
print '床位数'[email protected]
go
use 医院信息管理系统
go
alter trigger tri_br
on 病人表
after delete,update
as
declare @sno char(10) ,@cno char (10)
select @sno =病历号 from deleted
select @cno=病房号 from deleted
delete from 病人表 where 病历号[email protected]
update 病房表
set 床位数=床位数+1
where @cno = 病房表.病房号
go
delete from 病人表 where 病历号='21102'
go
下面是各个表的实体图
下面是数据流图
下面是医院管理E-R图
下面是医院功能结构图
1.设计任务
1.1Summary of system development background
随着计算机技术的飞速发展,The popularity of computer application in hospital management,Using computer to realize the hospital management is imperative.For large and medium-sized hospital,Using the computer support hospital efficiency to complete the work of hospital management daily routine,Is to adapt to the modern hospital management system requirements、To promote hospital management to scientific、Standardization of the necessary conditions for.
At present the popular market information management system a lot.但就是,For hospital management system of medium-sized hospital,Don't need a large database system.Only need a convenient operation,功能实用,To meet the demand of the center of the data management and system.Our goal is to develop a functional、操作方便,Simple hospital management system.To enter the hospital basic information,On the operation to complete, such as add、修改、删除、The query according to various conditions、New user Settings and password modification, etc,Basically meet the need of personnel daily business.Research and development team to complete the this topic,包括分析、设计、编码、测试、Document writing, etc.
1.2The purpose of system development and meaning
随着现代化社会的发展,为了抓住机遇,在竞争中占得先机,As an indispensable important link in management of enterprise—Online management of information、计算机化也就迫在眉捷了.Development of online information management system with macro sense,It is with the informationization times、现代化潮流,提高效益,Promote the management of the national economy structure optimization;也有微观上的意义,It is can improve the management modernization program,加强管理的信息化手段,提高工作效率,增加单位效益.
With the rapid development of computer and communication technology makes the human society has gradually entered the infmoratization era.Information and materials、As a kind of social basic energy production,In the human social production activities play an important role in.当前,Hospital is facing increasing competition in the market、要想在竞争中取胜,Also must use the advanced management methods and means.A well planned、Advanced design of computer information management network system is a necessary means for competition victory.By implementing advanced computer network management,For the leadership of the management and decision making in a timely manner to provide reliable digital basis,Make the management more reasonable、更先进;减少人力、物力资源的浪费,降低成本;提高工作效率,提高管理效率;提高经济效益,So as to improve the overall competitiveness of the hospital.Based on the personnel management of hospital information network management system for the center,To meet the needs of the hospital rapid development for a long time,More important is to make the treatment of patients in the hospital to get more satisfied.
2 需求分析
2.1信息要求
图2-1Functional module chart of the hospital information system
This course design simulation of the general hospital information management,Convenient for hospital information query.After a full investigation,Determine the system response to the patient basic information、科室基本信息、医生基本信息、Ward basic information、The nurse basic information、The nurse on management of the distribution of,This system is mainly for:
- Can the patient basic comprehensive management information、科室基本信息、医生基本信息、Ward basic information、Basic information, and the nurse nurse allocation information.
- This system can facilitate maintenance all kinds of information.
- This system can conveniently query the basic information of the various information table.
- Convenient to implement multiple information table join queries、嵌套查询.
- This system can realize useful information query statistics.
- This system can realize the output of the useful information.
2.2数据流图
图2-2Hospital information management data flow diagrams
2.3数据字典
数据字典是指对数据的数据项、数据结构、数据流、数据存储、处理逻辑、An external entity, such as five parts are defined and described,其目的是对数据流程图中的各个元素做出详细的说明.This experiment is mainly to analyze data dictionary items of data.如表2所示:
表2数据项
序号
数据项
数据类型
长度
备注
1
医生编号
CHAR
6
The doctor's job number
2
姓名
VARCHAR
20
The doctor's name
3
性别
CHAR
2
医生的性别
4
年龄
INT
The doctor's age
5
职称
VARCHAR
20
The doctor's title
6
科室号
CHAR
3
The doctor's department number
7
病历号
CHAR
5
The patient's medical record number
8
姓名
VARCHAR
20
病人的姓名
9
性别
CHAR
2
The patient's gender
10
年龄
INT
病人的年龄
11
病房号
CHAR
3
The patient's room number
13
血型
VARCHAR
2
The patient's blood type
14
科室号
CHAR
3
The patient's subordinate departments
15
确诊结果
VARCHAR
20
The patient's diagnosis report
16
科室号
CHAR
3
Department number
17
科室名
VARCHAR
20
The name of the department
18
科室地址
VARCHAR
20
The address of the department
19
科室电话
VARCHAR
10
Department of the phone
20
科室主任
VARCHAR
20
The director of the department
21
病房号
CHAR
3
The serial number of ward
22
床位数
INT
Ward beds
23
科室号
CHAR
3
Ward's department
24
病房地址
VARCHAR
20
Ward's address
25
护士编号
CHAR
6
The serial number of the nurse
26
姓名
VARCHAR
20
The nurse's name
27
性别
CHAR
2
The sex of the nurse
28
年龄
INT
The nurse's age
29
科室号
CHAR
3
The nurse's department
3概念结构设计
3.1Hospital information system entity attributes
Hospital doctors entity attributes,Mainly includes the doctor the doctor number,姓名,性别,年龄,科室号,职称.如图3-1The doctor entity attributes as shown in figure:
图3-1医生实体属性图
Hospital department entity attributes,Mainly includes the department department number,科室名,科室地址,科室电话,科室主任;如图3-2Department entity attributes as shown in figure:
图3-3Ward entity attributes figure
Hospital nurse entity attributes,Mainly includes the nurse number,姓名,性别,年龄,科室号.如图3-4The nurse entity attributes as shown in figure:
Hospital patients entity attributes figure,Mainly include the case number,姓名,性别,年龄,确诊结果,医生姓名,病房号,血型,科室号.如图3-5The patient entity attributes as shown in figure:
3.2总E-R图
Hospital information management alwaysE-R图,如图3-6总E-R图所示:
4 逻辑结构设计
4.1关系模式:
医生(医生编号、姓名、性别、年龄、职称、Subordinate departments number)
病人(病历号、姓名、性别、年龄、病房号、医生姓名、血型、Subordinate departments number、诊断)
科室(科室号、科室名、科室地址、科室电话、科室主任)
病房(病房号、床位号、Subordinate departments number、病房地址)
护士(护士编号、姓名、性别、年龄、Their room number)
5 物理结构设计
5**.1Data relationship model of optimization:******
对于1对NRelationship of registered,Can add department number attribute pattern in patients.
对于1对NRelations belong to,Can join in the doctor pattern department number attribute.
对于1对NRelationship with,Can join in the ward model department number attribute.
This optimized relational schema:
病人(病历号、姓名、性别、年龄、病房号、医生姓名、血型、确诊结果、科室号)
医生(医生编号、姓名、性别、年龄、职称、科室号)
病房(病房号、床位号、病房地址、科室号)
对于N对M的关系模式,Can generate a new model:
分配(病房号、护士编号)
For the optimized relational schema:
医生(医生编号、姓名、性别、年龄、职称、科室号)
病人(病历号、姓名、性别、年龄、病房号、医生姓名、血型、确诊结果、科室号)
科室(科室号、科室名、科室地址、科室电话、科室主任)
病房(病房号、床位号、病房地址、科室号)
护士(护士编号、姓名、性别、年龄、科室号)
分配(病房号、护士编号)
分析,Relational schema of each relationship can be divided into atomic values,Is the first model,And because every non-primary attribute is not depends on the models of candidate key,Therefore the model sets the third paradigm.
Through optimized relational schema doctor table:
表4.1The doctor basic information table
列名
数据类型
字段大小
是否为空
备注
医生编号
CHAR
6
NOT
主键
姓名
VARCHAR
20
NOT
性别
CHAR
2
NOT
年龄
INT
NOT
职称
VARCHAR
20
YES
科室号
CHAR
3
YES
外键
By optimizing the relation mode after it is concluded that the patient table:
表4.2病人基本信息表
列名
数据类型
字段大小
是否为空
备注
病历号
CHAR
5
NOT
主键
姓名
VARCHAR
20
NOT
性别
CHAR
2
NOT
年龄
INT
NOT
病房号
CHAR
3
YES
医生姓名
VARCHAR
20
YES
血型
CHAR
2
YES
确诊结果
VARCHAR
20
YES
科室号
CHAR
3
YES
外键
Through optimized relational schema section office table:
表4.3Department of basic information table
列名
数据类型
字段大小
是否为空
备注
科室号
CHAR
3
NOT
主键
科室名
VARCHAR
20
NOT
科室地址
VARCHAR
20
YES
科室电话
VARCHAR
10
YES
科室主任
VARCHAR
20
YES
Through optimized relational schema ward table:
表4.4Ward basic information table
列名
数据类型
字段大小
是否为空
备注
病房号
CHAR
3
NOT
主键
床位数
INT
YES
病房地址
VARCHAR
20
YES
科室号
CHAR
3
YES
外键
By optimizing the relation mode after it is concluded that the nurse watch:
表4.5The nurse basic information table
列名
数据类型
字段大小
是否为空
备注
护士编号
CHAR
6
NOT
主键
姓名
VARCHAR
20
NOT
性别
CHAR
2
NOT
年龄
INT
NOT
科室号
CHAR
3
YES
外键
Through optimized relational schema distribution list:
表4.6The nurse distribution list
列名
数据类型
字段大小
是否为空
备注
病房号
CHAR
3
NOT
主键、外键
护士编号
CHAR
6
NOT
主键、外键
5.2The content of the design
Because the user finally through a particularDBMS使用数据库,So the data of physical structure design must be combined with the specificDBMS进行,Mainly includes the select the database storage structure and access method two aspects.
5.2.1确定存储结构
Database physical structure design and specific hardware environment、DBMSAnd implementation environment is closely related to the,Database configuration is to determine the important content of physical structure,Including database space distribution、日志文件大小、Data dictionary space and related parameters Settings, and so on.
5.2.2Select access method
Database access method of index、Clustering methods.
1.索引的选择
In general has the properties of the column index of the following:
Frequent query attribute column.
Often appear in the link attribute column in the operation.
WHERE、ORDER、GROUP BYDIn the sentence properties such as column.
Should not be indexed column:
Don't appear or rarely attribute column in the query conditions.
Attribute values rarely column.
Often need to update the column.
Often need to update or contain fewer data table properties on record.
2.The choice of clustering
Clustering is to improve the system performance of another technology,The cluster is divided into the following3种情况:
分段.按属性分组,The files in the vertical direction decomposition.
分区.The file level decomposition,According to the record access frequency to group.
聚簇.Removed from the relationship of different certain attributes physically stored together,To change the query efficiency.
5.3评价物理结构
Physical structure to meet the needs of design,Have a great efficiency in terms of time and space,Can enter the database implementation stage,The physical structure of the database design needs to be after repeated testing、不断优化.
6 数据库实施
After complete analysis and structure optimization,Start the database implementation stage,This chapter mainly database creation,The data table of、删、改、查,View is created and stored procedure created as content.
6.1数据库的创建
createdatabase医院信息管理系统
on(
name=医院信息管理系统,
filename=‘D:Database course design of hospital information management system of hospital information management system.mdf’,
size=5,
filegrowth=1
)
logon
(name=医院信息管理系统_log,
filename=‘D:Database course design of hospital information management system of hospital information management system_log.ldf’,
size=2,
maxsize=30,
filegrowth=10%
)
6.2表的创建
6.2.1Create table department
use医院信息管理系统
createtable科室表
(科室号char(3)notnullprimarykey,
科室名varchar(20)notnull,
科室地址varchar(20)null,
科室电话varchar(10)null,
科室主任varchar(10)null)
go
6.2.2The doctor table create
createtable医生表
(医生编号char(6)notnullprimarykey,
姓名varchar(20)notnullunique,
性别char(2)notnull,
年龄intnotnull,
职称varchar(20)null,
科室号char(3)null)
go
altertable医生表
addconstraintys_zcdefault’医师’for职称
go
altertable医生表
addconstraintfk_ksforeignkey(科室号)references科室表(科室号)
go
6.2.3The patient table create
createtable病人表
(病历号char(5)notnullprimarykey,
姓名varchar(20)notnull,
性别char(2)notnull,
年龄intnotnull,
病房号char(3)null,
医生姓名varchar(20)null,
血型char(2)null,
确诊结果varchar(20)null,
科室号char(3)null)
go
altertable病人表
addconstraintfk_kshforeignkey(科室号)references科室表(科室号)
go
altertable病人表
addconstraintfk_bfhforeignkey(病房号)references病房表(病房号)
go
6.2.4Create ward table
createtable病房表
(病房号char(3)notnullprimarykey,
床位数intnull,
病房地址varchar(20)null,
科室号char(3)null)
go
altertable病房表
addconstraintfk_skforeignkey(科室号)references科室表(科室号)
go
6.2.5The nurse table create
createtable护士表
(护士编号char(6)notnullprimarykey,
姓名varchar(20)notnull,
性别char(2) notnull,
年龄intnotnull,
科室号char(3)null)
go
altertable护士表
addconstraintfk_skhforeignkey(科室号)references科室表(科室号)
go
6.2.6Create distribution list
createtable分配表
(病房号char(3)notnull,
护士编号char(6)notnull,
primarykey (病房号,护士编号),
foreignkey(病房号)references病房表(病房号),
foreignkey(护士编号)references护士表(护士编号))
go
6.3表的数据插入
6.3.1Department table insert data
insertinto科室表(科室号,科室名,科室地址,科室电话,科室主任)
values(‘101’,‘内科’,‘A1101’,‘A1-10001’,‘高飞’),
(‘102’,‘外科’,‘A1102’,‘A1-10002’,‘李想’),
(‘103’,‘儿科’,‘A1103’,‘A1-10003’,‘邓杨’),
(‘104’,‘妇科’,‘A1104’,‘A1-10004’,‘刘宇’),
(‘105’,‘神经科’,‘A1105’,‘A1-10005’,‘白皓’),
(‘201’,‘脑外科’,‘A1201’,‘A1-20001’,‘宋思琪’),
(‘202’,‘泌尿科’,‘A1202’,‘A1-20002’,‘孙怡’),
(‘203’,‘骨科’,‘A1203’,‘A1-20003’,‘杨子龙’),
(‘204’,‘内分泌科’,‘A1204’,‘A1-20004’,‘张子怡’),
(‘205’,‘口腔科’,‘A1205’,‘A1-20005’,‘郭易曼’),
(‘301’,‘眼科’,‘A1301’,‘A1-30001’,‘王陆明’),
(‘302’,‘耳喉鼻科’,‘A1302’,‘A1-30002’,‘韩子琦’),
(‘303’,‘皮肤科’,‘A1303’,‘A1-30003’,‘徐若鸿’),
(‘304’,‘心脏外科’,‘A1304’,‘A1-30004’,‘李丽’),
(‘305’,‘胸外科’,‘A1305’,‘A1-30005’,‘陈若玉’)
Go
6.3.2The doctor table insert data
insertinto医生表(医生编号,姓名,性别,年龄,职称,科室号)
values(‘101001’,‘高飞’,‘男’,30,‘主任医师’,‘101’),
(‘101002’,‘杨蕾’,‘女’,24,‘住院医师’,‘101’),
(‘101003’,‘齐风’,‘男’,27,‘主治医师’,‘101’),
(‘101004’,‘李想’,‘女’,45,‘主任医师’,‘102’),
(‘101005’,‘朱珠’,‘女’,30,‘主治医师’,‘102’),
(‘101006’,‘陆风’,‘男’,35,‘主治医师’,‘102’),
(‘101007’,‘邓杨’,‘男’,30,‘主治医师’,‘103’),
(‘101008’,‘程悦’,‘女’,28,‘副主治医师’,‘103’),
(‘101009’,‘刘宇’,‘女’,40,‘副主任医师’,‘104’),
(‘101010’,‘刘子怡’,‘女’,34,‘主治医师’,‘104’),
(‘101011’,‘白皓’,‘男’,58,‘主任医师’,‘105’),
(‘101012’,‘苏楠’,‘女’,32,‘主治医师’,‘105’),
(‘101013’,‘宋思琪’,‘女’,50,‘主任医师’,‘201’),
(‘101014’,‘陆大明’,‘男’,24,‘住院医师’,‘201’),
(‘101015’,‘孙怡’,‘女’,33,‘主治医师’,‘202’),
(‘101016’,‘刘楠’,‘男’,33,‘主治医师’,‘202’),
(‘101017’,‘杨子龙’,‘男’,35,‘主治医师’,‘203’),
(‘101018’,‘焦丹’,‘女’,23,‘住院医师’,‘203’),
(‘101019’,‘张子怡’,‘女’,38,‘副主任医师’,‘204’),
(‘101020’,‘李娟’,‘女’,32,‘主治医师’,‘204’),
(‘101021’,‘郭易曼’,‘女’,35,‘主治医师’,‘205’),
(‘101022’,‘刘晓’,‘男’,22,‘住院医师’,‘205’),
(‘101023’,‘王陆明’,‘男’,36,‘主治医师’,‘301’),
(‘101024’,‘张珍’,‘女’,29,‘副主治医师’,‘301’),
(‘101025’,‘韩子琦’,‘男’,31,‘主治医师’,‘302’),
(‘101026’,‘乔芳’,‘女’,31,‘主治医师’,‘302’),
(‘101027’,‘徐若鸿’,‘男’,49,‘主任医师’,‘303’),
(‘101028’,‘陆磊’,‘男’,31,‘主治医师’,‘303’),
(‘101029’,‘李丽’,‘女’,51,‘主任医师’,‘304’),
(‘101030’,‘高涛’,‘男’,31,‘主治医师’,‘304’),
(‘101031’,‘陈若玉’,‘女’,39,‘副主任医师’,‘305’),
(‘101032’,‘刘思雨’,‘女’,30,‘主治医师’,‘305’)
Go
6.3.3Ward table insert data
insertinto病房表(病房号,床位数,病房地址,科室号)
values(‘001’,4,‘B1001’,‘101’),
(‘002’,5,‘B1002’,‘101’),
(‘003’,1,‘B1003’,‘102’),
(‘004’,2,‘B1004’,‘102’),
(‘005’,0,‘B1005’,‘103’),
(‘006’,3,‘B1006’,‘103’),
(‘007’,2,‘B1007’,‘104’),
(‘008’,3,‘B1008’,‘105’),
(‘009’,1,‘B1009’,‘105’),
(‘010’,2,‘B1010’,‘201’),
(‘011’,1,‘B1011’,‘201’),
(‘012’,3,‘B1012’,‘202’),
(‘013’,2,‘B1013’,‘203’),
(‘014’,2,‘B1014’,‘204’),
(‘015’,1,‘B1015’,‘204’),
(‘016’,5,‘B1016’,‘205’),
(‘017’,2,‘B1017’,‘301’),
(‘018’,1,‘B1018’,‘302’),
(‘019’,3,‘B1019’,‘303’),
(‘020’,1,‘B1020’,‘303’),
(‘021’,2,‘B1021’,‘304’),
(‘022’,1,‘B1022’,‘304’),
(‘023’,3,‘B1023’,‘305’),
(‘024’,2,‘B1024’,‘305’)
go
6.3.4The patient table insert data
insertinto病人表(病历号,姓名,性别,年龄,病房号,医生姓名,血型,确诊结果,科室号)
values(‘21101’,‘王胜安’,‘男’,31,‘001’,‘齐风’,‘A’,‘肺炎’,‘101’),
(‘21102’,‘蔡壮保’,‘男’,54,‘002’,‘高飞’,‘B’,‘慢性气管炎’,‘101’),
(‘21103’,‘易江伟’,‘男’,28,‘003’,‘陆风’,‘O’,‘自发性气胸’,‘102’),
(‘21104’,‘张顺谷’,‘男’,32,‘004’,‘朱珠’,‘AB’,‘胆道结石’,‘102’),
(‘21105’,‘李鑫灏’,‘男’,8,‘006’,‘邓杨’,‘A’,‘细菌性痢疾’,‘103’),
(‘21106’,‘梁澄静’,‘女’,8,‘006’,‘程悦’,‘A’,‘诺如腹泻’,‘103’),
(‘21107’,‘时党舒’,‘女’,26,‘007’,‘刘宇’,‘B’,‘宫颈炎’,‘104’),
(‘21108’,‘何刚名’,‘男’,66,‘008’,‘白皓’,‘O’,‘脑梗塞’,‘105’),
(‘21109’,‘严席华’,‘男’,58,‘008’,‘苏楠’,‘B’,‘脑出血’,‘105’),
(‘21110’,‘刘鲜发’,‘男’,32,‘010’,‘宋思琪’,‘A’,‘脑积水’,‘201’),
(‘21111’,‘何毅’,‘男’,35,‘010’,‘陆大明’,‘O’,‘脑脓肿’,‘201’),
(‘21112’,‘唐宸禹’,‘男’,38,‘011’,‘宋思琪’,‘B’,‘颅脑外伤’,‘201’),
(‘21113’,‘张顺联’,‘男’,50,‘012’,‘刘楠’,‘A’,‘泌尿结石’,‘202’),
(‘21114’,‘汤青’,‘女’,29,‘012’,‘孙怡’,‘B’,‘急性肾炎’,‘202’),
(‘21115’,‘柯纤栩’,‘女’,34,‘013’,‘焦丹’,‘AB’,‘腰间盘突出’,‘203’),
(‘21116’,‘夏莱’,‘女’,30,‘014’,‘张子怡’,‘B’,‘电解质紊乱’,‘204’),
(‘21117’,‘杜鹃’,‘女’,28,‘015’,‘李娟’,‘A’,‘内分泌紊乱’,‘204’),
(‘21118’,‘张洪赫’,‘男’,25,‘016’,‘郭易曼’,‘B’,‘慢性牙周炎’,‘205’),
(‘21119’,‘池慕颖’,‘女’,26,‘016’,‘刘晓’,‘AB’,‘口腔白斑’,‘205’),
(‘21120’,‘齐芬霞’,‘女’,69,‘017’,‘王陆明’,‘O’,‘白内障’,‘301’),
(‘21121’,‘卢全旭’,‘男’,66,‘017’,‘张珍’,‘A’,‘青光眼’,‘301’),
(‘21122’,‘卓互知’,‘男’,45,‘018’,‘韩子琦’,‘AB’,‘中耳炎’,‘302’),
(‘21123’,‘元感奇’,‘男’,16,‘019’,‘徐若鸿’,‘O’,‘扁平疣’,‘303’),
(‘21124’,‘秦长乐’,‘男’,32,‘020’,‘陆磊’,‘B’,‘皮肤癣’,‘303’),
(‘21125’,‘丘寸心’,‘男’,48,‘021’,‘李丽’,‘O’,‘血胸’,‘304’),
(‘21126’,‘路从风’,‘男’,18,‘022’,‘高涛’,‘B’,‘漏斗胸’,‘304’),
(‘21127’,‘王浩’,‘男’,29,‘023’,‘陈若玉’,‘A’,‘胸部异物’,‘305’),
(‘21128’,‘潘奕’,‘女’,30,‘024’,‘刘思雨’,‘AB’,‘胸腔积液’,‘305’)
Go
6.3.5The nurse table insert data
insertinto护士表(护士编号,姓名,性别,年龄,科室号)
values(‘110101’,‘夏一柳’,‘女’,25,‘101’),
(‘110102’,‘席梦荣’,‘女’,28,‘101’),
(‘110103’,‘李文倩’,‘女’,22,‘102’),
(‘110104’,‘绕詹林’,‘男’,24,‘102’),
(‘110105’,‘吴申萌’,‘女’,29,‘103’),
(‘110106’,‘田甜’,‘女’,23,‘103’),
(‘110107’,‘高悦然’,‘女’,25,‘104’),
(‘110108’,‘刘子诺’,‘女’,21,‘104’),
(‘110109’,‘张以诺’,‘女’,22,‘105’),
(‘110110’,‘赵佳宇’,‘女’,22,‘105’),
(‘110111’,‘张怡铭’,‘女’,35,‘201’),
(‘110112’,‘蒋欣芹’,‘女’,26,‘201’),
(‘110113’,‘马航钰’,‘女’,30,‘202’),
(‘110114’,‘苏芷璇’,‘女’,25,‘202’),
(‘110115’,‘王晓甜’,‘女’,24,‘203’),
(‘110116’,‘陈子媛’,‘女’,26,‘203’),
(‘110117’,‘董璇’,‘女’,21,‘204’),
(‘110118’,‘孙玉’,‘女’,23,‘204’),
(‘110119’,‘李婉婷’,‘女’,28,‘205’),
(‘110120’,‘宋雨涵’,‘女’,31,‘205’),
(‘110121’,‘邓梦琪’,‘女’,24,‘301’),
(‘110122’,‘崔佳玉’,‘女’,26,‘301’),
(‘110123’,‘郭星瞳’,‘女’,24,‘302’),
(‘110124’,‘郭思羽’,‘女’,23,‘302’),
(‘110125’,‘王雨橙’,‘女’,28,‘303’),
(‘110126’,‘刘子琳’,‘女’,27,‘303’),
(‘110127’,‘李雨霏’,‘女’,29,‘304’),
(‘110128’,‘陆嘉晨’,‘女’,24,‘304’),
(‘110129’,‘张馨予’,‘女’,23,‘305’),
(‘110130’,‘刘欣悦’,‘女’,27,‘305’)
Go
6.3.6Distribution table insert data
insertinto分配表(病房号,护士编号)
values(‘001’,‘110101’),
(‘002’,‘110102’),
(‘003’,‘110103’),
(‘004’,‘110104’),
(‘005’,‘110105’),
(‘006’,‘110106’),
(‘007’,‘110107’),
(‘007’,‘110108’),
(‘008’,‘110109’),
(‘009’,‘110110’),
(‘010’,‘110111’),
(‘011’,‘110112’),
(‘012’,‘110113’),
(‘012’,‘110114’),
(‘013’,‘110115’),
(‘013’,‘110116’),
(‘014’,‘110117’),
(‘015’,‘110118’),
(‘016’,‘110119’),
(‘016’,‘110120’),
(‘017’,‘110121’),
(‘017’,‘110122’),
(‘018’,‘110123’),
(‘018’,‘110124’),
(‘019’,‘110125’),
(‘020’,‘110126’),
(‘021’,‘110127’),
(‘022’,‘110128’),
(‘023’,‘110129’),
(‘024’,‘110130’)
Go
7 数据库操作
7.1数据表查询
7.1.1Department table data query
go
select*
from科室表
go
7.1.2The doctor table data query
go
select*
from医生表
go
7.1.3The doctor form department table join queries
select医生表.姓名,科室名
from医生表join科室表
on医生表.科室号=科室表.科室号
go
7.1.4In the patient table insert a message
(’21129’,’张淦’,’男’,’25’,’024’,’刘思雨’,’O’,’胸腔积液’).
use医院信息管理系统
insertinto病人表(病历号,姓名,性别,年龄,病房号,医生姓名,血型,确诊结果)
values(‘21129’,‘张淦’,‘男’,‘25’,‘024’,‘刘思雨’,‘O’,‘胸腔积液’)
go
7.1.5Remove the patient finally a record in the table
(’21129’,’张淦’,’男’,’25’,’024’,’刘思雨’,’O’,’胸腔积液’).
go
delete
from病人表
where病历号=‘21129’
go
7.1.6Amend the nurse Xia Yiliu age in the table to26.
update护士表
set年龄=‘26’
where姓名=‘夏一柳’
go
7.1.7Query with hydrocephalus patients
His case number,姓名,性别,年龄,病房号,Blood type and corresponds to the doctor's name,职称,Subordinate departments number.
select病历号,病人表.姓名,病人表.性别,病人表.年龄,病房号,血型,医生姓名,职称,医生表.科室号
from病人表join医生表
on病人表.医生姓名=医生表.姓名
where确诊结果=‘脑积水’
go
7.1.8Query each department have many nurses.
select科室号,COUNT(护士编号)as’护士人数’
from护士表
groupby科室号
7.1.9Query with more than one ward department.
select科室号,COUNT(病房号)as’病房数’
from病房表
groupby科室号
having(COUNT(病房号))>1
go
7.1.10The average age of the query all the doctor.
selectAVG(年龄)as’全体医生平均年龄’
from医生表
go
7.1.11Query the patient's age,并按降序排列.
select姓名,年龄
from病人表
orderby年龄desc
go
7.1.12Query the nurse's birth.
select护士编号,姓名,YEAR(GETDATE())-年龄as’出生日期’
from护士表
go
7.1.13Query each nurse is responsible for the room number.
select护士表.护士编号,病房号,姓名
from护士表join分配表
on护士表.护士编号=分配表.护士编号
go
7.1.14Query the patient of the case number
他的姓名,性别,血型,病房号,医生姓名,职称,Subordinate departments number,科室名,科室地址.
select病历号,病人表.姓名,病人表.性别,血型,病房号,医生姓名,职称,医生表.科室号,科室表.科室名,科室表.科室地址
from病人表join医生表
on病人表.医生姓名=医生表.姓名
join科室表
on医生表.科室号=科室表.科室号
go
7.1.15创建一个视图v_pyk
Query the patient of the case number,姓名,性别,血型,病房号,医生姓名,职称,Subordinate departments number,科室名,科室地址.
createviewv_pyk
as
select病历号,病人表.姓名,病人表.性别,血型,病房号,医生姓名,职称,医生表.科室号,科室表.科室名,科室表.科室地址
from病人表join医生表
on病人表.医生姓名=医生表.姓名
join科室表
on医生表.科室号=科室表.科室号
go
select*
fromv_pyk
go
7.1.16将视图v_pykIn the data changes
The case number for21126The patient's room number instead021
updatev_pyk
set病房号=‘021’
where病历号=‘21126’
go
7.1.17创建一个存储过程pr_inf
Output the specified the patient's name,性别,血型,主治医生,医生编号,确诊结果.
as
select病人表.姓名,病人表.性别,血型,医生姓名,医生编号,确诊结果
from病人表join医生表
on病人表.医生姓名=医生表.姓名
where病人表.姓名[email protected]
go
execpr_inf’张%’
7.1.18创建一个存储过程hs_bf
Enter a nurse number,The output of the nurse of the ward and surplus of beds.
[email protected](6),@bnochar(10)output,@bedvarchar(10)output
as
[email protected]=分配表.病房号,@bed=床位数
from分配表join病房表
on病房表.病房号=分配表.病房号
where护士编号[email protected]
[email protected]=convert(varchar,@bed)
go
[email protected](10),@bed1varchar(10)
exechs_bf’110101’,@bno1output,@bed1output
print’病房号’[email protected]
print’床位数’[email protected]
go
7.1.19创建一个触发器
When delete a record of the patient table,Ward of the table data to achieve timely update.
createtriggertri_br
on病人表
insteadofdelete,update
as
[email protected](10),@cnochar (10)
[email protected]=病历号fromdeleted
[email protected]=病房号fromdeleted
deletefrom病人表where病历号[email protected]
update病房表
set床位数=床位数+1
[email protected]=病房表.病房号
go
deletefrom病人表where病历号=‘21102’
go
先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在.深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小.自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前.因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担.添加下方名片,即可获取全套学习资料哦
边栏推荐
猜你喜欢
随机推荐
(C language) program environment and preprocessing
WEB核心【记录网站登录人数,记录用户名案例】Cookie技术实现
解决rpc error: code = Unimplemented desc = method CheckLicense not implemented
Source code analysis of GZIPInputStream class
NowCoderTOP23-27 Binary tree traversal - continuous update ing
Principle of Redis Sentinel
细讲DDD领域驱动设计
Meikle Studio--Hongmeng 14-day development training notes (8)
ASP.NET 身份认证框架 Identity(一)
NowCoderTOP17-22 Binary search/sort - continuous update ing
【LeetCode】36.有效的数独
What does "chmod 777-R filename" mean?
SQLSERVER merges subquery data into one field
sql力扣刷题八
【LeetCode】242. 有效的字母异位词
loadrunner-controller-目标场景Schedule配置
Dart Log tool class
如何判断自己是否适合IT行业?方法很简单
Redis集群-哨兵模式原理(Sentinel)
loadrunner-Controller负载测试-各模块功能记录01测试场景设计