触发器及建表sql语句
下面是机构管理部分数据库的建立 create table users
(
username varchar(8) primary key,
passwd varchar(15) not null,
permit integer not null,
org varchar(30) not null
);
create table county
(
county_name varchar(10) primary key,
init char(2)
);
create table hospital
(
code char(4) primary key,
hos_name varchar(20) not NULL,
county varchar(10) not null,
foreign key(county) references county(county_name)
);
create table community
(
code char(4) primary key,
hos_name varchar(20) not NULL,
county varchar(10) not null,
foreign key(county) references county(county_name)
);
下面是机构管理的触发器和数据初始化
社区信息表community触发器所完成的功能:
1、插入功能:当向community输入一个新用户的时候会在users表默认生成两个账户,账户名为两位的区县代号+四位的社区代号+00(或者02),相应的账号密码为账号+888,,权限分别为33和65
2、更新功能:不能更新该社区所在的区县号,其它参数可以改变。修改社区相关信息时会改变users表下的相应账户信息,按照默认的情况同时更新信息上报员和账户管理员的用户名和密码
3、删除功能:如果删除社区,会同时在users表中删除该社区所拥有的信息上抱员和账户管理员的账户和密码
create or replace trigger community_trigger after insert or update or delete
on community for each row
begin
if inserting then
Insert into users(username,passwd,permit,org) values((select DISTINCT init from county where county_name=:NEW.county) || :NEW.code ||'00' ,(select DISTINCT init from county where county_name=:NEW.county) || :NEW.code || '00' || '888' , 33 , :NEW.hos_name);
Insert into users(username,passwd,permit,org) values((select DISTINCT init from county where county_name=:NEW.county)||:NEW.code||'02',(select DISTINCT init from county where county_name=:NEW.county) || :NEW.code || '02' || '888' ,65, :NEW.hos_name);
elsif updating then
Update users set
username=(select DISTINCT init from county where county_name=:NEW.county) || :NEW.code || '00',
passwd=(select DISTINCT init from county where county_name=:NEW.county) || :NEW.code || '00' || '888',
org=:NEW.hos_name
Where username=(select DISTINCT init from county where county_name=:OLD.county)||:OLD.code||'00';
Update users set
username=(select DISTINCT init from county where county_name=:NEW.county) || :NEW.code || '02',
passwd=(select DISTINCT init from county where county_name=:NEW.county) || :NEW.code || '02' || '888',
org=:NEW.hos_name
Where username=(select DISTINCT init from county where county_name=:OLD.county) || :OLD.code || '02';
elsif deleting then
Delete from users where username=(select DISTINCT init from county where county_name=:OLD.county) || :OLD.code ||'00';
Delete from users where username=(select DISTINCT init from county where county_name=:OLD.county) || :OLD.code ||'02';
end if;
end;
医院信息表hospital触发器完成三个功能:
(医院信息表hospital的触发器完成的功能和社区信息表触发器完成的功能差不多一样,有区别只是生成账号的权限不一样而已,其它都一样)
create or replace trigger hospital_trigger after insert or update or delete
on hospital for each row
begin
if inserting then
Insert into users(username,passwd,permit,org) values((select DISTINCT init from county where county_name=:NEW.county) || :NEW.code ||'00' ,(select DISTINCT init from county where county_name=:NEW.county) || :NEW.code || '00' || '888' , 34 , :NEW.hos_name);
Insert into users(username,passwd,permit,org) values((select DISTINCT init from county where county_name=:NEW.county)||:NEW.code||'02',(select DISTINCT init from county where county_name=:NEW.county) || :NEW.code || '02' || '888' ,66, :NEW.hos_name);
elsif updating then
Update users set
username=(select DISTINCT init from county where county_name=:NEW.county) || :NEW.code || '00',
passwd=(select DISTINCT init from county where county_name=:NEW.county) || :NEW.code || '00' || '888',
org=:NEW.hos_name
Where username=(select DISTINCT init from county where county_name=:OLD.county)||:OLD.code||'00';
Update users set
username=(select DISTINCT init from county where county_name=:NEW.county) || :NEW.code || '02',
passwd=(select DISTINCT init from county where county_name=:NEW.county) || :NEW.code || '02' || '888',
org=:NEW.hos_name
Where username=(select DISTINCT init from county where county_name=:OLD.county) || :OLD.code || '02';
elsif deleting then
Delete from users where username=(select DISTINCT init from county where county_name=:OLD.county) || :OLD.code ||'00';
Delete from users where username=(select DISTINCT init from county where county_name=:OLD.county) || :OLD.code ||'02';
end if;
end;
账户和密码注意:系统管理员可以修改账户和密码,其它用户只能修改自己的密码。
预定义先往数据库里添加信息:
添加区县信息:
insert into county(county_name,init) values('金山区','js');
insert into county(county_name,init) values('黄浦区','hp');
insert into county(county_name,init) values('徐汇区','xh');
insert into county(county_name,init) values('长宁区','cn');
insert into county(county_name,init) values('静安区','ja');
insert into county(county_name,init) values('普陀区','pt');
insert into county(county_name,init) values('闸北区','zb');
insert into county(county_name,init) values('虹口区','hk');
insert into county(county_name,init) values('杨浦区','yp');
insert into county(county_name,init) values('闵行区','mx');
insert into county(county_name,i …… 此处隐藏:4877字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [求职职场]加法运算定律的运用练习题
- [求职职场]大型石油化工工业过程节能新技术
- [求职职场]2015-2020年中国箱纸板行业分析与投资
- [求职职场]NADEX-IWC5A点焊机故障代码
- [求职职场]英语阅读 非常有用
- [求职职场]鲁卫疾控发〔2012〕2号(联合,印发山东
- [求职职场]2014年莆田公务员行测技巧:数字推理的
- [求职职场]基于最近发展区理论的高中数学课堂有效
- [求职职场]与贸易有关的知识产权协议
- [求职职场]【王风范】微演说·职场演说三
- [求职职场]新时代国珍健康大课堂
- [求职职场]群论期末考试复习题
- [求职职场]施工现场消防安全专项施工方案(范本)-
- [求职职场]初中物理光学知识点归纳完美版
- [求职职场]毕业设计总结与体会范文
- [求职职场]江南大学2018年上半年展示设计第1阶段
- [求职职场]景尚乡民兵参战支前保障方案
- [求职职场]【优质】2019年工会职工之家建设工作总
- [求职职场]数据库技术与应用—SQL Server 2008(第
- [求职职场]汽车变速箱构造与工作原理
- 首钢工业区工业遗产资源保护与再利用研
- 第4课 《大学》节选
- 2016程序文件——检验检测结果发布程序
- 2011年高考试题文言文阅读全解释__2011
- 化学是一门基础的自然科学
- 海外做市商制度的借鉴意义
- 外国建筑史复习资料(
- 七年级下思想品德期末综合测试(二)
- 思政课部2013年上学期教学工作总结
- 电大国际公法任务3 0004
- 《圆的认识》教学设计
- 中国轨道交通牵引变流器行业市场发展调
- 中泰证券#定期报告:坚守时代硬科技和
- 浅论企业财务管理与企业经营投资风险的
- 大功率半导体激光器光纤耦合技术调研报
- 中国传统家具的现状与发展探讨
- Broadcom数字电视芯片助海尔扩展高清电
- 新HSK4词汇练习 超全(五)
- 2013届高考数学单元考点复习12
- 雨霖铃精品课件




