1)用SQL命令创建指导教师teacher表。 2)用SQL命令在学生信息表中插入一行数据,学号:202201、姓名:刘柳、专业:英语、年龄:20、性别:女。 3)用SQL命令修改科技竞赛表中tzc的数据类型,由char(20)改为datetime。 4)用SQL命令在student中查询所有男生的平均年龄。 5)用SQL命令查询赛题编号为'101’的所有成绩和名次,并将成绩列重命名为“总分”,名次按升序排列。 6)用SQL命令查询所有姓李的男老师的工号和所带学生的编号。 7)用SQL命令查询每个19岁及以上学生参加了比赛的赛题总个数 8)用SQL命令查询成绩在90到100之间的所有学生姓名、专业、指导老师的姓名。 9)用SQL命令在teacher表中删除所有职称为“助教”的教师信息。 10)用SQL命令创建视图userview1,其中包含所有比赛题目和截止日期
时间: 2024-02-27 18:58:02 浏览: 99
实验3:SQL-SERVER数据表管理.docx
1) 创建指导教师teacher表的SQL命令:
```
CREATE TABLE teacher (
teacher_id INT PRIMARY KEY,
teacher_name VARCHAR(20) NOT NULL,
teacher_title VARCHAR(20),
department_name VARCHAR(20)
);
```
2) 在学生信息表中插入一行数据的SQL命令:
```
INSERT INTO student (student_id, student_name, major, age, gender)
VALUES (202201, '刘柳', '英语', 20, '女');
```
3) 修改科技竞赛表中tzc的数据类型的SQL命令:
```
ALTER TABLE competition MODIFY COLUMN tzc DATETIME;
```
4) 查询所有男生的平均年龄的SQL命令:
```
SELECT AVG(age) FROM student WHERE gender='男';
```
5) 查询赛题编号为'101'的所有成绩和名次,并将成绩列重命名为“总分”,名次按升序排列的SQL命令:
```
SELECT grade AS '总分', ranking FROM score WHERE stid='101' ORDER BY ranking ASC;
```
6) 查询所有姓李的男老师的工号和所带学生的编号的SQL命令:
```
SELECT teacher.teacher_id, student.student_id FROM teacher
JOIN course ON teacher.teacher_id = course.teacher_id
JOIN student ON course.student_id = student.student_id
WHERE teacher.teacher_name LIKE '李%' AND student.gender = '男';
```
7) 查询每个19岁及以上学生参加了比赛的赛题总个数的SQL命令:
```
SELECT student.student_id, COUNT(DISTINCT competition.competition_id) AS '比赛总数' FROM student
JOIN score ON student.student_id = score.stid
JOIN competition ON score.competition_id = competition.competition_id
WHERE student.age >= 19
GROUP BY student.student_id;
```
8) 查询成绩在90到100之间的所有学生姓名、专业、指导老师的姓名的SQL命令:
```
SELECT student.student_name, student.major, teacher.teacher_name FROM student
JOIN course ON student.student_id = course.student_id
JOIN teacher ON course.teacher_id = teacher.teacher_id
JOIN score ON student.student_id = score.stid
WHERE score.grade BETWEEN 90 AND 100;
```
9) 在teacher表中删除所有职称为“助教”的教师信息的SQL命令:
```
DELETE FROM teacher WHERE teacher_title='助教';
```
10) 创建视图userview1,其中包含所有比赛题目和截止日期的SQL命令:
```
CREATE VIEW userview1 AS
SELECT competition_name AS '比赛题目', deadline AS '截止日期' FROM competition;
```
阅读全文