SQLserver中的表数据的操作

上传人:桔**** 文档编号:486826629 上传时间:2023-08-07 格式:DOC 页数:3 大小:38.50KB
返回 下载 相关 举报
SQLserver中的表数据的操作_第1页
第1页 / 共3页
SQLserver中的表数据的操作_第2页
第2页 / 共3页
SQLserver中的表数据的操作_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《SQLserver中的表数据的操作》由会员分享,可在线阅读,更多相关《SQLserver中的表数据的操作(3页珍藏版)》请在金锄头文库上搜索。

1、实验四表数据的操作(二)实验报告姓名:张娜成绩: _【实验目的】1、掌握用企业管理器完成表数据的检索的方法。2、掌握用Transact-SQL 语言完成表数据的检索的方法。3、掌握视图的定义和操作【实验内容】2、用企业管理器完成查询 2006 年以来的订单号( OrderNo ) ,订购日期( OrderDate ) ,交付 日 期 ( DeliveryDate ) 和 交 付 地 址 ( AddressofDelivery ), 并 按 内 部 订 单 号( InternalOrderNo )降序排列。 (抓图)3、记录相应的SQL 语句( 1)查询表Orders 表的全部信息。select

2、 *from orders( 2)查询表 Products 表中所有商品的名称( Name),许可证代码( License Code)和单价( Price)。select Name,licensecode,price from products( 3)查询表 Order Details 中订购数量( QtyOrdered )不超过 10 的不重复订单号。select distinct orderno from orderdetails where qtyordered20)( 9)查询没有订购过复印机的年份。select distinct datepart(year,orderdate) fr

3、om orders where orderno not in(select orderno from orderdetails where productnoin(select productno from products where name= 复印机 ) ( 10)查询至少和 1002 号订单订购的商品种类相同的订单号。select distinct orderno from orderdetails where productno in(select productno from orderdetails where orderno=1002) and orderno!=10024、用

4、企业管理器在Sales 数据库的上创建视图View_order1,完成显示商品名称、 订购日期、交付日期和订购商量等信息,该视图的定义和结果。(抓图)5、写 SQL 语句在 Sales 数据库的上创建视图的名称,数量,单价和金额的功能。View_order2 ,实现统计每年订购的每种商品create view product_order2(yeartime,name,amount,price,allmoney)asselect datepart(year,orderdate),name,qtyordered,price,price*qtyordered from orders s1 joino

5、rderdetails s2 on s1.orderno=s2.ordernojoin products s3 on s3.productno=s2.productnoselect datepart(yy,orderdate),name,qtyordered,price,price*qtyorderedfrom orders s1 joinorderdetails s2 on s1.orderno=s2.ordernojoin products s3 on s3.productno=s2.productnoselect *from product_order2【思考题】1、编写查询数据和创建视

6、图的SQL 语句( 1)显示地址在北辰小区的旅游业务员姓名。Select oper_nm from operator where oper_add like % 北辰小区 %( 2)显示当年 7 月到 8 月间预订旅游的顾客姓名。 (用 Datepart ()函数)Selectcust_nmfromcustomerwheredatepart(month,start_dt)=7ordatepart(month,start_dt)=8( 3)显示所有旅游业务员的姓名和email 域名。(用 right (), rtrim() , len(), charindex()函数)Select oper_n

7、m,right(oper_email,(len(rtrim(oper_email)-charindex(,oper_email)asemail 域名 from operator( 4)显示每名能导游的旅游线路数(显示旅游业务员的姓名)。Selectoper_nm,count(*)aslinesfromoperatorjoincruiseonoperator.oper_cd=cruise.oper_cd group byoperator. oper_nm( 5)显示所有预期收入低于2000000 的旅行线路及其预期收入。Select cruise_nm ,sum(price)*(sum(tot_

8、seats)-sum(seats_avail)/count(price) total from cruise join cruise_book oncruise.cruise_cd=cruise_book.cruise_cdgroupbycruise_nmhavingsum(price)*(sum(tot_seats)-sum(seats_avail)/count(price)8( 9)通过视图long_cruise 修改表 cruise 的数据,将所有线路的价格增加15% 。update long_cruise set price=price*1.15( 10)删除名为 long_cruise 的视图。drop view long_cruise【实验小结】数据库是用于内部设计的,查询功能很强大,视图是为了供用户查询的,视图只是个虚表,它不会加快运行速度。

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

当前位置:首页 > 办公文档 > 活动策划

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号