SQL习题(附答案)

发布时间 : 星期一 文章SQL习题(附答案)更新完毕开始阅读

go (5)

alter table 借阅

add constraint fk_借阅_学生foreign key (学号) references 学生(学号) go (7)

alter table 学生drop constraint df_学生_民族 go

alter table 借阅drop constraint df_借书日期 go (8)

create rule phone_rule as

@ph_rl like '0551-2159[0-9][0-9][0-9]' Go (9)

exec sp_bindrule 'phone_rule','出版社.电话' go (10)

exec sp_addtype 编号,'varchar(20)','not null' 习题六 一、选择题

1-5. CCBAB 6-10.CBDBB 11-15.BBBDB 16-20. BCCCA 21-25ADDCC 26-30 CDCBC 二、填空题

1.update 2.where 3.[-] 4.union 5.交叉连接6.into 7.group by 8.revoke 9.order by

10.group by 11.and 12. where 13. 相关子查询14. 交叉连接15. all 16. with rollup 17. distinct

18. from 子句19. 嵌套查询20. truncate table 21.数据转转与转移 三、实践题 1.

select a.姓名,a.出生日期,b.姓名,b.出生日期from 学生a,学生b where a.出生日

期=b.出生日期and a.学号!=b.学号 2.

select 学号,'高考投档成绩',总分from 学生 3.

select distinct(籍贯) from 学生 4.

select avg(总分) from 学生group by 性别 5.

select * from 学生where 籍贯='安徽'

6.

select * from 学生where 性别='女'

and 出生日期=(select max(出生日期) from 学生where 性别='女') go

select * from 学生where 性别='男'

and 出生日期=(select max(出生日期) from 学生where 性别='男') 7.

select* from 学生order by 总分desc 8.

select 学生.学号,姓名,性别,课程号,成绩from 学生,选修 where 学生.学号=选修.学号and 成绩>85 9.

select 姓名,'学生'as 身份from 学生where 性别='男' union

select 姓名,'教师'as 身份from 教师where 性别='男' 10.

select * from 学生where 出生日期between '1990-1-1' and '1991-1-1' 11.

select top 5 * into course from 课程 12.

select 籍贯,count(*) from 学生group by 籍贯 13.

select 学号,姓名,籍贯from 学生where 籍贯='安徽' compute count(籍贯) 14.

select 学号,姓名,籍贯from 学生where 籍贯='安徽' order by left(学号,6) compute count(籍贯) by left(学号,6) 或

select 学号,姓名,籍贯from 学生where 籍贯='安徽' go

select left(学号,6),count(*) from 学生where 籍贯='安徽' group by left(学号,6) 15.

select * from 学生a where 出生日期>=(

select max(出生日期) from 学生b where a.性别=b.性别) 16.

select * from 选修a where 成绩>(

select avg(成绩) from 选修b where a.学号=b.学号) 17.

select * from 选修where 成绩>(select avg(成绩) from 选修) 略 习题七 一、填空题

1.全局变量2.注释语句3.select 语句4.单引号5.表达式6.break 7. 8. max() 9. waitfor 10.end 11. syscomments 12. ‘ab’ 13. 14. T-SQL 15. GO 16. 批

处理

17. Unicode 18. 内嵌表值19. smalldatetime 20. smallmoney 二、选择题

1-5DCDA 6-10DCDBD 11-15 ACBDB 16-20. BDBAB 21-25 DCCBC__

联系合同范文客服:xxxxx#qq.com(#替换为@)