实验任务书(实验一)课程名称:数据库原理与技术实验报告要求:1.列出所有的SQL语句和源代码;2.程序要求有适当的注释;3.对数据完整性约束实施要求给出相应的测试用例。4.实验报告提交电子档。实验内容:一:创建表和实施数据完整性1.运行给定的SQLScript,建立数据库GlobalToyz。2.了解表的结构。3.利用系统预定义的存储过程sp_helpdb查看数据库的相关信息,例如所有者、大小、创建日期等。4.利用系统预定义的存储过程sp_helpconstraint查看表中出现的约束(包括Primarykey,Foreignkey,checkconstraint,default,unique)其他的表也是用同样的方法查询5.对表Toys实施下面数据完整性规则:(1)玩具的现有数量应在0到300之间;(2)玩具适宜的最低年龄缺省为1。altertabletoysaddconstraintdefLowerAgedefault1forsiLowerAge6.向表Orders中增加10条2016年1月的订单记录(注意Orders表与其它表的关联)。原表插入操作:insertintoOrders(cOrderNo,dOrderDate,cCartId,cShopperId,cShippingModeId,mShippingCharges,mGiftWrapCharges,cOrderProcessed,mTotalCost,dExpDelDate)values('000011','2016-04-0100:00:00.000','000008','000010','01','15.89','4.5','Y','19.8','2016-05-2400:00:00.000')insertintoOrders(cOrderNo,dOrderDate,cCartId,cShopperId,cShippingModeId,mShippingCharges,mGiftWrapCharges,cOrderProcessed,mTotalCost,dExpDelDate)values('000012','2016-04-0300:00:00.000','000009','000011','02','17.98','2.9','Y','58.1','2016-03-0500:00:00.000')insertintoOrders(cOrderNo,dOrderDate,cCartId,cShopperId,cShippingModeId,mShippingCharges,mGiftWrapCharges,cOrderProcessed,mTotalCost,dExpDelDate)values('000013','2016-04-0600:00:00.000','000012','000015','01','10.20','7.1','N','42.8','2016-03-0500:00:00.000')insertintoOrders(cOrderNo,dOrderDate,cCartId,cShopperId,cShippingModeId,mShippingCharges,mGiftWrapCharges,cOrderProcessed,mTotalCost,dExpDelDate)values('000014','2016-04-0200:00:00.000','000013','000019','03','11.70','4.1','Y','47.3','2016-03-0500:00:00.000')insertintoOrders(cOrderNo,dOrderDate,cCartId,cShopperId,cShippingModeId,mShippingCharges,mGiftWrapCharges,cOrderProcessed,mTotalCost,dExpDelDate)values('000015','2016-04-0400:00:00.000','000008','000017','02','19.60','7.4','Y','50.2','2016-03-0500:00:00.000')insertintoOrders(cOrderNo,dOrderDate,cCartId,cShopperId,cShippingModeId,mShippingCharges,mGiftWrapCharges,cOrderProcessed,mTotalCost,dExpDelDate)values('000016','2016-04-0700:00:00.000','000005','000012','03','15.41','6.1','N','43.8','2016-03-0500:00:00.000')insertintoOrders(cOrderNo,dOrderDate,cCartId,cShopperId,cShippingModeId,mShippingCharges,mGiftWrapCharges,cOrderProcessed,mTotalCost,dExpDelDate)values('000017','2016-04-0900:00:00.000','000002','000014','03','15.73','5.9','Y','98.8','2016-03-0500:00:00.000')insertintoOrders(cOrderNo,dOrderDate,cCartId,cShopperId,cShippingModeId,mShippingCharges,mGiftWrapCharges,cOrderProcessed,mTotalCost,dExpDelDate)values('000018','2016-04-0600:00:00.000','000002','000011','01','20.42','7.2','N','112.8','2016-03-0500:00:00.000')insertintoOrders(cOrderNo,dOrderDate,cCartId,cShopperId,cShippingModeId,mShippingCharges,mGiftWrapCharges,cOrderProcessed,mTotalCost,dExpDelDate)values('000019','2016-04-0900:00:00.000','000006','000012','02','27.32','8.8','N','158.6','2016-03-0500:00:00.000')insertintoOrders(cOrderNo,dOrderDate,cCartId,cShopperId,cShippingModeId,mShippingCharges,mGiftWrapCharges,cOrderProcessed,mTotalCost,dExpDelDate)values('000020','2016-04-0400:00:00.000','000004','000011','02','14.06','2.3','Y','20.8','2016-05-2400:00:00.000')7.创建一张表Orders_history,表的结构与Orders相同,将Orders表中2001年5月的订单记录复制到表Orders_history中。Orders表操作后二:查询、更新数据库1.显示属于California和Illinoi州的顾客的名、姓和emailID。2.显示定单号码、顾客ID,定单的总价值,并以定单的总价值的升序排列。3.显示在orderDetail表中vMessage为空值的行。4.显示玩具名字中有“Racer”字样的所有玩具的基本资料。5.列出表PickofMonth中的所有记录,并显示中文列标题。6.根据2000年的玩具销售总数,显示“PickoftheMonth”玩具的前五名玩具的ID。SELECTTOP5cToyId,sum(iTotalSold)FROMPickOfMonthWHEREiYear=2000groupbyctoyidOrderbysum(iTotalSold)desc7.根据OrderDetail表,显示玩具总价值大于¥50的定单的号码和玩具总价值。SELECT'OrderNumber'=cOrderNo,'TotalCostofToyforanOrder'=sum(mToyCost)fromorderdetailgroupbycOrderNohavingsum(mToyCost)508.显示一份包含所有装运信息的报表,包括:OrderNumber,ShipmentDate,ActualDeliveryDate,DaysinTransit.(提示:DaysinTransit=ActualDeliveryDate–ShipmentDate)9.显示所有玩具的名称、商标和种类(ToyName,Brand,Category)。10.以下列格式显示所有购物者的名字和他们的简称:(Initials,vFirstName,vLastName),例如AngelaSmith的Initials为A.S。11.显示所有玩具的平均价格,并舍入到整数。原价:操作之后12.显示所有购买者(Shopper)和收货人(Recipient)的名、姓、地址和所在城市,要求显示结果中的重复记录。Shopper表信息:Recipient表信息:提取两表相同信息方法一:方法二:13.显示没有包装的所有玩具的名称。(要求用子查询实现)首先分析数据库关系图发现OrderDetail这张表可以将Toys和Wrapper这两张表联系起来selectvToyNamefromtoyswherecToyIdin(selectcToyIdfromorderdetailwherecWrapperIdisNULL)于是运用两层子查询:14.显示已收货定单的定单号码以及下定单的时间。(要求用子查询实现)订单号码和下单时间在表Orders中收货状态在表Shipment中用一层子查询实现15.显示一份基于Orderdetail的报表,包括cOrderNo,cToyId和mToyCost,记录以cOrderNo升序排列,并计算每一笔定单的玩具总价值。SELECTcOrderNo,cToyId,mToyCostFROMOrderDetailORDERBYcOrderNoCOMPUTESUM(mToyCost)BYcOrderNo;16.给id为‘000001’玩具的价格增加$1。原表操作后:17.删除“Largo”牌的所有玩具。查看了ToyBrand表的内容发现“Largo”牌的玩具的cBrandId是004按此思路进行操作之后,输出:语句终止了,然后我看了数据关系图发现cToyId是ShoppingCart表中的主键于是,我先将该主键取消但是发现了这样的通知:然后我输出了ShoppingCart表的信息,发现只有cCartId主键不唯一然后我用了另一种方法显示出了信息,但是并没有删除那些行