【正文】
values (39。12202139。,39。2021041139。,39。1039。,39。000000639。) insert into charge values (39。12202139。,39。2021060839。,39。9039。,39。000000739。) insert into charge values (39。12202139。,39。2021070939。,39。30039。,39。000000839。) insert into charge values (39。12202139。,39。2021092239。,39。2539。,39。000000939。) insert into charge values (39。12202139。,39。2021092339。,39。1639。,39。000001039。) insert into charge values (39。12202139。,39。2021092439。,39。539。,39。000001139。) insert into charge values (39。12202139。,39。2021092539。,39。2039。,39。000001239。) insert into charge values (39。12202139。,39。2021092539。,39。2539。,39。000001339。) insert into charge values (39。12202139。,39。2021092439。,39。3439。,39。000001439。) insert into charge values (39。12202139。,39。2021092739。,39。18039。,39。000001539。) insert into charge values (39。12202139。,39。2021100139。,39。1639。,39。000001639。) insert into charge values (39。12201739。,39。2021100739。,39。10039。,39。000001739。) insert into charge values (39。12201839。,39。2021111139。,39。239。,39。000001839。) insert into charge values (39。12201939。,39。2021111539。,39。839。,39。000001939。) 37 insert into charge values (39。12202039。,39。2021112339。,39。2539。,39。000002039。) go select * from charge。 ( 7)向醫(yī)生診斷結(jié)果( dc)表中插入數(shù)據(jù) USE hospital GO insert into dc values (39。001139。,39。張力 39。,39。心臟病 39。) insert into dc values (39。001239。,39。彭國(guó)華 39。,39。皮膚病 39。) insert into dc values (39。000839。,39。趙麗宏 39。,39。眼病 39。) insert into dc values (39。000639。,39。張萍 39。,39。神經(jīng)衰弱 39。) insert into dc values 38 (39。000639。,39。王蘭 39。,39。尿道炎 39。) ....... ....... ....... insert into dc values (39。000639。,39。黃浩 39。,39。感冒 39。) insert into dc values (39。000439。,39。蔡閨 39。,39。肩周炎 39。) insert into dc values (39。000339。,39。顧天 39。,39。發(fā)燒 39。) insert into dc values (39。000139。,39。林嘉 39。,39。上火 39。) go select * from dc。 (8)向科室( office)表中插入數(shù)據(jù) 39 USE hospital GO insert into office values (39。10139。,39。內(nèi)科 39。,39。0278611121239。) insert into office values (39。10239。,39。外科 39。,39。0278611122339。) insert into office values (39。10439。,39。兒科 39。,39。0278611233439。) insert into office values (39。10739。,39。骨科 39。,39。0278611343439。) insert into office values (39。20939。,39。精神科 39。,39。0278611454539。) insert into office values (39。10539。,39。兒科 39。,39。1898611345639。) insert into office values (39。21039。,39。神精科 39。,39。0278611456739。) insert into office values (39。31039。,39。腦科 39。,39。0278611458939。) insert into office values (39。40739。,39。皮膚科 39。,39。0278611562139。) ....... ....... ....... insert into office values (39。20839。,39。神經(jīng)科 39。,39。0278611347839。) insert into office values (39。10639。,39。兒科 39。,39。0278611314539。) insert into office values (39。10839。,39。骨科 39。,39。0278611989839。) insert into office values (39。40639。,39。皮膚科 39。,39。0278611451139。) 40 go select * from office。 對(duì)表建約束 因?yàn)樵诮ū淼臅r(shí)候已經(jīng)建了主鍵,所以下面對(duì)表建立其 他的約束。 ( 1)對(duì)表添加檢查約束 use hospital go alter table register add constraint che_re_date check (re_date39。2021010139。) alter table doctor add constraint che_do_phone check (do_phone like 39。[09][09][09][09][09][09][09][09][09][09][09]39。) alter table patient add constraint che_pa_age check (pa_age150 and pa_age0) alter table patient add constraint che_pa_sex check (pa_sex=39。男 39。 or pa_sex=39。女 39。) 41 alter table office add constraint che_of_phone check (of_phone like 39。[09][09][09][09][09][09][09][09][09][09][09]39。) go ( 2)對(duì)表建外鍵約束 use hospital go alter table patient add constraint fk_re_number foreign key(re_number) references register(re_number) alter table dc add constraint fk_do_number foreign key(do_number) references doctor(do_number) 創(chuàng)建 視圖 ( 1)創(chuàng)建一個(gè)掛號(hào)管理的視圖 use hospital go create view view_register as select re_number,re_date,re_way,pa_name from register go ( 2)創(chuàng)建一個(gè)醫(yī)生管理的視圖 use hospital go create view view_doctor as select * from doctor go ( 3)創(chuàng)建一個(gè)病人病案生成的視圖 use hospital go create view view_binganshengcheng 42 as select ,pa_age,pa_sex,cu_name,of_number,doctor.do_phone from patient,doctor,dc where = and = go ( 4)創(chuàng)建藥品劃價(jià)的視圖 use hospital go create view view_drug as select * from drug go ( 5)創(chuàng)建一個(gè)門診收費(fèi)的視圖 use hospital go create view view_drug as select * from drug go ( 6)創(chuàng)建一個(gè)統(tǒng)計(jì)各科室門診情況 use hospital go create view view_gekeshiqingkuang as select ,do_name,pa_name from doctor,office,patient where = and = go 43 建索引 ( 1)在掛號(hào)單上的掛單號(hào)和日期上建一個(gè)索引,以便快速查找和統(tǒng)計(jì)每天掛號(hào)的人數(shù)。 use hospital go create index index_num_date on register(re_number,re_date) ( 2)在醫(yī)生表中的電話上建一個(gè)索引,可以方便的查找一生的 電話 use hospital go create index index_do_name_phone on doctor(do_name,do_phone) ( 3)在病人表建一個(gè)的掛單號(hào),病人姓名唯一索引,以便及時(shí)掌握病人的病情。 use hospital go create index unique index_pa_name on patient(re_number,pa_name) 44 ( 4)在收費(fèi)單上的日期和金額上建索引,可以快速查看醫(yī)院每天的收入情況 use hospital go create index index_charge on charge(ch_date,ch_money) ( 5)在科室的科室號(hào)和電話建索引,可以查找個(gè)科室的聯(lián)系方式,以便各科室之間保持聯(lián)系。 use hospital go create index index_office on office(of_number,of_phone) 建存儲(chǔ)過(guò)程 ( 1)創(chuàng)建醫(yī)生的存儲(chǔ)過(guò)程 use hospital go create procedure pro_doctor as select * from doctor ( 2)創(chuàng)建病人的存儲(chǔ)過(guò)程 use hospital go create procedure pro_patient as select * from patient ( 3)創(chuàng)建掛號(hào)單的存儲(chǔ)過(guò)程 use hospital go 45 create procedure pro_register as select re_number,re_date,re_way,pa_name from register go ( 4)創(chuàng)建病案的存儲(chǔ)過(guò)程 use hospital go create procedure pro_bingan as select ,pa_age,pa_sex,cu_name,of_number,doctor.do_phone from patient,doctor,dc where = and = go ( 5)創(chuàng)建病案的存儲(chǔ)過(guò)程 use hospital go create procedure pro_gekeshiqingkuang as select ,do_name,pa_name from doctor,office,patient where = and = go 建觸發(fā)器 ( 1)創(chuàng)建一個(gè)觸發(fā)器以防止從 hospital數(shù)據(jù)庫(kù)中刪除任何表。 use hospital go 46 create trigger yiyuan_hos on database for drop_table as print39。確定要?jiǎng)h除表時(shí)必須先要禁用本觸發(fā)器 39。 rollback go ( 2)創(chuàng)建了一個(gè)觸發(fā)器,再輸入病人年