(1) 掌握DBMS的数据查询功能
(2) 掌握SQL语言的数据更新功能
(1) update 语句用于对表进行更新
(2) delete 语句用于对表进行删除
(3) insert 语句用于对表进行插入
(1) 熟练掌握SQL的数据更新语句INSERT、UPDATE、DELETE
(2) 写出实验报告
认真阅读S_T.sql,理解其中插入和修改语句的作用和用法;执行S_T.sql,建立示例数据库S_T
对学生关系Student、课程关系Course和选修关系SC进行数据插入、修改和删除元组(记录)的更新操作
S_T.sql即下述代码
在前文中也出现过
create database S_T;
go
use S_T; /*将S_T设为当前数据库*/
create table Student
(Sno CHAR(9) PRIMARY KEY,
Sname CHAR(20) UNIQUE,
Ssex CHAR(2),
Sage SMALLINT,
Sdept CHAR(20)
);
go
/*表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)
);
go
/*表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)
);
go
/*表SC的主码为(Sno, Cno), Sno和Cno均为外码,被参照表分别为Student和Course,被参照列分别为Student.Sno和Course.Cno*/
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', 'PASCAL语言', 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);
/*为表SC添加数据*/
go
因为某些原因,导致这期只有图片,不过好处是更直观的看到代码的效果
删除表中数据后,该表的定义未被删除
这就是关于sql的简单的增删改查也就是数据更新的内容了