数据库上机实验报告 4.doc





《数据库上机实验报告 4.doc》由会员分享,可在线阅读,更多相关《数据库上机实验报告 4.doc(4页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、数据库上机实验报告 4学号: 姓名: 日期: 年 月 日实验目的:(1)练习连接查询;(2)练习视图的创建与使用;(3)学习使用ODBC的方法;(4)体验T-SQL的功能;体验存储过程的功能;体验表值函数、标量值函数的作用;体验ranking等功能。1 练习视图及连接查询。(1)创建一个视图,视图名为viNF,视图内容为select id,count(*) as nf from friends group by id。执行成功后,将SQL语句复制到下方。(2)基于viNF视图,查找拥有最多好友的用户、最少好友的用户。执行成功后,将SQL语句复制到下方。(3)基于users表和viNF视图进行连
2、接查询。分别进行内连接、全外连接、左外连接、右外连接四种操作。执行成功后,将SQL语句复制到下方,并回答:四种结果表,哪两个的结果是一致的,为什么?(4)将题(3)中全外连接保存为一个新的视图viUAF。2 通过ODBC用Excel打开users表。3 体验T-SQL。回顾实验2中的题目:定义最低价格为成本价;依据此成本价做如下计算:连接Goods,Goods_Extent,Sellers表,按照总利润,输出前10名;要求输出表的格式为(商品名称,卖家名称,商品价格,运费,卖家信誉,卖家好评率,历史销量,历史利润,期内销量,期内利润,总销量,总利润)利用如下语句进行查询,体会和之前有什么不同。
3、如感兴趣,自己可以仿照写一个变量定义、赋值及应用的例子。declare cost as float;select cost=min(good_price) from goods;select top 10 good_name as 商品名称, goods.seller_name as 卖家名称, good_price as 商品价格, good_shipping as 运费, rp_as_seller as 卖家信誉, positive_percent_as_seller as 卖家好评率, good_soldbefore as 历史销量, good_soldbefore*(good_pric
4、e-cost) as 历史利润, good_soldinterm as 期内销量, good_soldinterm*(good_price-cost) as 期内利润, good_soldbefore+good_soldinterm as 总销量, (good_soldbefore+good_soldinterm)*(good_price-cost) as 总利润 from goods,goods_extent,sellers where goods.good_id=goods_extent.good_id and goods.seller_id=sellers.seller_id order
5、 by 总利润 desc;4 体验存储过程。执行如下语句:CREATE PROCEDURE Notes_SQLid intASBEGINprint(存储过程样例);select id,gender,homeprovince from users where id in (select friendID from friends where id=id);END执行完毕后,在可编程性存储过程下查看自己创建的存储过程,并右键点击修改存储过程,观察所展示的代码与上述代码的不同之处。在查询窗口中执行如下语句,理解这一存储过程:exec Notes_SQL 155100422;5 体验存储过程的输入和输
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据库上机实验报告 数据库 上机 实验 报告

限制150内