??SQL Server 2008测验题(A卷) ??考试时间90分钟 ??学号班级
??一、选择题(每题3分,个别题2分, 共40分)
??1) 假定有一个用户表,表中包含字段:userid (int)、username (varchar)、 password(varchar)、等,该表需要设置主键,以下说法正确的是。(选择两项) ??a)如果不能有同时重复的username和password,那么username和password可以组合在一起作为主键。
??b)此表设计主键时,根据选择主键的最小性原则,最好采用userid作为主键。 ??c)此表设计主键时,根据选择主键的最小性原则,最好采用username和password作为组合键。
??d) 如果采用userid作为主键,那么在userid列输入的数值,允许为空。 ??2) 以下()语句从表TABLE_NAME中提取前10条记录。(选择一项) a)select * from TABLE_NAME where rowcount=10 ??b)select TOP 10 * from TABLE_NAME ??c)select TOP of 10 * from TABLE_NAME
??d)select * from TABLE_NAME where rowcount<=10 ??3) 查找 student表中所有电话号码(列名:telephone)的第一位为8或6,第三位为0的电话号码()。(选择一项)
??a)SELECT telephone FROM student WHERE telephone LIKE ?[8,6]%0*? b)SELECT telephone FROM student WHERE telephone LIKE ?(8,6)*0%? c)SELECT telephone FROM student WHERE telephone LIKE ?[8,6]_0%? d)SELECT telephone FROM student WHERE telephone LIKE ?[8,6]_0*?
??4) 现有表Employee,字段:id (int),firstname(varchar), lastname(varchar); 以下sql语句错误的是()。(选择一项) a)select firstname+?.?+lastname as ?name? from employee )
??b)select firstname+?.?+lastname=?name? from employee ??c)select ?name?=firstname+?.?+lastname from employee ??d)select firstname,lastname from employee
??5) 若要删除book表中所有数据,以下语句错误的是()。(选择两项)
??a)truncate table book //对整个数据表中的数据进行删除,没有附带事物这一特性,比delete要快,只能删除单表中的数据 ??b)delete * from book
??c)drop table book //删除整个数据表对象 ??d)delete from book
??6) 现有书目表book,包含字段:price (float); 现在查询一条书价最高的书目的详细信息,以下语句正确的是()。(选择两项) ??a)select top 1 * from book order by price asc ??b)select top 1 * from book order by price desc
??c)select top 1 * from book where price= (select max (price)from book) d)select top 1 * from book where price= max(price) ??
??//聚合函数只能放在select 和from 之间使用
??7) 查询student表中的所有非空email信息, 以下语句正确的是()。(选择一项) a)Select email from student where email !=null
??b)Select email from student where email not is null ??c)Select email from student where email <> null ??d)Select email from student where email is not null
??8) 现有订单表orders,包含用户信息userid, 产品信息 productid, 以下()语句能够返回至少被订购过两回的productid? (选择一项) ??a)select productid from orders where count(productid)>1 ??b)select productid from orders where max(productid)>1
??c)select productid from orders where having count(productid)>1 group by productid_ d)select productid from orders group by productid having count(productid)>1
??9) 使用以下()不可以进行模糊查询。(选择一项)(本题2分) ??a)OR
??b)Not between ??c)Not IN ??d)Like
??10) Sql语句:select * from students where SNO like ?010[ ]%[A,B,C]%?,可能会查询出的SNO是()。(选择两项)(本题2分) ??a)01053090A #Hm3? ??b)01003090A01 ??c)01053090D09 ??d)0101A01
??11) 创建一个名为?Customers?的新表,同时要求新表中包含表?clients?的所有记录,sql语句是()。(选择一项) ??a)Select * into customers from clients ??b)Select into customers from clients
??c)Insert into customers select * from clients ??d)Insert customers select * from clients
??12) 假设订单表orders用来存储订单信息,cid代表客户编号,money代表单次订购额,现要查询每个客户的订购次数和每个客户的订购总金额,下面()sql语句可以返回正确结果。(选择一项)
??a)select cid,count(distinct(cid)),sum(money) from orders group by cid ??b)select cid,count(distinct(cid)),sum(money) from orders order by cid ??c)select cid,count(cid),sum(money) from orders order by cid ??d)select cid,count(cid),sum(money) from orders group by cid ??13) 以下描述不正确的是 ()(本题2分) ??a)存储过程能够实现较快的执行速度。
??b)内嵌表值型函数相当于一个带参数的视图。 ??c)不指定所有者时,调用标量函数会出错。 ??d)可以通过视图更改任意基表
??14) 主索引可确保字段中输入值的()性。(本题2分) ??A.多样 ??B.重复
??
??C.唯一 ??D.若干
??15) Select 职工号 FROM 职工 WHERE 工资>1250 命令的功能是()。(本题2分)
??A.查询工资大于1250的纪录
??B.查询1250号记录后的记录 C.检索所有的职工号 ??D.从[职工]关系中检索工资大于1250的职工号 ??1. 二、判断题:(每小题4分,共20分) ??2. F ??3. T ??4. F ??5. F
??6. T 1. 主键字段允许为空。(f)
??2. SQL Server 自动为primary key约束的列建立一个索引。(t) 3. 数据库的名称一旦建立就不能重命名。(f)
??4. 固定数据库角色:db_datarader 的成员可修改本数据库内表中的数据。(t)f ??5. 验证模式是在安装SQL Server过程中选择的。系统安装之后,可以重新修改SQL
??Server系统的验证模式。(t)
??三、阅读下列程序,说明它们的功能。(每题7分,共20分) ??1.
??use 成绩数据库
??If exists ( select name from sysobjects ??Where name=?student_inf? and type=?p?) ??Drop procedure student_inf ??Go
??Create procedure student_inf as
??Select 学号, 姓名, 总学分 from xsqk ??2. (本题6分)
??use 教学成绩管理数据库 ??go
??alter table 学生信息表 ??add email varchar(20) null, ??学历 text, ??照片 image ??3.
??use 教学成绩管理数据库
??select 教学成绩表.学号,姓名,sum(分数) 总分,avg(分数) 均分 ??from 学生信息表 join 教学成绩表
??on 学生信息表.学号 = 教学成绩表.学号 ??group by 教学成绩表.学号,姓名 ??order by avg(分数) desc ??四、编程题(20分)
??1、问题描述: ??
??已知关系模式:
??S (SNO,SNAME) 学生关系。SNO 为学号,SNAME 为姓名
??C (CNO,CNAME,CTEACHER) 课程关系。CNO 为课程号,CNAME 为课程名,CTEACHER 为任课教师
??SC(SNO,CNO,SCGRADE) 选课关系。SCGRADE 为成绩 ??1. 找出没有选修过“李明”老师讲授课程的所有学生姓名(6分)
??2. 列出有二门以上(含两门)不及格课程的学生姓名及其平均成绩(7分) ??3. 列出既学过“1”号课程,又学过“2”号课程的所有学生姓名(7分) ??SQL Server 2008测验题(A卷) ??考试时间90分钟
??一、选择题(每题2分, 共40分) ??1) AB ??2) B ??3) C ??4) B ??5) BC ??6) BC ??7) D ??8) D ??9) B ??10) AD ??11) A ??12) D ??13) D ?? ??14)C ??15)D
??二、判断题:(每小题4分,共20分) ??1. F ??2. T ??3. F ??4. F ??5. T
??三、阅读下列程序,说明它们的功能。(每题7分,共20分) ??1.
??use 成绩数据库
??If exists ( select name from sysobjects ??Where name=?student_inf? and type=?p?) ??Drop procedure student_inf ??Go
??Create procedure student_info as
??Select 学号, 姓名, 总学分 from xsqk
??
??2. (本题6分)
??use 教学成绩管理数据库 ??go
??alter table 学生信息表 //修改数据表
??add email varchar(20) null, //增加email列 可以为空 ??学历 text, ??照片 image ??3.
??use 教学成绩管理数据库
??select 教学成绩表.学号,姓名,sum(分数) 总分,avg(分数) 均分 ??from 学生信息表 join 教学成绩表
??on 学生信息表.学号 = 教学成绩表.学号 ??group by 教学成绩表.学号,姓名 ??order by avg(分数) desc ??四、编程题(20分) ??1、问题描述: ??已知关系模式:
??S (SNO,SNAME) 学生关系。SNO 为学号,SNAME 为姓名
??C (CNO,CNAME,CTEACHER) 课程关系。CNO 为课程号,CNAME 为课程名,CTEACHER 为任课教师
??SC(SNO,CNO,SCGRADE) 选课关系。SCGRADE 为成绩 ??1. 找出没有选修过“李明”老师讲授课程的所有学生姓名(6分) ??Select SNAME FROM S ??Where NOT EXISTS( ??Select * FROM SC,C ??Where SC.CNO=C.CNO
??AND CTEACHER=?李明? ) ??
??2. 列出有二门以上(含两门)不及格课程的学生姓名及其平均成绩(7分) select sname,ave(scgrade) ??from s,sc
??WHERE s.sno=SC.sno AND SNO IN (select Sno from sc where scgrade<60 ??group by sno
??having count(distinct cno)>=2) ??或者
??select sname,avg_scgrade=avg(scgrade) ??from s,sc,( ??select sno ??from sc
??where scgrade<60 ??group by sno
??having count(distinct cno)>=2
??)a where s.sno=a.sno and sc.sno=a.sno