《关系数据库基础与应用》由会员分享,可在线阅读,更多相关《关系数据库基础与应用(2页珍藏版)》请在金锄头文库上搜索。
1、关系数据库基础与应用练习 21存储过程 1第一题:创建一个存储过程,名称为proctsinfo,该存储过程的功能是根据输入的出版社名称查询该出版社所出版的图书信息。create proc proctsinfo3publiname char(20)asselecttb_bookinfo.bookID,bookname,price,authorID,tb_bookinfo.publishIDfromtb_pubinfo,tb_bookinfowhere pubname=publiname and tb_pubinfo.publishID=tb_bookinfo.publishIDexec proc
2、tsinfo3 清华大学出版社第二题:创建一个存储过程,功能是向作者信息表中插入数据,并调用该存储过程插入一条 记录。执行create proc auto_insert(authorID char(4),authname char(20),sex char(2),age tinyint,authaddress char(30)asinsert into tb_authorinfo(authorID,authname,sex,age,authaddress) values(authorID,authname,sex,age,authaddress)exec auto_insert 1119,to
3、m,男,20,北京exec tb_authorinfo_add 1119,tom,男,20,北京第三题:创建一个存储过程,功能是根据输入的出版社名称修改图书表中的图书价格 执行:create proc book_update(pubname char(20),price decimal(18,2)asupdate dbo.tb_bookinfoset dbo.tb_bookinfo.price=price where dbo.tb_pubinfo.publishID=dbo.tb_bookinfo.publishID and dbo.tb_pubinfo.pubname=pubnameexec
4、 book_update 北京大学出版社,2exec tb_bookinfo_update 北京大学出版社,2第四题:创建一个存储过程根据输入的作者姓名删除作者表中的该作者信息执行 create proc auto_del authname char(20) asdelete tb_authorinfo where authname=authnameexec auto_del tom:exec tb_authorinfo_del tom第五题:使用T-SQL命令创建一个名为projcnt的存储过程,该存储过程可以根据输入的 性别统计出该性别的作者人数。如使用语句调用该存储过程declare sum intexec proc_cnt 女,sum outputprint 该性别的作者人数为+convert(char(2),sum)返回的结果如下所示:该性别的作者人数齿d