免费预览已结束,剩余12页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
一、选择题(1-25没题1分26-30每题2分共35分)1)假定有一个用户表,表中包含字段:userid (int)、username (varchar)、 password(varchar)、等,该表需要设置主键,以下说法正确的是()。(选择两项) a)如果不能有同时重复的username和password,那么username和password可以组合在一起作为主键。 b)此表设计主键时,根据选择主键的最小性原则,最好采用userid作为主键。 c)此表设计主键时,根据选择主键的最小性原则,最好采用username和password作为组合键。 d) 如果采用userid作为主键,那么在userid列输入的数值,允许为空。 2)Microsoft SQL Server 2000 在安装的时候就创建的示例用户数据库包括()。(选择两项) a)Pubs b)Master c)Northwind d)Msdb 3)以下()语句从表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一次性纸杯 b)SELECT * FROM 产品WHERE 价格(SELECT * FROM 产品WHERE 产品名称 一次性纸杯 c)SELECT * FROM 产品WHERE EXISTS 产品名称= 一次性纸杯 d)SELECT * FROM 产品WHERE 价格(SELECT 价格FROM 产品WHERE 产品名称= 一次性纸杯 5)查找 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* 6)现有表book,字段:id (int),title (varchar), price (float); 其中id字段设为标识, 使用insert语句向book表中插入数据,以下语句错误的是()。(选择一项) a)insert into book (id,title,price) values(1,java,100) b)insert into book (title,price) values(java,100) c)insert into book values (java,100) d)insert book values(java,100) 7)现有表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 8)在sql server 2000中,关于数据库说法错误的是()。(选择一项) a)数据库在磁盘上默认的存储位置是:SQL Server安装路径Microsoft SQL ServerMSSQLData b)一个数据库至少应包含一个数据库文件(*.mdf)和一个事务日志文件(*.ldf) c)只有当数据库中不存在数据的情况下,才可以进行数据库的收缩操作。 d)可以通过从A机器拷贝数据库文件和事务日志文件至B机器,然后通过在B机器上执行相应的附加数据库操作,实现数据库从A机器到B机器的复制。9)若要删除book表中所有数据,以下语句错误的是()。(选择两项) a)truncate table book b)delete * from book c)drop table book d)delete from book 10)学生成绩表grade中有字段score(float),现在要把所有在55分至60之间的分数提高5分,以下sql语句正确的是()。(选择两项) a)Update grade set score=score+5 b)Update grade set score=score+5 where score=55 or score =55 and score =6011)现有书目表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)12)现有书目表book,包含字段:价格price (float),类别type(char); 现在查询各个类别的平均价格、类别名称,以下语句正确的是()。(选择一项) a)select avg(price),type from book group by type b)select count(price),type from book group by price c)select avg(price),type from book group by price d)select count (price),type from book group by type 13)查询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 14)成绩表grade中字段score代表分数,以下()语句返回成绩表中的最低分。(选择两项) a)select max(score) from grade b)select top 1 score from grade order by score asc c)Select min(score) from grade d)select top 1 score from grade order by score desc 15)现有订单表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 16)关于聚合函数,以下说法错误的是()。(选择一项) a)Sum返回表达式中所有数的总合,因此只能用于数字类型的列。 b)Avg返回表达式中所有数的平均值,可以用于数字型和日期型的列。 c)Max和Min可以用于字符型的列。 d)Count可以用于字符型的列。17)使用以下()不可以进行模糊查询。(选择一项) a)OR b)Not between c)Not IN d)Like18)关于多表联接查询,以下()描述是错误的。(选择一项) a)外联接查询返回的结果集行数可能大于所有符合联接条件的结果集行数。 b)多表联接查询必须使用到JOIN关键字 c)内联接查询返回的结果是:所有符合联接条件的数据。 d)在where子句中指定联接条件可以实现内联接查询。19)Sql语句:select * from students where SNO like 0100%A,B,C%,可能会查询出的SNO是()。(选择两项) a)01053090A #Hm3? b)01003090A01 c)01053090D09 d)0101A0120)关于Truncate table, 以下()描述是错误的。(选择两项) a)Truncate table 可跟Where从句,根据条件进行删除。 b)Truncate table 用来删除表中所有数据。 c)触发器对Truncate table无效。 d)delete 比Truncate table速度快。 21)创建一个名为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 clients22)关于主键,以下()说法是错误的。(选择两项) a)主键可以用来确保表中不存在重复的数据行。 b)一个表必须有一个主键。 c)一个表只能有一个主键。 d)只能对整数型列设置主键。23)假设订单表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 24)现有客户表customers(主键:客户编号cid),包含10行数据,订单表orders(外键:客户编号cid),包含6条数据。执行sql语句:select * from customers right outer join orders on customers.cid=orders.cid。最多返回()条记录。(选择一项) a)10 b)6 c)4 d)0 25)以下描述不正确的是 a)存储过程能够实现较快的执行速度。 b)内嵌表值型函数相当于一个带参数的视图。 c)不指定所有者时,调用标量函数会出错。 d)可以通过视图更改任意基表26)Your database stores telephone numbers. Each telephone number is stored as an integer. You must format the telephone number to print on a report in the following format:(999) 999-9999You have selected the phone number into a local variable as follows:DECLARE PhoneNumber int Which statement will correctly format the number? a)SELECT Phone Number = ( + SUBSTRING(CONVERT(varchar(10), PhoneNumber),3,0) + ) + SUBSTRING(CONVERT(varchar(10), PhoneNurnber),3,3)+ - + SUBSTRING(CONVERT(varchar(10), PhoneNumber),4,6) b)SELECT Phone Number = ( + SUBSTRING(CONVERT(varchar(10),PhoneNuwber),3,1) + ) + SUBSTRING(CONVERT(varcher(10), PhoneNumber),3,4)+ - + SUBSTRING(CONVERT(varchar(10), PhoneMumber),4,7) c)SELECT Phone Number = ( + SUBSTRING(CONVERT(varchar(10), PhoneNumber),0,3) + ) + SUBSTRING(CONVERT(varchar(10), PhoneNumber),3,3)+ - + SUBSTRING(CONVERT(varchar(10), PhoneNurtiber),6,4) d)SELECT Phone Number = ( + SUBSTRING(CONVERT(varchar(10), PhoneNumber),1,3) + ) + SUBSTRING(CONVERT(varchar(10), PhoneNumber),4,3)+ - + SUBSTRING(CONVERT(varchar(10), PhoneNumber),7,4)27)You are a database developer for Wide World Importers. You are creating a database that will store order information. Orders will be entered in a client/server application. Each time a new order is entered, a unique order number must be assigned. Order numbers must be assigned in ascending order. An average of 10,000 orders will be entered each day. You create a new table named Orders and add an OrderNumber column to this table. What should you do next? a)Set the data type of the column to UniqueIdentifier. b)Set the data type of the column to int, and set the IDENTITY property for the column. c)Set the data type of the column to int. Create a user-defined function that selects the maximum order number in the table. d)Set the data type of the column to int. Create a NextKey table, and add a NextOrder column to the table. Set the data type of the NextOrder column to int. Create a stored procedure to retrieve and update the value held in the NextKey.28)You are creating a script that will execute this stored procedure. If the stored procedure executes successfully, it should report the year-to-date sales for the book title. If the stored procedure fails to execute, it should report the following message:“No Sales Found”How should you create the script? a)DECLARE retval int DECLARE ytd int EXEC get_sales_for_title Net Etiquette, ytd IF retval 0 PRINT No sales found ELSE PRINT Year to date sales: + STR (ytd) GO b)DECLARE retval int DECLARE ytd int EXEC get_sales_for_title Net Etiquette, ytd OUTPUT IF retval 0 PRINT No sales found ELSE PRINT Year to date sales: + STR (ytd) GO c)DECLARE retval int DECLARE ytd int EXEC get_sales_for_title Net Etiquette,retval OUTPUT IF retval 0 PRINT No sales found ELSE PRINT Year to date sales: + STR (ytd) GO d)DECLARE retval int DECLARE ytd int EXEC retval = get_sales_for_title Net Etiquette, ytd OUTPUT IF retval 0 PRINT No sales found ELSE PRINT Year to date sales: + STR (ytd) GO29)You are a database developer for an insurance company. Information about the companys insurance policies is stored in a SQL Server 2000 database. You create a table named policy for this database by using the script shown below:CREATE TABLE Policy(PolicyNumber int NOT NULL DEFAULT (0),InsuredLastName CHAR (30) NOT NULL,InsuredFirstName CHAR (20) NOT NULL,InsuredBirthDate dattime NOT NULL,PolicyDate datetime NOT NULL,FaceAmount money NOT NULL,CONSTRAINT PK_Policy PRIMARY KEY (PolicyNumber)Each time the company sells a new policy, the policy must be assigned a unique policy number. The database must assign a new policy number when a new policy is entered. What should you do? a)Create an INSTEAD OF INSERT trigger to generate a new policy number, and include the policy number in the data instead into the table. b)Create an INSTEAD OF UPDATE trigger to generate a new policy number, and include the policy number in the data inserted into the table. c)Create an AFTER UPDATE trigger to generate a new policy number, and include the policy number in the data inserted into the table. d)Replace the DEFAULT constraint with a AFTER INSERT trigger that generates a new policy number and includes the policy number in the data inserted into the table. 30)You are a database developer for a marketing firm. You have designed a quarterly sales view. This view joins several tables and calculates aggregate information. You create aview. You want to provide a parameterised query to access the data contained in your view. The output will be used in other SELECT lists. How should you accomplish this goal? a)Use an ALTER VIEW statement to add the parameter value to the view definition. b)Create a stored procedure that accepts the parameter as input and returns a rowset with the result set. c)Create a scalar user-defined function that accepts the parameter as input. d)Create an inline user-defined function that accepts the parameter as input.二、填空题(每空一分共25分)1、关系R是1NF,当且仅当所有的基础域仅包含_。2、主关键字应该具有_性,_性,_性。3、关系R是3NF,当且仅当R是2NF,并且所有非PK属性都是_于PK。4、Transact-SQL 语言包含_语言,_语言,_语言。5、消除列重复的关键字是_,使用_操作符从多个查询中创建单结果集,提交一个事务的语句为_ 。6、SQLServer的两种授权模式分别为_和_。7、有一个数据表其一行有5KB,有10000行数据,那么我们至少需要_M的数据库空间。8、数据完整性分为_,_,_.9、每个允许有_个簇索引,_索引是SQLServer默认选择。10、可以使用_关键字显示未加密存储过程信息,执行存储过程的关键字是_,统计列平均值的聚合函数为_,修改对象的关键字为_,删除对象的关键字为_。11、_数据库保存所有的临时表和临时存储过程。三、简答题(15分)1、请简述一下第二范式(3分)2、请简述UPDATE 触发器工作原理(3分)3、强制引用完整性时,简述SQL Server 禁止用户进行的操作(3分)4、简述相关子查询的步骤(3分)5、简述使用索引和不使用索引的理由(3分)上机题(25分)一、(12分)问题描述:已知关系模式:S (SNO,SNAME) 学生关系。SNO 为学号,SNAME 为姓名C (CNO,CNAME,CTEACHER)课程关系。CNO 为课程号,CNAME 为课程名,CTEACHER 为任课教师SC(SNO,CNO,SCGRADE) 选课关系。SCGRADE 为成绩1. 找出没有选修过“李明”老师讲授课程的所有学生姓名(4分)2. 列出有二门以上(含两门)不及格课程的学生姓名及其平均成绩(4分)3. 列出既学过“1”号课程,又学过“2”号课程的所有学生姓名(4分)二、定义一个十进制转换成2进制的标量函数。(4分)三、活期存款中,“储户”通过“存取款单”和“储蓄所”发生联系。假定储户包括:账号,姓名,电话,地址,存款额;“储蓄所”包括:储蓄所编号,名称,电话,地址(假定一个储户可以在不同得储蓄所存取款)1、写出设计以上表格的语句(4分)2、创建一个触发器TR1完成下面内容:当向“存取款单”表中插入数据时,如果存取标志则应该更改储户表让存款额加上存取金额,如果存取标志0则应该更改储户表让存款额减去存取金额,如果余额不足显示余额不足错误。(5分)答案:上一、填空题1)a,b 2)a,c 3)b 4)d 5)c 6)a 7)b 8)c 9)b,c 10)c,d 11)b,c 12)a 13)d 14)c,d 15)d 16)b 17)d 18)b 19)a,d 20)a,d 21)a 22)a,c 23)d 24)b 25)d 26)d 27)b 28)d 29)a 30)d二、填空题1、原子值2、稳定性,最简性,熟悉性3、非传递地依赖4、数据定义,数据控制,数据操纵5、distinct,UNION,COMMIT TRANSACTION 6、NT only验证模式,混合模式7、808、域完整性,实体完整性,参考完整性9、一,非簇10、sp_help,EXEC,AVG,ALTER,DROP11、tempdb 下一、准备数据create table s(sno int,sName varchar(100)create table c(cno int,cName varchar(100),CTEACHER varchar(100)create table sc(sno int,cno int,scGrade int)insert into svalues(1,lfm1)insert into svalues(2,lfm2)insert into svalues(3,lfm3)insert into svalues(4,lfm4)insert into svalues(5,lfm5)insert into svalues(6,lfm6)insert into cvalues(1,ch1,李明)insert into cvalues(2,ch2,王刚)insert into cvalues(3,ch3,ll)insert into cvalues(4,ch4,ff)insert into cvalues(5,ch5,ffd)insert into cvalues(6,ch6,se)insert into cvalues(7,ch7,s)insert into scvalues(1,2,80)insert into scvalues(2,2,50)insert into scvalues(1,1,60)insert into scvalues(1,3,90)insert into scvalues(3,2,55)insert into scvalues(1,6,77)insert into scvalues(3,4,80)insert into scvalues(4,2,70)1. 找出没有选修过“李明”老师讲授课程的所有学生姓名-实现代码:SELECT SNAME FROM SWHERE NOT EXISTS( SELECT * FROM SC,C WHERE SC.CNO=C.CNO AND CNAME=李明 AND SC.SNO=S.SNO) select sname from swhere sno not in(select s.sno from sinner join scon sc.sno=s.snoinner join con o=owhere cteacher=李明)2. 列出有二门以上(含两门)不及格课程的学生姓名及其平均成绩-实现代码:SELECT S.SNO,S.SNAME,AVG_SCGRADE=AVG(SC.SCGRADE)FROM S,SC,( SELECT SNO FROM SC WHERE SCGRADE=2)A WHERE S.SNO=A.SNO AND SC.SNO=A.SNOGROUP BY S.SNO,S.SNAMEselect s.sno,avg(scGrade) from s,scwhere s.sno in(select sc.sno from scinner join con o=owheresc.scGrade=2) and s.sno=sc.snogroup by s.sno3. 列出既学过“1”号课程,又学过“2”号课程的所有学生姓名-实现代码:SELECT S.SNO,S.SNAMEFROM S,( SELECT SC.SNO FROM SC,C WHERE SC.CNO=C.CNO AND C.CNO IN(1,2) GROUP BY SNO HAVING COUNT(DISTINCT c.CNO)=2)SC WHERE S.SNO=SC.SNO select S.SNO,S.SNAME from sc,swhere cno=1 and sc.sno in(select sno from sc where cno=2) and s.sno=sc.sno二、create function convert2( num int)returns varchar(100)asbegindeclare re varchar(100)set re=while num0select re=substring(01,num%2+1,1)+re ,num=num/2return reendselect dbo.convert2(8)三、1、CREATE TABLE 储户(账号 INT PRIMARY KEY ,姓名 CHAR(10),电话 INT ,地址 CHAR(10),存款额MONEY)GOCREATE TABLE 储蓄所(储蓄所编号 INT PRIMARY KEY,名称 CHAR(10),电话 INT,地址 CHAR(10)GOCREATE TABLE 存取款单(账号 INT NOT NULL,储蓄所编号 INT NOT NULL,存取日期 DATETIME NOT NULL,存取标志 INT NOT NULL,存取金额 MONEY)GO2、CREATE TRIGGER TR1ON 存取款单FOR INSERTASDECLARE BZ INT,MONEY MONEY,ZH INTSELECT BZ=存取标志,MONEY=存取金额,ZH=账号FROM INSERTEDIF BZ=0 BEGINUPDATE 储户SET 存款额=存款额-MONEYWHERE 账号=ZHdeclare sy moneyselect sy=存款额 from 储户WHERE 账号=ZHif sy0begin raiserror (余额不足,16,1)rollbackendENDIF BZ=1BEGINUPDATE 储户SET 存款额=存款额+MONEYWHERE 账号=ZHEND只看该作者 引用 回复 报告 liyihongcug 高级会员 精华贴数 1 个人空间 0技术积分 11193 (135)社区积分 1052 (1182)注册日期 2004-7-15论坛徽章:10#5使用道具发表于 2007-12-7
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 初中二年级上学期第十五课篮球传接球(击地)备课教案
- 口腔科牙周炎护理培训计划
- 老年人消化系统
- 肺动脉高压患者的长期管理指南
- 老年人营销特点
- 康复医学科创伤后康复治疗要点
- 眼科青光眼药物治疗护理指南
- 眼科近视眼防控管理指南
- 我国食品安全法课件
- 吉林省吉林市第一中学2026届高二物理第一学期期末检测试题含解析
- 家庭服务业劳务品牌技能大赛 《整理收纳》项目理论复习题库(参考100题)
- GJB9001C-2017国军标整套体系文件汇编(质量手册+程序文件+表单)
- 进入有限空间作业工作票
- GB/T 29790-2020即时检验质量和能力的要求
- 最新部编版人教版一年级语文上册《江南》优质教学课件
- 艰苦边远地区范围和类别表
- 高考作文指导:理顺说理逻辑增强议论文生命力 课件(47张PPT)
- 《普通高中英语课程标准版》
- 国家开放大学人文英语4 unit1~8边学边练答案完整版
- 直流充电桩出厂检验报告
- 风电项目开发流程
评论
0/150
提交评论