(1) 掌握DBMS的数据定义功能
(2) 掌握SQL语言的数据定义语句
(3) 掌握RDBMS的数据单表查询功能
(4) 掌握SQL语言的数据单表查询语句
(1) 创建、删除表
(2) 查看、修改表的定义
(3) 理解索引的特点
(4) 创建和删除索引
(5)SELECT语句的基本用法
(6)使用WHERE子句进行有条件的查询
(7)使用IN,NOT IN,BETWEEN AND等谓词查询
(8)利用LIKE子句实现模糊查询
(9)利用ORDER BY子句为结果排序
(10)用SQL Server的聚集函数进行统计计算
(11)用GR0UP BY子句实现分组查询的方法
(1) 熟练掌握SQL的数据定义语句CREATE、ALTER、DROP
(2) 熟练掌握SQL的数据查询语句SELECT
设有一个学生-课程数据库,包括学生关系Student、课程关系Course和选修关系SC:
学生表:Student(Sno,Sname,Ssex,Sage,Sdept)
课程表:Course(Cno,Cname,Cpno,Ccredit)
学生选课表:SC(Sno,Cno,Grade)
(1) 用查询分析器创建、删除表
(2) 查看、修改表的定义
(3) 创建和删除索引
(4) 删除表
利用SQL Server集成管理器(简称SSMS)交互式创建数据库S_T2;
(6)将S_T设为当前数据库
(7)创建3个表
(8)在3个表中添加示例数据(任选一种数据添加方法)
表Student
| Sno | 姓名 |
Sname | 性别
Ssex 年龄
Sage 所在系
Sdept
200215121 李勇 男 20 CS
200215122 刘晨 女 19 CS
200215123 王敏 女 18 MA
200215125 张立 男 19 IS
表Course
课程号
Cno 课程名
Cname 现行课
Cpno 学分
Ccredit
1 数据库 5 4
2 数学 2
3 信息系统 5 4
4 操作系统 6 3
5 数据结构 7 4
6 数据处理 2
7 PASCAL语言 6 4
表SC
学号
Sno 课程号
Cno 成绩
Grade
200215121 1 92
200215121 2 85
200215121 3 88
200215122 2 90
200215122 3 80
(9) 对学生关系Student、课程关系Course和选修关系SC进行查询。
Create Database S_T1;
CREATE TABLE Student
(Sno CHAR(9) NOT NULL UNIQUE,
Sname CHAR(20) UNIQUE,
Ssex CHAR(1),
Sage INT,
Sdept CHAR(15))
create table Course
(Cno CHAR(4) PRIMARY KEY,
Cname CHAR(40),
Cpno CHAR(4),
Ccredit SMALLINT,
FOREIGN KEY (Cpno) REFERENCES Course(Cno)
);
CREATE TABLE SC(
Sno CHAR(9),
Cno CHAR(3),
Grade int,
Primary key (Sno, Cno));
DROP TABLE Student;
ALTER TABLE Student ADD Scome DATETIME;
ALTER TABLE Student modify COLUMN Sage SMALLINT;
CREATE UNIQUE INDEX Stusno ON Student(Sno);
CREATE UNIQUE INDEX Coucno ON Course(Cno);
CREATE UNIQUE INDEX SCno ON SC(Sno ASC,Cno DESC);
DROP INDEX Stusno ON Student;
use S_T2;
create table Student
(Sno CHAR(9) PRIMARY KEY,
Sname CHAR(20) UNIQUE,
Ssex CHAR(2),
Sage SMALLINT,
Sdept CHAR(20)
);
/*表Student的主码为Sno,属性列Sname取唯一值*/
create table Course
(Cno CHAR(4) PRIMARY KEY,
Cname CHAR(40),
Cpno CHAR(4),
Ccredit SMALLINT,
FOREIGN KEY (Cpno) REFERENCES Course(Cno)
);
/*表Course的主码为Cno,属性列Cpno(先修课)为外码,被参照表为Course,被参照列是Cno*/
create table SC
(Sno CHAR(9),
Cno CHAR(4),
Grade SMALLINT,
primary key (Sno, Cno),
FOREIGN KEY (Sno) REFERENCES Student(Sno),
FOREIGN KEY (Cno) REFERENCES Course(Cno)
);
use S_T;/*将S_T设为当前数据库*/
insert into student values(‘200215121’,’李勇’,'男',20,'CS');
insert into student values(‘200215122’,'刘晨','女',19,'CS');
insert into student values(‘200215123’,'王敏','女',18,'MA');
insert into student values(‘200215125’,'张立','男',19,’IS’);
go
/*为表Student添加数据*/
insert into course values('1', '数据库', NULL,4);
insert into course values('2', '数学', NULL,2);
insert into course values('3', '信息系统', NULL,4);
insert into course values('4', '操作系统', NULL,3);
insert into course values('5', '数据结构', NULL,4);
insert into course values('6', '数据处理', NULL, 2);
insert into course values('7', 'java', NULL,4);
go
update Course set Cpno = '5' where Cno = '1';
update Course set Cpno = '1' where Cno = '3';
update Course set Cpno = '6' where Cno = '4';
update Course set Cpno = '7' where Cno = '5';
update Course set Cpno = '6' where Cno = '7';
/*为表Course添加数据*/
go
insert into SC values('200215121', '1',92);
insert into SC values('200215121', '2',85);
insert into SC values('200215121', '3',88);
insert into SC values('200215122', '2',90);
insert into SC values('200215122', '3',80);
insert into SC values('200215123','2',92);
SELECT Sno,Sname,Ssex,Sage,Sdept
FROM Student;
SELECT Student.Sno, student.Sname
FROM Student, SC
WHERE Student.Sno = SC.Sno AND SC.Cno= '2' AND SC.Grade > 90
SELECT Sname,Ssex
FROM Student
WHERE Sdept IN ( 'IS','MA','CS' )
SELECT Sname,Sdept,Sage
FROM Student
WHERE Sage BETWEEN 20 AND 23
SELECT Sname,Sno,Ssex
FROM Student
WHERE Sname LIKE '刘%'
SELECT Sno,Grade
FROM SC
WHERE Cno= '3'
ORDER BY Grade DESC
SELECT AVG(Grade)
FROM SC
WHERE Cno= '1' SELECT Sno
FROM SC
GROUP BY Sno
HAVING COUNT(*) >3