S2 测试的错题及解析

来源:互联网 发布:支票打印软件下载 编辑:程序博客网 时间:2024/06/05 05:39
 1.下面T_SQL语句输出的结果是(C)。    print 10+10+'10'+'10'   (选择一项)  A.10101010  B.201010  C.40  D.出错 解析:即使有‘’号,但是里面的值是int类型,T_SQL会进行自动类型转换 2.在SQL Server 中,关于变量描述,不正确的是(C)。(选择一项)  A.变量可分为全局变量和局部变量俩大类 B.全局变量是由系统提供且预先声明,通过在名称前加俩个“@”符号区别于局部变量 C.不能使用SELECT语句给变量赋值 D.可使用DECLARE语句声明局部变量 解析:T_SQL中,对已经定义的变量赋值,分别是SET和SELECT       当表达式返回一个值并对一个变量进行赋值时,推荐是用SET 3.SQL Server 中,有学生表(student表:ID,SName),课程表(Course表:ID,CName)和选课表(Select-course表:ID,SID ,CID)。下面的(A)语句可以查询获得选修了所以课程的学生信息。(选择一项)  A. Select * from student ts where not exists(Select * from Course c where not exists(Select * from select-Course sc where sc.sid=ts.id and sc.cid=c,id));  B.select * from student ts where exists(Select * from Course c where not exists(Select * from select-Course sc where sc.sid=ts.id and sc.cid=c.id));  C.select * from student ts where not exists(Select * from Course c where exists(Select * from select-course sc where sc.sid=ts.id and sc.cid=c.id));  D.select * from student ts where exists(Select * from course c where exists(Select * from select-course sc where sc.sid=ts.id and sc.cid=c.id)) 解析:如果有一门课没有选,则是(1)select * from selec-course sc where sc.student-id=ts.id and sc.course-id=c.id存在null,这说明(2)select * from course c 的查询结果中确实有记录不存在(1查询中),查询结果返回没有选的课程,此时select * from student ts 后的not seists 判断结果为false,不执行查询。4.在SQL Server中,关于变量的使用,不正确的是(B)(选择一项)   A.局部变量是使用时先证明在赋值   B.declare int @age 定义了一个整型变量   C.Select赋值语句一般用于从表中查询数据,然后在赋值给变量   D.Set赋值语句一般用于赋给变量制定的数据常量,变量,表达式  解析:声明局部变量的语法:declare @variabke_name datetype.Delclare @age int 声明了一个整型变量age.5.
解析:子查询一般用在where语句中      子查询可以返回多个结果6.
  解析:SQL Server 中,先按id字段排序,使用MAX()函数查找出第2000条记录的ID,在对比获取比2000记录ID字段值大的前5条记录即为我们需要等待结果。7.
解析:如果题目是一些 那代码是’some’      如果题目是任何 那代码是’any’      如果题目给出的是’所有或全部’,’all’8.
解析:T_SQL中,case语句有两种格式:CaseWhen 条件1 then 结果1When 条件2 then 结果2Endcase 结束位置使用as而不是end关键字9.
解析:子查询的查询结果中可能有多条记录,因此,主查询的where 子句中只能使用in

0 0
原创粉丝点击