2022年数据库系统概论,第五版,教程sql代码 .pdf

上传人:Q****o 文档编号:25952024 上传时间:2022-07-14 格式:PDF 页数:10 大小:60.33KB
返回 下载 相关 举报
2022年数据库系统概论,第五版,教程sql代码 .pdf_第1页
第1页 / 共10页
2022年数据库系统概论,第五版,教程sql代码 .pdf_第2页
第2页 / 共10页
点击查看更多>>
资源描述

《2022年数据库系统概论,第五版,教程sql代码 .pdf》由会员分享,可在线阅读,更多相关《2022年数据库系统概论,第五版,教程sql代码 .pdf(10页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、1.0 createtriggersc_t afterupdateofgradeon sc referencignoldrowas oldtuple newrow as newtuple foreachrow when ( newtuple. grade=1.0 * oldtuple. grade) insertintosc_u ( sno , cno , oldgrade, newgrade) values( oldtuple. sno , oldtuple. cno , oldtuple. grade, newtuple. grade) /* 触发器 */ 2.0 begintransac

2、tion 读取账户甲的金额belance; balance=balance- amount; if( balance0) then 打印 金额不足 , 不能转账 ; rollback; else 读账户乙的余额BALANCE1 ; balance1=balance1+amount; 写回 balance1; commit; 3.0 createdatabasestudent; use student createtablestu ( Sno char( 11 ) Primarykey, Sname char ( 20 ) unique, Ssex char( 2), Sage SMALLINT

3、 , Sdeptchar ( 20 ) ) createtablecourse ( Cno char( 4) PRIMARYKEY , Cname char ( 40 )NOTNULL, Cpno CHAR( 4), CcreditSMALLINT , FOREIGNKEY ( Cpno ) referencescourse( Cno ) ) createtablesc ( Sno char( 11 ), Cno char( 4), Grade SMALLINT , PRIMARYKEY ( Sno , Cno ), FOREIGNKEY ( Sno ) referencesstu ( Sno

4、 ), FOREIGNKEY ( Cno ) referencescourse( Cno ) ) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 10 页 - - - - - - - - - select* from course; 4.0 /* 6.0 建立下面二个关系模式 */ createdatabasework ; use work createtableworker ( Wnochar( 10 ), Wnamechar ( 3), age smallint, j

5、ob char( 3), WmoneySMALLINT , Wpubchar( 5), primarykey( Wno), foreignkey( Wpub) referencesclub( Wpub), check( age =( selectCOUNT( fid) from female)+(selectCOUNT( mid ) from male ) ); 5.0 createdatabasehomewark; use homewark createtables( sno char( 5) primarykey, sname char ( 30 ), statussmallint, ci

6、tychar( 20 ) ); select* from s; createtablep( pno char( 5) primarykey, pname char ( 10 ), colorchar ( 2), weightsmallint ); select* from p; createtablej ( jno char( 2) primarykey, jname chAR ( 15 ), citychar( 10 ) ); select* from j ; createtablespj ( sno char( 2), pno char( 2), jno char( 2), qty sma

7、llint, primarykey( sno , pno , jno ) ); select* from spj ; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 10 页 - - - - - - - - - selectdistinctsno from spj where jno =j1; selectsno from spj where pno =p1 and jno =j1; selectsno from spj , p where spj . pno =p. p

8、no and jno =j1and color= 红 ; selectdistinctsno from spj where pno =p1 and pno in ( selectpno from p where color= 红 ); selectjno from spj , s, p where spj . pno =p. pno and spj . sno =s. sno and color= 红 and city!= 天津 ; selectjno from spj where pno in ( selectpno from p where color= 红 ) and sno in (s

9、electsno from s where city!= 天津 ); selectjno from spj where sno =s1; selectpname , qty 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 10 页 - - - - - - - - - from p, spj where spj . pno =p. pno and spj . jno =j2; selectdistinctp. pno from s , spj , p where s. sn

10、o =spj . sno and spj . pno =p. pno and city= 上海 ; createviewpro1 as selectsno , pno , qty from spj , j where spj . jno =j . jno and jname = 三建 ; selectdistinctpno , qty from pro1 ; select* from pro1 where pno =p1; 6.0 selectsname , sno from stu ; select* from stu orderbySdept, Sage desc ; selectCOUN

11、T( distinctsno ) from sc ; selectCOUNT(*) from stu ; selectcno , COUNT( sno ) from sc groupbyCno ; selectstu .*,sc .* from stu , sc where stu . sno =sc . sno ; selectsname from stu where Sno in ( selectSno from sc where Cno =2); selectsname , sage from stu where Sage any(selectSage名师资料总结 - - -精品资料欢迎

12、下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 10 页 - - - - - - - - - from stu where Sdept=cs) and Sdeptcs; selectsno , sname , sdept from stu where notexists ( select* from sc where Sno =stu . Sno and Cno =1); insert intostu ( Sno , Sname , Ssex , Sdept, sage ) values( 20121512

13、6, 张程 , 男 , cs, 18); select* from stu ; insert intosc ( Sno , Cno ) values( 201215125, 1); select* from sc ; UPDATEstu set Sage =22 where Sno =201215121; select* from stu ; updatestu set Sage =Sage +1; select* from stu ; deletefrom stu where Sno =201215126; select* from stu ; createviewis_stu as sel

14、ectsno , sname , sagefrom stu where Sdept=is; select* 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 10 页 - - - - - - - - - from is_stu; createviewis_s1( sno , sname , grade) as selectstu . Sno , sname , grade from stu , sc where Sdept=isand stu . Sno =sc . Sno

15、 and sc . Cno =1; select* from is_s1; 7.0 createtables( sno char( 5) primarykey, sname char ( 30 ), statussmallint, citychar( 20 ) ); select* from s; createtablep( pno char( 5) primarykey, pname char ( 10 ), colorchar ( 2), weightsmallint ); select* from p; createtablej ( jno char( 2) primarykey, jn

16、ame chAR ( 15 ), citychar( 10 ) ); select* from j ; droptablespj ; createtablespj ( sno char( 2), pno char( 2), jno char( 2), qty smallint, primarykey( sno , pno , jno ) ); select* from spj ; 8.0 select* 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 10 页 - - -

17、 - - - - - - from stu ; -1.0 selectsname from stus1 where exists ( select* from stus2 where s2 . Sdept=s1 . Sdeptand s2 . Sname = 刘晨 ); -2.0 select* from stu where Sdept=cs unionselect* from stu where Sage = 19 ; -3.0 select* from stu where Sdept=cs intersectselect* from stu where Sage = 19 ; -4.0 i

18、nsertintostu ( Sno , Sname , Ssex , Sdept, Sage ) values( 201215128, 陈丹 , 男 , is, 18 ); select* from stu -5.0 insertintosc ( Sno , Cno ) values( 201215128, 1); select* from sc ; -6.0 updatestu set Sage =22 where Sno =201215121; select* from stu ; -7.0 updatestu set Sage =Sage +5; select* from stu ;

19、-8.0 select* from stu where Sname isnullorSsex isnull 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 10 页 - - - - - - - - - or Sage isnullorSdeptisnull; -9.0 createviewdf ( sno , sname , grade) as selectstu . Sno , sname , grade from stu , sc where Sdept=isand

20、stu . Sno =sc . Sno and sc . Cno =1; select* from df ; -10.0 dropviewdf ; createviewdf ( sno , sname , grade) as selectstu . Sno , sname , grade from stu , sc where Sdept=isand stu . Sno =sc . Sno and sc . Cno =1; select* from df ; -11.0 createviewbt_s( sno , gave ) as selectsno , AVG( grade) from s

21、c groupbySno ; selectsno , gave from bt_s; -12.0 grantselect ontablestu to u1 ; -13.0 createtablesss (sno char( 9), cno char( 4), gradesmallint, primarykey( sno , cno ), foreignkey( sno ) referencesstu ( sno ) ondeletecascade onupdatecascade, foreignkey( cno ) referencescourse( cno ) ondeletenoactio

22、n onupdatecascade 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 9 页,共 10 页 - - - - - - - - - ); -14.0 createtablestud ( sno char( 9), sname char ( 8)notnull, ssex char( 2), sage smallint, primarykey( sno ), check( ssex = 女 or sname notlikems.%) ); 15.0 createviewsucceed selectGradefrom sc ; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 10 页,共 10 页 - - - - - - - - -

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 技术资料 > 技术总结

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁