高分求够数据库高手来啊 几个查询语句

来源:百度知道 编辑:UC知道 时间:2024/05/17 22:03:56
1、
(1)、在school数据库上创建表“student”与表“score”(要求使用SQL语句完成)
表的结构如下:
 学生student(学号sid,姓名sname,性别sex,系名department_name,年龄age)
PK=学号
 成绩score(学号sid,课程号cid,成绩mark)
PK=<学号,课程号>
其中:学号sid(整数),姓名sname(长度为20的字符串),性别sex(长度为5的字符串),系名department_name(长度为20的字符串),年龄age(整数),课程号cid(整数),成绩mark(整数)
(2)、添加记录:使用INSERT分别向表“student”和表“score”中各添加三条记录(记录具体内容由考生自己定义);

(3)、将表“score”中”cid”为3的课程的成绩*60%;

(4)、为学号(sid=12)的学生创建一个视图score_view,包括“sid”、“sex”、“sname”、“department_name”;

(5)、查询视图中所有性别为”女”的学生的姓名“sname”和所在系“department_name”;

(6)、删除表“student”和“score”。

-----(1)------------------------------
use school
go
create table student (
sid int not null,
sname varchar(20) not null,
sex varchar(5) not null,
department_name varchar(20) not null,
age int null default 0,
constraint pk_student primary key (sid)
)
go
create table score (
sid int not null,
cid int not null,
mark int not null,
constraint pk_score primary key (sid, cid)
)
go
-----(2)-----------------------------
insert into student values(1, '蛋头', '男', '炮灰系', 21)
insert into student values(2, '阿炮', '男', '冒险系', 22)
insert into student values(3, '龟毛', '男', '极地系', 19)
insert into score values(3, 5, 89)
insert into score values(3, 6, 58)
insert into score values(2, 5, 60)
go
-----(3)------------------------------
update score set mark = ma