sql第八章 实践练习

合集下载

SQL课后练习题(1-9章答案)

SQL课后练习题(1-9章答案)

第一章1、数据完整性是指( D )A.数据库存中的数据不存在重复B.数据库中所有的数据格式是一样的C.所有的数据全部保存在数据库中D.数据库中的数据能够正确反映情况2、SQL中pubs数据库属于(A )A.用户数据库B.系统数据库C.数据库模板D.数据库管理系统3、数据冗余指的是( D )A.数据与数据之间没有联系B.数据有丢失C.数据量太大D.存在重复的数据4、SQL Server数据库的主数据文件的扩展名为( B )A. .sqlB. .mdfC. .mdbD. .ldf5、下列关于关系数据库叙述错误的是(B )A.关系数据库的结构一般保持不变,但也可根据需要进行改变B.一个数据表组成一个关系数据库,多种不同数据则需要创建多个数据库C. 关系数据库表中的所有记录的关键字字段的值互不相同D. 关系数据库表中的外部关键字不能用于区别该表中的记录6、创建数据库时,需要指定( C )属性。

A.数据库初始大小B.数据库的存放位置C.数据库的物理名和逻辑名D.数据库的访问权限7、以下说法正确的是( A )A.通过SQL Server服务器对SQL Server的启动、停止和通过服务管理器对SQL Server的启动、停止是同等功效B.必须先启动服务管理器中的SQL Server服务之后才能通过SQL Server服务管理器启动SQL ServerC.必须先通过SQL Server服务管理器启动SQL Server之后才能启动服务管理器中的SQL Server服务D.只能通过服务管理器对SQL S erver进行启动和停止8、SQL Server提供的4个系统数据库,以下说法正确的是( D )A.tempdb数据库是一个空数据库,完全可以删除B.adventure works是用来做模板的一个数据库C.msdb数据库是用来做例子的数据库D.创建新的空白数据库时,将使用Model数据库所规定的默认值9、以下说法错误的是(C)A.数据完整性是指存储在数据库中数据的准确性B.SQL Server是一个DBMSC.ERP、CRM、MIS等都是DBMSD.设计数据库时允许必要的冗余第二章1、创建银行的贷款情况表时,“还款日期”默认为当天,且必须晚于“借款日期”,应采用(A)约束。

数据库第8章习题参考答案

数据库第8章习题参考答案

第8章习题参考答案2.求程序的运行结果(1)Public Sub 习题8_2_1()Dim i As IntegerDebug.Print Tab(10); "*"For i = 1 To 5Debug.Print Tab(10 - i); "*"; Spc(i - 1); "*"; Spc(i - 1); "*"Next iFor i = 4 To 1 Step -1Debug.Print Tab(10 - i); "*"; Spc(i - 1); "*"; Spc(i - 1); "*"Next iDebug.Print Tab(10); "*"End Subrun:***** * ** * ** * ** * ** * ** * ** * *****(2)Public Sub 习题4_2_2()Dim x, y, i As Doublex = 0: y = 0For i = 1 To 8If i Mod 2 <> 0 Thenx = x - iElsey = y + iEnd IfNextDebug.Print "i="; iDebug.Print "x="; xDebug.Print "y="; yEnd Subrun:x=-16y= 20(3)Public Sub习题4_2_3()Dim m, s, k As Doublem = 28s = 0k = 1Do While k <= Int(m / 2)If Int(m / k) = m / k ThenDebug.Print ks = s + kEnd Ifk = k + 1LoopDebug.Print "s="; sEnd Subrun:124714s= 28(4)Public Sub 习题8_2_4()Dim n, a1, a2, a3, i As Doublen = Val(InputBox("请输入n,要求n>=3"))If n <= 2 ThenExit SubEnd Ifa1 = 1a2 = 1Debug.Print a1; a2For i = 2 To n - 1a3 = a1 + a2a1 = a2a2 = a3Debug.Print a3NextEnd Sub1 12353.改错题(1)Public Sub 改错8_3_1()Dim i, n, s As Doublen = Val(InputBox("请输入n"))i = 2: s = 1Do While i <= ns = s + ii = i + 1LoopDebug.Print "S="; sEnd Sub(2)Public Sub 改错8_3_2_求分式多项和()Dim nm, n, k ,p As integerDim y As Doublenm = Val(InputBox("请输入计算公式1后面的项目数目个数")) n = 1: p = 1: y = 1Do While n <= nmk = 2 * n + 1p = p * (k - 1) * ky = y + ((-1) ^ n) / pn = n + 1LoopDebug.Print "y="; yEnd Sub4.编程题(1)用if……else语句编程Public Sub分段函数1()Dim x, y, z As Doublex = Val(InputBox("请输入x的值:"))y = Val(InputBox("请输入y的值:"))If x > y And y <> 0 Thenz = x / yElseIf x = y Thenz = x * y * Sgn(y)Elsez = x + yEnd IfDebug.Print "x="; xDebug.Print "y="; yDebug.Print "z="; zEnd Sub(1)用select case语句结构编程Public Sub分段函数2()Dim x, y, z, a As Doublex = Val(InputBox("请输入x"))y = Val(InputBox("请输入y"))a = y - xSelect Case aCase Is > 0z = x + yDebug.Print zCase 0z = x * y * Sgn(y)Debug.Print zCase ElseIf y <> 0 Thenz = x / yDebug.Print zElseDebug.Print "z没有值"End IfEnd SelectEnd Sub(2)Public Sub 求解一元二次方程()Dim a, b, c As IntegerDim d, x1, x2, x3, x4 As Doublea = Val(InputBox("请输入a的整型数:"))b = Val(InputBox("请输入b的整型数:"))c = Val(InputBox("请输入c的整型数:"))d = b * b - 4 * a * cIf d > 0 Thenx1 = (-b + Sqr(d)) / (2 * a)x2 = (-b - Sqr(d)) / (2 * a)Debug.Print "x1="; x1, "x2="; x2Else if d=0 thenx3 = -b / (2 * a)x4 = -b/ (2 * a)Debug.Print "x3=";x3Debug.Print "x4=";x4ElseDebug.Print "方程没有实数解"End IfEnd Sub(3--1)用无条件转向语句GOTO编程Public Sub 数字与星期的转换1()Dim num As Integer10 num = Val(InputBox("请输入整数值:")) If num = 0 ThenDebug.Print "这是星期日"ElseIf num = 1 ThenDebug.Print "这是星期一"ElseIf num = 2 ThenDebug.Print "这是星期二"ElseIf num = 3 ThenDebug.Print "这是星期三"ElseIf num = 4 ThenDebug.Print "这是星期四"ElseIf num = 5 ThenDebug.Print "这是星期五"ElseIf num = 6 ThenDebug.Print "这是星期六"ElseIf num = -1 ThenDebug.Print "程序运行结束"EndElseDebug.Print "输入数据错误!"GoTo 10End IfEnd Sub(3--2)Public Sub数字与星期的转换2 ()Dim x As IntegerDo While Truex = Val(InputBox("请输入数字"))If x = 0 ThenDebug.Print "这是星期日"Exit DoElseIf x >= 1 And x <= 6 ThenDebug.Print "这是星期" + Str(x)Exit DoElseIf x = -1 ThenExit DoElseMsgBox ("输入数据错误!")End IfLoopEnd Sub(4)Public Sub 行李重量计费()Dim an, cn, weight, s_w, distance, fee As Doublean = Val(InputBox("请输入成年人数量"))cn = Val(InputBox("请输入未成年人数量"))weight = Val(InputBox("请输入行李重量"))distance = Val(InputBox("请输入距离"))s_w = weight - 20 * an - 10 * cnIf s_w <= 0 Thenfee = 0ElseIf distance / 100 = Int(distance / 100) Thenfee = 0.2 * s_w * (distance / 100)Elsefee = 0.2 * s_w * (Int(distance / 100) + 1) End IfEnd IfDebug.Print feeEnd Sub(5)Public Sub 求自然数的多项式和()Dim n, s As Integers = 0For n = 1 To 10s = s + (s + n)NextDebug.Print "S=1+(1+2)+(1+2+3)+...+1+2+3+...+10)="; s End SubRun:S=1+(1+2)+(1+2+3)+...+1+2+3+...+10)= 2036Public Sub 求多项自然数阶乘的和()Dim s, t As SingleDim n As Integert = 1s = 0For n = 1 To 20t = t * ns = s + tNextDebug.Print "1!+2!+3!+...+20!="; sEnd SubRun:1!+2!+3!+...+20!= 2.561327E+18(6)Public Sub 既能被3整除又能被5整除正整数个数() Dim i, x As Integerx = 0For i =100 To 200If i / 3 = Int(i / 3) And i / 5 = Int(i / 5) ThenDebug.Print ix = x + 1End IfNextDebug.Print "x="; xEnd SubRun:120135150165180195x= 7(7)Public Sub 输出直角三角形图案1()Dim i, j As IntegerFor i = 1 To 9Debug.PrintNextFor i = 1 To 4Debug.Print Tab(20); "*";For j = 1 To (2 * i - 2)Debug.Print "*";NextDebug.PrintNextEnd SubRun:****************Public Sub 输出直角三角形图案2() Dim i, j As IntegerFor i = 1 To 9Debug.PrintNextDebug.Print Tab(20); "*";For i = 1 To 4Debug.Print Tab(19 - i); "*";For j = 1 To (i + 1)Debug.Print "*";NextDebug.PrintNextEnd SubRun:*******************Public Sub 输出平行四边形图案() Dim i, j As IntegerFor i = 1 To 9Debug.PrintNextFor i = 1 To 5Debug.Print Tab(21 - i);For j = 1 To 6Debug.Print "*";NextDebug.PrintNextEnd SubRun:******************************(8)Public Sub 求选手获得的平均分()Dim score(1 To 11), minno, maxno, sum, aver As Single Dim i As Integerminno = 1maxno = 1sum = 0For i = 1 To 10score(i) = Val(InputBox("请输入选手的成绩值:")) Debug.Print score(i)NextFor i = 2 To 10If score(i) < score(minno) Thenminno = iEnd IfIf score(i) > score(maxno) Thenmaxno = iEnd IfNext iFor i = 1 To 10sum = sum + score(i)Next isum = sum - score(minno) - score(maxno)aver = sum / 8Debug.Print "该选手的平均分是:"; averEnd Sub(9)关于素数的求解(9-1)求100之内的所有素数Public Sub 求所有素数之和()Dim s, w, n As Integers = 0For w = 2 To 99 Step 2For n = 2 To Sqr(w)If w Mod n = 0 ThenExit ForEnd IfNextIf n > Sqr(w) Thens = s + wEnd IfDebug.Print "S="; sNextEnd Sub(9-2)Public Sub 求200以内的所有素数()Dim w, n As IntegerDebug.Print "200 以内的所有素数是:" For w = 2 To 199For n = 2 To Sqr(w)If w Mod n = 0 ThenExit ForEnd IfNext nIf n > Sqr(w) ThenDebug.Print w;End IfNextDebug.PrintEnd Sub(10)Public Sub 求水仙花数1()Dim i, j, k, n As IntegerDebug.Print "水仙花数是:"For i = 1 To 9For j = 0 To 9For k = 0 To 9n = i * 100 + j * 10 + kIf n = i * i * i + j * j * j + k * k * k ThenDebug.Print n;End IfNext kNext jNext iDebug.PrintEnd SubPublic Sub 求水仙花数2()Dim i, j, k, n As IntegerDebug.Print "水仙花数是:"For n = 150 To 999i = Int(n / 100)j = Int(n / 10 - i * 10)k = n Mod 10If n = i * i * i + j * j * j + k * k * k ThenDebug.Print n;End IfNextDebug.PrintEnd Subrun:水仙花数是:153 370 371 407(11)Public Sub 求分数数列和()Dim i, t, n As IntegerDim a, b, s As Singlen = 20a = 2:b = 1: s = 0For i = 1 To ns = s + a / bt = aa = a + bb = tNextDebug.Print "sum="; s;End Sub(12)Public Sub N年达到的利息()Dim y As IntegerDim interest1,interest As DoubleP=10000y = 0interest = 0Do Until interest >= 1000Interest1 =2*p* 0.0225 *(1-0.2) ‘一期2年整存整取扣税后的利息p=p+interest1 ‘扣税后的利息加上本金成为新一期的本金Interest=p-10000 ‘存款以来实际所的利息y = y + 2Debug.Print interest, yLoopEnd SubRun:360 2732.959999999999 4 1119.34656 6。

sql server 2008 数据库应用与开发教程 课后习题参考答案

sql server 2008 数据库应用与开发教程  课后习题参考答案

SQL Server 2008数据库应用与开发教程(第二版)第一章习题参考答案1.简述SQL Server 2008系统中主要数据库对象的特点。

答:主要的数据库对象包括数据库关系图、表、视图、同义词、存储过程、函数、触发器、程序集、类型、规则和默认值等。

“表”节点中包含了数据库最基本、最重要的对象——表。

表实际用来存储系统数据和用户数据,是最核心的数据库对象。

“视图”节点包含了数据库中的视图对象。

视图是一种虚拟表,用来查看数据库中的一个或多个表,视图是建立在表基础之上的数据库对象,它主要以SELECT语句形式存在。

在“同义词”节点中包含了数据库中的同义词对象。

这是Microsoft SQL Server 2008系统新增的一种对象。

“可编程性”对象是一个逻辑组合,它包括存储过程、函数、触发器、程序集、类型、规则和默认值等对象。

数据库中的函数对象包含在“函数”节点中。

函数是接受参数、执行复杂操作并将结果以值的形式返回的例程。

2.SQL Server 2008数据库管理系统产品分为哪几个版本,各有什么特点?答:SQL Server 2008数据库管理系统产品的服务器版本包括了企业版和标准版,专业版本主要包括以下版本:工作组版(Workgroup)、开发人员版(Developer)、免费精简版(Express)、Web版,以及免费的集成数据库SQL Server Compact 3.5。

3.SQL Server 2008包含哪些组件,其功能各是什么?答:SQL Server 2008的体系结构是对SQL Server的组成部分和这些组成部分之间的描述。

Microsoft SQL Server 2008系统由4个组件组成,这4个组件被称为4个服务,分别是数据库引擎、Analysis Services、Reporting Services和Integration Services。

数据库引擎是Microsoft SQL Server 2008系统的核心服务,负责完成数据的存储、处理、查询和安全管理等操作。

第8章课后习题答案知识讲解

第8章课后习题答案知识讲解

学习资料第9 课为学生信息管理系统创建存储过程1. 什么是存储过程?使用存储过程有哪些特点?答:存储过程是一种数据库对象,通常是把实现某个特定任务的一组预编译的SQL 语句创建一个存储过程,以一个存储单元的形式存储在服务器上,供用户反复调用,提高程序的使用效率。

使用存储过程的优点:允许模块化程序设计;允许更快执行;减少网络流量;可作为安全机制使用。

2. 试说明存储过程分类的特点。

答:1)系统存储过程。

存储在master数据库中,并以sp_为前缀,许多管理和信息活动可以通过系统存储过程执行。

2)本地存储过程。

是用户自行创建的并存储在用户数据库中的存储过程。

这类存储过程能根据用户的实际需要完成某以特定的功能。

3)临时存储过程。

临时存储过程分为本地临时存储过程和全局临时存储过程。

在创建存储过程时。

如果过程名的第一个字符取“#”,那么创建的就是本地临时存储过程;如果过程名的第一•第二字符都取,那么创建的就是全局临时存储过程。

临时存储过程存储在tempbd 内,它们在连接到SQL Server 以前的版本时很有用。

4)远程存储过程。

指非本地服务器上的存储过程,只有在分布式查询中使用此存储过程。

5)扩展存储过程。

扩展存储过程是用户使用外部程序语言编写的存储过程。

使用时需要先加载到SQLServer 系统中,且只能存储在master 数据库中,其执行与一般的存储过程完全相同。

引入扩展存储过程主要是弥补SQLServer 的不足之处,可以按需要大幅扩展其功能。

3. 请分别写出用企业管理器和T_SQL语句命令创建存储过程的主要步骤。

答:使用企业管理器1. 运行企业管理器,展开数据库STUM,S 在“存储过程”图标上右击,在弹出的快捷菜单中选择“新建存储过程”命令。

2. 在该窗口中首先输入所有者和存储过程名。

3. 输入实现存储过程功能的语句,单击“检查语法”按钮,进行语法检查。

4. 如果没有任何错误,单击“确定”按钮,将存储过程保存到STUMS数据库中。

06数据库原理第八章练习题参考答案

06数据库原理第八章练习题参考答案

实践综合训练之三参考答案思路或参考答案(在MS SQL SERVER中的实现):思路一:使用一个SQL语句完成查询统计,然后在界面显示统计结果。

这样做的条件是能够使用一个SQL语句完成查询统计,否则,不能使用此方法。

该方法的好处是数据不保存节省空间,不会造成访问冲突;缺点是每次都要重新统计一次数据,对服务器性能产生一些影响,尤其是在服务器忙的时候。

该SQL语句可以直接写在应用程序中,也可以写成存储过程在应用程序中调用执行。

本题的一个SQL语句:select zc.kc,zc.yyjb,zcrs,case when bsrs is null then 0 else bsrs end as bsrs,bsrs*100.0/zcrs bsjgl, case when jsrs is null then 0 else jsrs end as jsrs,jsrs*100.0/zcrs jsjgl,case when qbrs is null then 0 else qbrs end as qbrs,qbrs*100.0/zcrs qbjglfrom (select kc,substring(zkzh,1,2) yyjb,count(*) zcrs from ta_kscj where kc='25' and yzkzh is nullgroup by kc,substring(zkzh,1,2)) as zcleft join (select substring(zkzh,1,2) yyjb,count(*) bsrs from ta_kscj where kc='25' and yzkzh is null and bscjdd>0 group by substring(zkzh,1,2)) as bs on(zc.yyjb=bs.yyjb)left join(select substring(zkzh,1,2) yyjb,count(*) jsrs from ta_kscj where kc='25' and yzkzh is null and sjcjdd>0 group by substring(zkzh,1,2)) as js on(zc.yyjb=js.yyjb)left join(select substring(zkzh,1,2) yyjb,count(*) qbrs from ta_kscj where kc='25' and yzkzh is null and zcjdd>0 group by substring(zkzh,1,2)) as qb on(zc.yyjb=qb.yyjb)order by zc.yyjb;可以再与TC_YYJBDM表关联,得出具体的语言级别名称。

(完整版)数据库系统基础教程第八章答案

(完整版)数据库系统基础教程第八章答案

Section 1Exercise 8.1.1a)CREATE VIEW RichExec ASSELECT * FROM MovieExec WHERE netWorth >= 10000000;b)CREATE VIEW StudioPres (name, address, cert#) ASSELECT , MovieExec.address, MovieExec.cert# FROM MovieExec, Studio WHERE MovieExec.cert# = Studio.presC#;c)CREATE VIEW ExecutiveStar (name, address, gender, birthdate, cert#, netWorth) AS SELECT , star.address, star.gender, star.birthdate, exec.cert#, WorthFROM MovieStar star, MovieExec exec WHERE = ANDstar.address = exec.address;Exercise 8.1.2a)SELECT name from ExecutiveStar WHERE gender = ‘f’;b)SELECT from RichExec, StudioPres where = ;c)SELECT from ExecutiveStar, StudioPresWHERE Worth >= 50000000 ANDStudioPres.cert# = RichExec.cert#;Section 2Exercise 8.2.1The views RichExec and StudioPres are updatable; however, the StudioPres view needs to be created with a subquery.CREATE VIEW StudioPres (name, address, cert#) ASSELECT , MovieExec.address, MovieExec.cert# FROM MovieExecWHERE MovieExec.cert# IN (SELECT presCt# from Studio);Exercise 8.2.2a) Yes, the view is updatable.b)CREATE TRIGGER DisneyComedyInsertINSTEAD OF INSERT ON DisneyComediesREFERENCING NEW ROW AS NewRowFOR EACH ROWINSERT INTO Movies(title, year, length, studioName, genre)VALUES(NewRow.title, NewRow.year, NewYear.length, ‘Disney’, ‘comedy’);c)CREATE TRIGGER DisneyComedyUpdateINSTEAD OF UPDATE ON DisneyComediesREFERENCING NEW ROW AS NewRowFOR EACH ROWUPDATE Movies SET length NewRow.lengthWHERE title = NewRow.title AND year = NEWROW.year ANDstudionName = ‘Disney’ AND genre = ‘comedy’;Exercise 8.2.3a) No, the view is not updatable since it is constructed from two different relations.b)CREATE TRIGGER NewPCInsertINSTEAD OF INSERT ON NewPCREFERENCING NEW ROW AS NewRowFOR EACH ROW(INSERT INTO Product VALUES(NewRow.maker, NewRow.model, ‘pc’))(INSERT INTO PC VALUES(NewRow.model, NewRow.speed, NewRow.ram, NewRow.hd, NewRow.price));c)CREATE TRIGGER NewPCUpdateINSTEAD OF UPDATE ON NewPCREFERENCING NEW ROW AS NewRowFOR EACH ROWUPDATE PC SET price = NewPC.price where model = NewPC.model;d)CREATE TRIGGER NewPCDeleteINSTEAD OF DELETE ON NeePCREFERENCING OLD ROW AS OldRowFOR EACH ROW(DELETE FROM Product WHERE model = OldRow.model)(DELETE FROM PC where model = OldRow.model);Section 3Exercise 8.3.1a)CREATE INDEX NameIndex on Studio(name);b)CREATE INDEX AddressIndex on MovieExec(address);c)CREATE INDEX GenreIndex on Movies(genre, length);Section 4Exercise 8.4.1Exercise 8.4.2Q1 = SELECT * FROM Ships WHERE name = n;Q2 = SELECT * FROM Ships WHERE class = c;Q3 = SELECT * FROM Ships WHERE launched = y;I = InsertsIndexesNone Name Class Launched Name & Name & Class & ThreeSection 5Exercise 8.5.1Updates to movies that involves title or yearUPDATE MovieProd SET title = ‘newTitle’ where title=’oldTitle’ AND year = oldYear; UPDATE MovieProd SET year = newYear where title=’oldYitle’ AND year = oldYear;Update to MovieExec involving cert#DELETE FROM MovieProdWHERE (title, year) IN (SELECT title, yearFROM Movies, MovieExecWHERE cert# = oldCert# AND cert# = producerC#);INSERT INTO MovieProdSELECT title, year, nameFROM Movies, MovieExecWHERE cert# = newCert# AND cert# = producerC#;Exercise 8.5.2Insertions, deletions, and updates to the base tables Product and PC would require a modification of the materialized view.Insertions into Product with type equal to ‘pc’:INSERT INTO NewPCSELECT maker, model, speed, ram, hd, price FROM Product, PC WHEREProduct.model = newModel and Product.model = PC.model;Insertions into PC:INSERT INTO NewPCSELECT maker, ‘newModel’, ‘newSpeed’, ‘newRam’, ‘newHd’, ‘newPrice’FROM Product WHERE model = ‘newModel’;Deletions from Product with type equal to ‘pc’:DELETE FROM NewPC WHERE maker = ‘deletedMaker’ AND model=’deletedModel’; Deletions from PC:DELETE FROM NewPC WHERE model = ‘deletedModel’;Updates to PC:Update NewPC SET speed=PC.speed, ram=PC.ram, hd=PC.hd, price=PC.price FROM PC where model=pc.model;Update to the attribute ‘model’ needs to be treated as a delete and an insert. Updates to Product:Any changes to a Product tuple whose type is ‘pc’ need to be treated as a delete or an insert, or both.Exercise 8.5.3Modifications to the base tables that would require a modification to the materialized view: inserts and deletes from Ships, deletes from class, updates to a Class’ displacement. Deletions from Ship:UPDATE ShipStats SETdisplacement=((displacement * count) –(SELECT displacementFROM ClasssesWHERE class = ‘DeletedShipClass’)) / (count – 1),count = count – 1WHEREcountry = (SELECT country FROM C lasses WHERE class=’DeletedShipClass’); Insertions into Ship:Update ShipStat SETdisplacement=((displacement*count) +(SELECT displacement FROM ClassesWHERE class=’InsertedShipClass’)) / (count + 1),count = count + 1WHEREcountry = (SELECT country FROM Classes WHERE classes=’InsertedShipClass); Deletes from Classes:NumRowsDeleted = SELECT count(*) FROM ships WHERE class = ‘DeletedClass’; UPDATE ShipStats SETdisplacement = (displacement * count) - (DeletedClassDisplacement *NumRowsDeleted)) / (count – NumRowsDeleted),count = count – NumRowsDeletedWHERE country = ‘DeletedClassCountry’;Update to a Class’ displacement:N = SELECT count(*) FROM Ships where class = ‘UpdatedClass’;UPDATE ShipsStat SETdisplacement = ((displacement * count) + ((oldDisplacement – newDisplacement) * N))/countWHEREc ountry = ‘UpdatedClassCountry’;Exercise 8.5.4Queries that can be rewritten with the materialized view:Names of stars of movies produced by a certain producerSELECT starNameFROM StarsIn, Movies, MovieExecWHERE movieTitle = title AND movieYear = year AND producerC# = cert# AND name = ‘Max Bialystock’;Movies produced by a certain producerSELECT title, yearFROM Movies, MovieExecWhere produce rC# = cert# AND name = ‘George Lucas’;Names of producers that a certain star has worked withSELECT nameFROM Movies, MovieExec, StarsInWhere producerC#=cert# AND title=movieTitle AND year=movieYear AND starName=’Carrie Fisher’;The number of movies produced by given producerSELECT count(*)FROM Movies, MovieExecWHER E producerC#=cert# AND name = ‘George Lucas‘;Names of producers who also starred in their own moviesSELECT nameFROM Movies, StarsIn, MovieExecWHERE producerC#=cert# AND movieTitle = title AND movieYear = year AND = starName;The number of stars that have starred in movies produced by a certain producer SELECT count(DISTINCT starName)FROM Movies, StarsIn, MovieExecWHERE producerC#=cert# AND movieTitle = title AND movieYear = year AND n ame ‘George Lucas’;The number of movies produced by each producerSELECT name, count(*)FROM Movies, MovieExecWHERE producerC#=cert# GROUP BY name。

第8章习题参考答案

第8章习题参考答案

第8章习题解答1.思考题(1)SQL Server 2008提供了哪些安全管理机制?安全性管理是建立在什么机制上的?答:SQL Server 2008提供了非常完善的安全管理机制,包括用户登录、管理和对用户使用数据库对象的管理。

SQL Server2008的安全性管理是建立在身份验证和访问许可机制上的。

(2)SQL Server 2008有几种身份验证方式?它们的区别是什么?哪种身份验证方式更安全?答:SQL Server 2008有两种身份验证方式,即Windows身份验证模式和混合模式。

Windows 身份验证模式会启用 Windows 身份验证并禁用 SQL Server 身份验证。

混合模式会同时启用 Windows 身份验证和 SQL Server 身份验证。

Windows 身份验证始终可用,并且无法禁用。

SQL Server 2008 的默认身份验证模式是Windows身份验证模式,混合模式更为安全。

(3)数据库的权限是指什么权限?权限管理的主要任务是什么?角色中的所有成员能否继承该角色所拥有的权限?答:SQL Server2008中的权限包括3种类型:对象权限、语句权限和隐含权限。

权限管理的主要任务是对象权限和语句权限的管理。

角色中的所有成员继承该角色所拥有的权限。

(4)SQL Server 2008中有几种角色类型?它们的主要区别是什么?答:SQL Server 2008中有3种角色类型:固定角色、用户定义的数据库角色和应用程序角色。

固定角色:是指其权限已被SQL Server 2008定义,且SQL Server 2008管理者不能对其权限进行修改的角色。

这些固定角色涉及服务器配置管理以及服务器和数据库的权限管理。

按照管理目标对象的不同,固定角色又分为固定服务器角色和固定数据库角色。

用户定义数据库角色:就是当一组用户需要设置的权限不同于固定数据库角色所具有的权限时,为了满足要求而定义的新的数据库角色。

《数据库原理与应用(SQL Server 2005)》第八章数据查询课后答案

《数据库原理与应用(SQL Server 2005)》第八章数据查询课后答案

7、select top 10 productid,productname,unitprice from products
order by unitprice
8、select * from products
select categoryid, count(categoryid) as '产品数量',avg(unitprice) as '平均价格',max(unitprice) as '最高价格'
in(select supplierid from suppliers where country='USA')
17.
select e1.employeeid,stname,e2.ReportsTo from employees as e1 left join employees as e2 on e1.employeeid=e2.ReportsTo
参考答案:
select e2.employeeid,stname from employees as e1 right join employees as e2 on e1.employeeid=e2.ReportsTo
更改后的第十七题的答案:select e1.employeeid, stname ,e1.title,count(e2.reportsto) as '下属个数'
from employees as e1 left join employees as e2 on e1.employeeid=e2.ReportsTo
group by e1.employeeid,stname,e1.title
18.
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
相关文档
最新文档