《SQL Server数据库实用案例教程》 实验10-存储过程练习 参考代码-不要先发学生.docx





《《SQL Server数据库实用案例教程》 实验10-存储过程练习 参考代码-不要先发学生.docx》由会员分享,可在线阅读,更多相关《《SQL Server数据库实用案例教程》 实验10-存储过程练习 参考代码-不要先发学生.docx(4页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、提示:不要把答案先发给学生,实验结束后再公布答案。要让学生先自己思考做题,老师对学生不会的题目适当提示,一题题解决困惑。实验10存储过程练习参考代码/*继续使用实验创建的银行储蓄数据库,客户信息(customerinfo)表、账户信息(accountinfo)表、交易信息(transInfo)表三个表的表结构见表易信表-20。*/(1)题 存款存储过程-创建存储过程的语句create proc p_ck-定义存储过程zh char(19),je decimal(202),-两个输入参数mess varchar(50) outputas*不蛤U-1余柄-存储过套语法中必须有的关键字beginse
2、t nocount onifje 1-判断存款大于元beginif exists(select accountID from accountinfowhere accountID = zh and accountstate =正常)beginINSERT INTO transInfo(accountID, transType, transMoney)VALUES(zh;存入;je)-交易信息表transInfo插入存款记录update accountinfo set accountMoney = accountMoney + jeWHERE accountID = zh-更新卡余额select
3、 mess 廿存款成功!账号:+zh+存入:ltrim(str(je)+元endelseselect mess =账号不存在,或已经挂失! endelseselect mess=存款金额不可以小于元,End龙象资源告理器0 0 LAPTOP-NMGPMIMMsql2008 (SQL S田一I系统数据库+ 数是座二花 日 U bank数据库关系图囹口表因 视图田口同义词0 一1可编程性创建成功后在对象资源管理器中查看。星dbp_ck以下为执行存储过程的语句,不要与创建存储过程的语句一起执行-给账号1005存款50元declare ms varchar( 100exec p_ck U005 50
4、, ms output print msJ消息执行结果:存款成功!账号:1005存入:50元-执行存储过程前后分别查看两个表中数据select * from accountinfo where accountID = *1005*select * from transInfo where accountID = *1005*-执行存储过程之前两个表中数据口结果消息accountID savingType moneyType openDateopenMoney accountMoney password accountstate cus11005 -活期 人民币 2023-06-1510:45:
5、25.273 40.0040 00666666 正常5transID transDateaccountID transType transMoney bz1transIDtransDate2023-05-06 00:00:00 000accountID 1005transType存入transMoney 40 00bzNULLIIlli| 5132023-06-1511:27:25.0331005存入50 00null口结果3消息1| 5 I 2023-05-06 00:00:00 000 1005 存入 40.00 NULL1accountID1005savingType moneyType
6、 openDateopenMoney活期人民币2023-06-1510:45:25.273 40.00accountMoney 90 00Jpassword accountstate cus666666 正常5-执行存储过程之后两个表中数据(2)题生成账号存储过程/*随机产生十九位账号*/*第一种方式创建存储过程不定义变量*/create proc p_zh 1randZH chart 19 output asselectrandZH=,60138261050r+right(0000000+LTRIM(str(ceiling(Rand()* 10000000)5)/*第二种方式创建存储过程定义
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- SQL Server数据库实用案例教程 SQL Server数据库实用案例教程 实验10-存储过程练习 参考代码-不要先发

链接地址:https://www.taowenge.com/p-96866910.html
限制150内