您好,欢迎访问三七文档
实验一,二1)学生表增加一属性nation(民族),数据类型为varchar(20)。2)删除学生表中新增的属性Nation。3)为学生创建一个名为IX_sname的索引,以姓名排序。4)删除IX_sname索引。createdatabasestudent_course(在“企业管理器”中创建名为student_course数据库)usestudent_coursecreatetablestudent(snochar(9)primarykeynotnull,snamevarchar(20)uniquenotnull,ssexchar(2)notnull,sagesmallintnotnull,sdeptchar(5)notnull);createtablecourse(cnochar(9)primarykeynotnull,cnamevarchar(20)uniquenotnull,cpnochar(9)notnull,ccrebitsmallint);createtablesc(snochar(7)notnull,cnochar(9)notnull,gradenumeric(4,1));insertintostudent(sno,sname,ssex,sage,sdept)values('0215125','张立','男','19','is');select*fromstudentinsertintocourse(cno,cname,cpno,ccrebit)values('3','信息系统','1','4');select*fromcourseinsertintosc(sno,cno,grade)values('1015121','2','85');select*fromscaltertablestudentaddsnationvarchar(20);select*fromstudentaltertablestudentdropcolumnsnation;selectsno,snamefromstudentselect*fromstudent(创建索引)createindexIX_snameonstudent(sname);dropindexstudent.IX_sname;实验三内容1.1.查询所有作者的作者号、姓名信息2.查询所有作者的姓名、作者号信息,并在每个作者的作者号前面显示字符串“身份证号:”,表明显示的信息是身份证信息3.查询在CA州的作者姓名和城市4.查询出版日期在1992.1.1-2000.12.31之间的书名和出版日期(查询1991年出版的书)5.查询每个出版社出版的书6.查询某店销售某书的数量7.查询有销售记录的所有书信息,包括书的编号、书名、类型和价格8.查询已销售书的信息9.显示所有的书名(无销售记录的书也包括在内)10.查询已销售书的信息(书号、书名、作者等)11.查询所有出版商业(business)书籍的出版社的名称usepubs1.selectau_id,au_fname,au_lnamefromdbo.authorsselectau_id,name=au_fname+''+au_lname+''fromdbo.authors2.selectau_id='身份证号'+au_id,name=au_fname+''+au_lname+''fromdbo.authors3.selectname=au_fname+''+au_lname+'',cityfromdbo.authorswherestate='CA'4.selecttitle,pubdatefromdbo.titleswherepubdatebetween'1992.1.1'and'2000.12.31'5.selectpub_name,titlefromdbo.publishers,dbo.titleswheredbo.publishers.pub_id=dbo.titles.pub_id6.selecttitle,stor_name,qtyfromdbo.stores,dbo.titles,dbo.saleswheredbo.stores.stor_id=dbo.sales.stor_idanddbo.titles.title_id=dbo.sales.title_id;7.selecttitle,type,price,titles.title_idfromtitles,saleswheresales.title_id=titles.title_idandqty0orderbytitle9.selecttitlefromdbo.titles10.selectdistincttitle,type,pricefromdbo.titles,dbo.sales,dbo.authorswheredbo.titles.title_id=dbo.sales.title_idanddbo.sales.qty0;11.selectpub_namefromdbo.publishers,dbo.titleswheredbo.publishers.pub_id=dbo.titles.pub_idandtype='business';内容2.1.查询书名以T开头或者出版社号为0877,而且价格大于16的书的信息。2.按照类型的升序和价格的降序(在类型相同时)显示书的信息(书名、作者、出版社、类型、价格)3.查询销售量大于30的书名及销售数量4.查询在2002.1.1到2002.10.31间,每本书的销售总额5.查询所有作者的所在城市和州名,要求没有重复信息6.计算多少种书已被订价7.查询每本书的书名、作者及它的售书总量8.计算所有书的平均价格9.查询价格最高的书的书名、作者及价格usepubs1.selecttitle,pub_id,pricefromdbo.titleswheretitlelike'T%'orpub_idlike'0877'andprice162.selecttitle,type,pricefromdbo.publishers,dbo.titleswheredbo.titles.pub_id=dbo.publishers.pub_idorderbytype,pricedesc;3.selectqty,titlefromdbo.sales,dbo.titleswheredbo.sales.title_id=dbo.titles.title_idandqty30;4.selecttitle,销售总额=sum(price*qty)fromtitles,saleswhereord_datebetween'1994.1.1'and'1994.10.31'andsales.title_id=titles.title_idgroupbytitle5.selectdistinctname=au_fname+''+au_lname+'',city,statefromdbo.authors;6.selectcount(distinctprice)fromdbo.titles;7.selectname=au_fname+''+au_lname+'',title,sum(distinctytd_sales)fromdbo.authors,dbo.titles,dbo.titleauthorwheredbo.authors.au_id=dbo.titleauthor.au_idanddbo.titleauthor.title_id=dbo.titles.title_idgroupbyau_fname,au_lname,title;8.selectavg(price)fromdbo.titles;9.*selecttitle,au_fname+au_lnamename,pricefromtitles,authors,titleauthorwhereprice=(selectmax(distinctprice)fromtitles)andauthors.au_id=titleauthor.au_idandtitles.title_id=titleauthor.title_id内容3;1.参照以上各表给出的主键、外键设置的设置要求,在自己创建的表中进行相应的设置。2.向authors表中插入一行作者信息(具体值自定)3.数量超过100的商店增加10%的折扣4.删除2001.10.3的订单5.删除1中所建立的索引6.建立CA州作者所著书的视图(包括作者号、姓名、所在州、书名、价格、出版日期)7.建立付款方式是现金(cash)的订单视图8.建立CA州的所有商店的视图2.insertintoauthors(au_id,au_lname,au_fname,phone,address,city,state,zip,contract)value~~~~~~3.updatedbo.discountssetdiscount=discount*1.1fromdbo.discounts,dbo.saleswheredbo.discounts.stor_id=dbo.sales.stor_idandqty100;select*fromdbo.discounts;4.deletefromdbo.saleswhereord_date='2001.10.3';6.createviewtitle_authorasselectauthors.au_id,au_fname+au_lnamename,state,title,price,pubdatefromauthors,titles,titleauthorwhereauthors.au_id=titleauthor.au_idandtitleauthor.title_id=titles.title_id7.createviewcashasselectpaytermsfromdbo.saleswherepayterms='cash'8.createviewCAasselect*fromdbo.storeswherestate='CA'
本文标题:数据库习题
链接地址:https://www.777doc.com/doc-5029562 .html