




已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1.0create trigger sc_tafter update of grade on screferencign oldrow as oldtuplenewrow as newtuplefor each rowwhen(newtuple.grade=1.0*oldtuple.grade)insert into sc_u(sno,cno,oldgrade,newgrade)values(oldtuple.sno,o,oldtuple.grade,newtuple.grade)/* 触发器 */2.0begin transaction读取账户甲的金额 belance;balance=balance-amount;if(balance0)then打印金额不足,不能转账;rollback;else 读账户乙的余额BALANCE1;balance1=balance1+amount;写回 balance1;commit;3.0create database student;use studentcreate table stu(Sno char(11) Primary key, Sname char(20) unique, Ssex char(2), Sage SMALLINT, Sdept char(20) ) create table course (Cno char(4) PRIMARY KEY, Cname char(40) NOT NULL, Cpno CHAR(4), Ccredit SMALLINT, FOREIGN KEY(Cpno) references course(Cno) ) create table sc (Sno char(11), Cno char(4), Grade SMALLINT, PRIMARY KEY(Sno,Cno), FOREIGN KEY(Sno) references stu(Sno), FOREIGN KEY(Cno) references course(Cno) ) select *from course;4.0/* 6.0 建立下面二个关系模式 */create database work;use workcreate table worker( Wno char(10), Wname char(3), age smallint, job char(3), Wmoney SMALLINT, Wpub char(5), primary key(Wno), foreign key(Wpub) references club(Wpub), check(age=(select COUNT(fid) from female)+(select COUNT(mid) from male) ); 5.0create database homewark;use homewarkcreate table s( sno char(5) primary key, sname char(30), status smallint, city char(20) ); select * from s; create table p( pno char(5) primary key, pname char(10), color char(2), weight smallint ); select * from p; create table j( jno char(2) primary key, jname chAR(15), city char(10) ); select * from j; create table spj( sno char(2), pno char(2), jno char(2), qty smallint, primary key(sno,pno,jno) ); select * from spj; select distinct sno from spj where jno=j1; select sno from spj where pno=p1 and jno=j1; select sno from spj,p where spj.pno=p.pno and jno=j1 and color=红; select distinct sno from spj where pno=p1 and pno in ( select pno from p where color=红); select jno from spj,s,p where spj.pno=p.pno and spj.sno=s.sno and color=红 and city!=天津; select jno from spj where pno in ( select pno from p where color=红) and sno in ( select sno from s where city!=天津); select jno from spj where sno=s1; select pname,qty from p,spj where spj.pno=p.pno and spj.jno=j2; select distinct p.pno from s,spj,p where s.sno=spj.sno and spj.pno=p.pno and city=上海; create view pro1 as select sno,pno,qty from spj,j where spj.jno=j.jno and jname=三建; select distinct pno,qty from pro1; select * from pro1 where pno=p1;6.0select sname,snofrom stu;select*from stuorder by Sdept,Sage desc;select COUNT(distinct sno)from sc;select COUNT(*)from stu;select cno,COUNT(sno)from scgroup by Cno;select stu.*,sc.*from stu,scwhere stu.sno=sc.sno;select snamefrom stuwhere Sno in(select Sno from sc where Cno=2); select sname,sage from stu where Sageany(select Sage from stu where Sdept=cs) and Sdeptcs; select sno,sname,sdept from stu where not exists (select* from sc where Sno=stu.Sno and Cno=1); insert into stu(Sno,Sname,Ssex,Sdept,sage) values(201215126,张程,男,cs,18); select* from stu; insert into sc(Sno,Cno) values(201215125,1); select* from sc; UPDATE stuset Sage=22where Sno=201215121;select* from stu; update stu set Sage=Sage+1; select* from stu; delete from stu where Sno=201215126; select* from stu; create view is_stu as select sno,sname,sage from stu where Sdept=is; select* from is_stu; create view is_s1(sno,sname,grade)asselect stu.Sno,sname,gradefrom stu,scwhere Sdept=is and stu.Sno=sc.Sno and sc.Cno=1;select*from is_s1;7.0create table s( sno char(5) primary key, sname char(30), status smallint, city char(20) ); select * from s; create table p( pno char(5) primary key, pname char(10), color char(2), weight smallint ); select * from p; create table j( jno char(2) primary key, jname chAR(15), city char(10) ); select * from j; drop table spj; create table spj( sno char(2), pno char(2), jno char(2), qty smallint, primary key(sno,pno,jno) ); select * from spj;8.0select *from stu; -1.0select snamefrom stu s1where exists( select *from stu s2where s2.Sdept=s1.Sdept ands2.Sname=刘晨);-2.0select *from stuwhere Sdept=csunion select *from stuwhere Sage=19;-3.0select *from stuwhere Sdept=csintersect select *from stuwhere Sage=19;-4.0insert into stu (Sno,Sname,Ssex,Sdept,Sage)values(201215128,陈丹,男,is,18);select *from stu-5.0insert into sc(Sno,Cno)values(201215128,1);select *from sc;-6.0update stuset Sage=22where Sno=201215121;select *from stu;-7.0update stuset Sage=Sage+5;select *from stu;-8.0select *from stuwhere Sname is null or Ssex is nullor Sage is null or Sdept is null;-9.0create view df(sno,sname,grade)asselect stu.Sno,sname,gradefrom stu,scwhere Sdept=is andstu.Sno=sc.Sno andsc.Cno=1;select * from df;-10.0drop view df;create view df(sno,sname,grade)asselect stu.Sno,sname,gradefrom stu,scwhere Sdept=is andstu.Sno=sc.Sno andsc.Cno=1;select * from df;-11.0create view bt_s(sno,gave)asselect sno,AVG(grade)from scgroup by Sno;select sno,gavefrom bt_s;-12.0grant selecton table stuto u1;-13.0create table sss( sno char(9), cno char(4), grade smallint, primary key(sno,cno), foreign key(sno) references stu(sno) on delete cascade on update cascade, foreign
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 神经科病人的饮食护理
- 公司级安全教育培训心得课件
- 房地产年度汇报
- 《荷叶母亲》说课件课
- 鞋厂跟单工作总结
- 了不起的轮子课件
- 辅导教师学期工作总结
- 乳酸酚棉蓝染色课件
- 《罗斯福集邮》课件
- 服装店设计汇报
- 汇率预测模型优化-洞察及研究
- 稳评机构各项管理制度
- 建筑安全与人工智能的深度结合
- 2026年高考政治一轮复习:选择性必修1~3共3册知识点背诵提纲汇编
- 广告标识牌采购投标方案
- 北京市2025年第一次普通高中学业水平合格性考试政治试题(原卷版)
- 公墓建设项目合同协议书
- 家政服务行业互联网+平台商业模式创新与盈利模式研究报告
- (高清版)DG∕TJ 08-59-2019 钢锭铣削型钢纤维混凝土应用技术标准
- GSP药品经营质量管理规范培训
- 网吧网管硬件技术培训手册
评论
0/150
提交评论