sql数据库基础面试题复习试题考试题_全 下载本文

内容发布更新时间 : 2024/4/20 14:31:47星期一 下面是文章的全部内容请认真阅读。

专业资料

实现的有( )(选择二项)

A、create table student(id int primary key not null) B、create table student(id primary key int not null) C、create table student(id int not null)

Alter table student add constraint 约束名称 primary key (id) D、create table student(id int not null)

add constraint 约束名称 primary key (id)

22、在SQL Server2005中,对userinfo表中列修改错误的是( )(选择一项) A、alter table userinfo add age int not null; B、alter table userinfo drop column age;

C、alter table userinfo update column age decimal(6,2) D、alter table userinfo alter column age decimal(6,2)

23、在SQL Server2005中,要删除表studentInfo错误的是( )(选择一项) A、if exists(select * from sys.sysobjects where [name]=’studentInfo’) Drop table studentInfo go

B、if object_id(‘studentInfo’) is not null Drop table studentInfo go

C、drop table studentInfo D、delete table studentInfo

第三章

6、 在SQL Server 2005中,假设表users包含主键列id,那么执行“Update users SET id=20

WHERE id=30”,执行的结果可能是( )。 (选择一项)

A、 如果表中同时含有id 为20和id 为30的记录,则更新失败

B、 如果表中含有id为30的记录,但不包含id为20的记录,则更新失败 C、 执行出错,因为主键列不可以被更新

D、 如果表中不包含id 为20和id 为30的记录,则更新一行记录

7、 在SQL Server 中创建一个名为Customers的新表,同时要求该表与clients表的表结构相同,但不包括clients表的记录,sql语句是( )。 (选择一项)

E、 Select * into customers from clients where false F、 Select * into customers from clients where 1<>1 G、 Insert into customers select * from clients where false H、 Insert into customers select * from clients where 1<>1

word完美格式

专业资料

3、在SQL Server2005数据库中,使用update语句更新数据库表中的数据,以下说法正确的是( ) (选择一项) A、每次只能更新一行数据 B、每次可以更新多行数据

C、如果没有数据项被更新,将提示错误信息 D、更新数据时,必须带有WHERE条件子句

4、在SQLServer2005数据库中有已经建立关系的学生表和班级表(主表),现在想删除班级表,则以下说法中正确的是( )(选择一项)

A、首先应当删除班级表中的数据,然后再删除班级表 B、可以直接删除班级表

C、首先应当删除学生表中的数据,然后在删除班级表 D、首先应当先删除学生表,然后在删除班级表

5、在SQL Server2005数据库中,删除一个表结构的命令是( )(选择一项) A、DELETE TABLE B、DROP TABLE C、TRUNCATE TABLE D、ALTER TABLE

6、在SQL Server2005数据库中,有student(学生)表,包含字段:SID(学号),SNAME(姓名),Grade(成绩)。现要将所有学员的成绩加10分。下列SQL语句正确的是( )(选择一项)

A、update students set Grade=Grade+10 where SID=1 B、update*set Grade=Grade+10

C、update*from stedents set Grade=Grade+10 D、update students set Grade=Grade+10 7、在SQL Sever 2005中,有student(学生)表,其结构为:sID(学号、int型、主键),sName(姓名、varchar型),birthday(出生日期、varchar型),score(成绩、int型)。现要向学员表中插入一名学员的信息,下列SQL语句正确的是( )(选择一项) A、INSERT INTO students VALUES(1,'李刚','1999-01-01',80)

B、INSERT INTO students (sID,sName,birthday) VALUES(1,'李刚','1999-01-01',80) C、INSERT INTO students VALUES(1,李刚,1999-01-01,80)

D、INSERT INTO students (sID,sName,birthday) VALUES(NULL,'李刚','1999-01-01')

8、在SQL Server 2005中,删除表sample中的所有数据,可以使用如下( )语句。(选择一项)

A、Drop table sample B、delete from sample C、delete*from sample D、drop*from sample

9、在SQL Sever2005数据库中有已经建立关系的学生表和班级表(主表),现在想删除班级表,当前学生表数据不为空,则以下说法中正确的是( )(选择一项) A、首先应当先删除学生表,然后再删除班级表 B、可以直接删除班级表

C、应当首先清除班级表中的数据,然后再删除班级表 D、应当首先清除学生表中的数据,然后再删除班级表

word完美格式

专业资料

10、在SQL Server2005中,假如表ABC中有A、B、C三列,均设为字符数据类型,其中A列的默认值为“VA”。如果能够正确执行语句:INSERT ABC(A,C)VALUES (‘V’,’NULL’),下列的说法正确的是( )(选择二项)

A、插入A列的值为V B、插入A列的值为VA C、插入B列的值为空值 D、插入C列的值为空值

11、在SQL Sever 2005中,有表结构如下。现要向UserInfo表中插入一名用户的信息,下列SQL语句错误的是( )(选择一项) create table UserInfo (

id int primary key identity not null, name varchar(20) not null, age int default 20 not null )

A、insert into UserInfo values(‘admin’,22)

B、insert into UserInfo values(‘admin’,default) C、insert into UserInfo(name) values(‘admin’) D、insert into UserInfo values(1,’admin’,25)

12、在SQL Sever 2005中,有表结构如下。现要向UserInfo表中插入一名用户的信息,下列SQL语句错误的是( )(选择一项) create table UserInfo (

id int primary key identity not null, name varchar(20) not null, age int default 20 not null )

A、insert into UserInfo values(‘admin’,22)

B、insert into UserInfo(name,age) values(‘admin’,default) C、insert into UserInfo(age,name) values(‘admin’,20) D、insert into UserInfo values(’admin’,25)

13、在SQL Server2005数据库中,删除一个User表数据但不删除表结构且标识列还原初始值的命令是( )(选择一项) A、delete from User B、drop table User C、truncate table User D、alter table User

第四章

8、 关于Sql Server的字符串函数,以下说法不正确的是( )。(选择一项)

word完美格式

专业资料

A、 select trim(‘ hello ’) 返回值为: hello (前后都无空格) B、 select ltrim(rtrim(‘ hello ’)) 返回值为: hello (前后都无空格) C、 select replace(‘hello’,’e’,’o’) 返回值为: hollo D、 select right(‘hello’,3) 返回值为: llo

9、 在SQLServer 2005中,查询score表中stuName字段数据。( ) (选择一项)

A、 select * from score

B、 select * from score where stuName=”” C、 select stuName from score

D、 select stuName from score student=””

10、在SQL Server 2005中,假定有studentCourse(学生选修课)表,其结构为:sID(学

号),cID(课程.编号) ,score(成绩).那么列出所有选修课程超过5门的学生学号以及选修课数目的SQL 语句的是()。(选择一项)

a) select sID,count(cID) from studentcourse where count(cID)>5

b) select sID,count(cID) from studentcourse group by sID where count(cID)>5 c) select sID,count(cID) from studentcourse group by sID having count(cID)>5 d) select sID,count(cID) from studentcourse group by cID having count(cID)>5

11、在SQL Server 2005中,现有客户代表customer(主键:客户编号cid),包含10行数据。订单表orders(外键:客户编号cid),包含6行数据。执行sql语句:select * from customers inner join orders on customers.cid=orders.cid 返回5行记录,则执行sql语句:select * from customers inner join orders on customers.cid<>orders.cid将返回( )行记录。(选择一项)

A、 11 B、 55 C、 60 D、 5

12、在SQL Server2005中,有时候需要显示的列名为中文,下列哪项代码具有此功能( )。(选择一项)

A、 select stuName=’学员姓名’ from score B、 select * ‘学员姓名’ from score C、 select stuName ‘学员姓名’ from score D、 以上都不正确

13、取当前时间转换成10位字符串正确的是( )(选择一项)

A、 select convert(getdate())

word完美格式

专业资料

B、 select convert(char(10))

C、 select convert(char(10),getdate()) D、 以上都不正确

14、在SQL Server 2005中,查找student表中所有身份证号码CardNo的前三位为010或

020的记录,以下语句正确的是( )。(选择二项)

A、 select *from student where cardno like ‘010%’or ‘020%’

B、 select *from student where cardno like ‘010%’or cardno like ‘020%’ C、 select *from student where cardno like ‘0(1,2)0%’ D、 select *from student where cardno like ‘0[1,2]0%’

15、在SQL Server 2005中,学生表student中包含字段:学生编号sid (主键),学生姓名sName, 现在查询所有姓名重复的记录,以下语句正确的是( )。(选择一项)

A、 select * from student group by sName where count(sid)>1 B、 select * from student where count(sid)>1

C、 select a.* from student a,student b where a. sname=b.sname

D、 select a.* from student a,student b where a. sname=b.sname and a.sid!=b.sid

9、在SQL Server2005中,有一个product(产品)表,包含字段:pname(产品名称),要从此表中筛选出产品名称为“苹果”或者“香蕉”的纪录,下列语句正确的是( )(选择一项)

A、SELECT * FROM product ON pname=’苹果’ OR pname=’香蕉’ B、SELECT * FROM product ON pname=’苹果’ AND pname=’香蕉’ C、SELECT * FROM product WHERE pname=’苹果’ OR pname=’香蕉’ D、SELECT * FROM product WHERE pname=’苹果’ AND pname=’香蕉’

10、在SQL Server 2005中,要查找eatables 表中item_desc 字段的值以“CHOCO”开头(如CHOCOLATE、CHOCOPIE)的所有记录。下列SQL语句正确的是( )。(选择一项) A、select * from eatables where item_desc LIKE “CHOCO” B、select * from eatables where item_desc =“CHOCO_” C、select * from eatables where item_desc LIKE “CHOCO%” D、select * from eatables where item_desc LIKE “%CHOCO?”

11、在SQL Server2005数据库的聚合函数中,函数( )返回表达式中的平均值. (选择一项)

A、AVG B、SUM C、MIN D、COUNT

12、在SQL Server2005数据库中,有students(学生)表,包含字段:SID(学号),SName(姓名),Grade(成绩).现查找所有学员中成绩最高的前5名学员.下列SQL语句正确的是( ). (选择一项)

word完美格式