SQLserver面试题

题目一、
有两个表:

TableX有三个字段Code、 Name、 Age、 其中Code为主键; 
TableY有三个字段Code、 Class、Score, 其中Code + Class 为主键。两表记录如下: 

Code Name Age Code Class Score 
97001 张三 22 97001 数学 80 
97002 赵四 21 97002 计算机 59 
97003 张飞 20 97003 计算机 60 
97004 李五 22 97004 数学 55 


1、请写出SQL,找出所有姓张的学生,并按年龄从小到大排列; 
 select * from TableX where name like '张%' order by age

2、请写出SQL,取出计算机科考成绩不及格的学生; 
 select * from tableX where code in (select code from tableY WEHRE class='计算机' and score<60)

3、通过等值联接,取出Name、Class、Score,请写出SQL即输出结果 
 select a.name,b.class,b.score from tableX a,tableY b where a.code=b.code  

4、通过外联接,取出每个学生的Name、Class、Score、请写SQL输出结果 
 select a.name,b.class,b.score from tableX full join tableY on a.code=b.code

5、请写SQL,在TableX 表中增加一条学生记录(学号:97005 姓名:赵六 年龄:20);
insert into tablex values('97005','赵六',20) 


6、李五的年龄记录错了,应该是21,请写SQL,根据主键进行更新; 
update tablex set age=21 where code='97004'

7、请写SQL,删除TableX中没有考试成绩的学生记录,请使用not in条件; 
delete tablex where code not in (select code from tabley)
题目二、
有两个表定义如下:
create tableindividual (
firstname   varchar2(20) not null
lastname    vatchar2(20) not null
birthdate   date
gender      varchar2(1) 
initial     number(2)
farorite    varchar2(6)
type        varchar2(8)
);

在此表中建唯一索引 firstname + lastname

create table chile_detail(
firstname   varchar2(20)
lastname    varchar2(20)
cname       varchar2(8)
coment      varchar2(2)
type        varchar2(8)
);


1、写一个简单的SQL语句实现:删除表individual中一条出生日期(brithdate)为 1990年10月2日 出生的人的记录

delete individual to_char(brithdate,'yyyy-mm-dd')='1990-10-02'


2、写一修改语句实现: 将表child_detail 中的type 为 “kkd” 的记录的Cname 值为“declear”,coment的值为“02”

update child_detail set Cname='declear' ,coment='02' where type='kkd'

  • 3
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值