触发器及建表sl语句.doc

  1. 1、本文档共14页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
触发器及建表sl语句

下面是机构管理部分数据库的建立 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触发器所完成的功能: 插入功能:当向community输入一个新用户的时候会在users表默认生成两个账户,账户名为两位的区县代号+四位的社区代号+00(或者02),相应的账号密码为账号+888,,权限分别为33和65 更新功能:不能更新该社区所在的区县号,其它参数可以改变。修改社区相关信息时会改变users表下的相应账户信息,按照默认的情况同时更新信息上报员和账户管理员的用户名和密码 删除功能:如果删除社区,会同时在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

文档评论(0)

nbc152 + 关注
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档