create table TableX--code为主键
(
code varchar(50) primary key,
name varchar(50),
age int
)
create table TableY--code+class为主键
(
code varchar(50),
class varchar(50),
score int,
CONSTRAINT [PK_TableY] PRIMARY KEY
(
[code],[class]
)
ON [PRIMARY]
)
insert into TableX values('97001','张三',22)
insert into TableX values('97002','赵四',21)
insert into TableX values('97003','张飞',20)
insert into TableX values('97004','李五',22)
insert into TableY values('97001','数学',90)
insert into TableY values('97002','计算机',59)
insert into TableY values('97003','计算机',60)
insert into TableY values('97004','数学',90)
1、请写出SQL,找出所有姓张的学生,并按年龄从小到大排列;
select * from TableX where name like'张%' order by age
2、请写出SQL,取出计算机科考成绩不及格的学生;
select * from TableX where code in(select code from TableY where class='计算机' and Score<60)
3、通过等值联接,取出Name、Class、Score,请写出SQL即输出结果
4、通过外联接,取出每个学生的Name、Class、Score、请写SQL输出结果
5、请写SQL,在TableX 表中增加一条学生记录(学号:97005 姓名:赵六 年龄:20);
6、李五的年龄记录错了,应该是21,请写SQL,根据主键进行更新;
7、请写SQL,删除TableX中没有考试成绩的学生记录,请使用not in条件;