实验一:数据定义/数据操纵语言
[ 实验日期 ] 年 月 日
[ 实验目的 ]
通过实验熟悉ORACLE上机环境;熟练掌握和使用DDL语言,建立、修改和删除数据库表;熟练掌握和使用DML语言,对数据进行增加、修改和删除操作。
[ 实验内容 ]
(1)(建立数据库表) 建立教学数据库的四个数据库表,并按要求创建完整性约束。
–1.学生情况表
CREATE TABLE Student
(SNO CHAR(5) PRIMARY KEY,
SNAME VARCHAR2(12) NOT NULL,
SDEPT CHAR(2) NOT NULL,
SCLASS CHAR(2) NOT NULL,
SSEX CHAR(3),
SAGE NUMBER(2)
);
INSERT INTO STUDENT VALUES('96001','马小燕','CS','01','女',21);
INSERT INTO STUDENT VALUES('96002','黎明','CS','01','男',18);
INSERT INTO STUDENT VALUES('96003','刘东明','MA','01','男',18);
INSERT INTO STUDENT VALUES('96004','赵志勇','IS','02','男',20);
INSERT INTO STUDENT VALUES('97001','马蓉','MA','02','女',19);
INSERT INTO STUDENT VALUES('97002','李成功','CS','01','男',20);
INSERT INTO STUDENT VALUES('97003','黎明','IS','03','女',19);
INSERT INTO STUDENT VALUES('97004','李丽','CS','02','女',19);
INSERT INTO STUDENT VALUES('97005','司马志明','CS','02','男',18);
–2.课程名称表
CREATE TABLE Course (
CNO CHAR(3)PRIMARY KEY,
CNAME VARCHAR2(20),
CTIME NUMBER(3)
);
INSERT INTO Course VALUES ('001','数学分析',144);
INSERT INTO Course VALUES ('002','普通物理',144);
INSERT INTO Course VALUES ('003','微机原理',80);
INSERT INTO Course VALUES ('004','数据结构',72);
INSERT INTO Course VALUES ('005','操作系统',80);
INSERT INTO Course VALUES ('006','数据库原理',80);
INSERT INTO Course VALUES ('007','编译原理',60);
INSERT INTO Course VALUES ('008','程序设计',40);
–3.教师授课表
CREATE TABLE Teach
(TNAME VARCHAR2(12),
TSEX CHAR(3),
CNO CHAR(3),
TDATE DATE,
TDEPT CHAR(2),
PRIMARY KEY(TNAME,CNO,TDEPT),
CONSTRAINT FK_CNO FOREIGN KEY(CNO) REFERENCES Course(CNO)
);
INSERT INTO Teach VALUES('王成刚','男','004','1999.9.5','CS');
INSERT INTO Teach VALUES('李正科','男','003','1999.9.5','CS');
INSERT INTO Teach VALUES('严敏','女','001','1999.6.8','MA');
INSERT INTO Teach VALUES('赵高','男','004','1999.3.12','IS');
INSERT INTO Teach VALUES('李正科','男','003','2000.2.23','MA');
INSERT INTO Teach VALUES('刘玉兰','女','006','2000.2.23','CS');
INSERT INTO Teach VALUES('王成刚','男','004','2000.3.3.','IS');
INSERT INTO Teach VALUES('马跃','女','008','2000.6.9','CS');
–4.成绩表
CREATE TABLE Score(
SNO CHAR(5),
CNO CHAR(3),
SCORE NUMBER(4,1),
PRIMARY KEY(SNO,CNO),
CONSTRAINT FK_SNO FOREIGN KEY(SNO) REFERENCES Student(SNO),
CONSTRAINT FK_CNO2 FOREIGN KEY(CNO) REFERENCES Course(CNO)
);
INSERT INTO Score VALUES('96001','001',77.5);
INSERT INTO Score VALUES('96001','003',89);
INSERT INTO Score VALUES('96001','004',86);
INSERT INTO Score VALUES('96001','005',82);
INSERT INTO Score VALUES('96002','001',88);
INSERT INTO Score VALUES('96002','003',92.5);
INSERT INTO Score VALUES('96002','006',90);
INSERT INTO Score VALUES('96005','004',92);
INSERT INTO Score VALUES('96005','005',90);
INSERT INTO Score VALUES('96005','006',87);
INSERT INTO Score VALUES('96005','007',76);
INSERT INTO Score VALUES('96003','001',69);
INSERT INTO Score VALUES('97001','001',96);
INSERT INTO Score VALUES('97001','008',95);
INSERT INTO Score VALUES('96004','001',87);
INSERT INTO Score VALUES('96003','003',91);
INSERT INTO Score VALUES('97002','003',91);
INSERT INTO Score(SNO,CNO) VALUES('97002','004');
INSERT INTO Score VALUES('97002','006',92);
INSERT INTO Score VALUES('97004','005',90);
INSERT INTO Score VALUES('97004','006',85);
(2)(修改数据库表) 在Student表中增加Birthday(date) 字段。
ALTER TABLE student ADD Birthday date;
(3) (修改数据库表) 在Student表中删除Birthday(date) 字段。
ALTER TABLE student DROP COLUMN Birthday;
(4) (修改数据库表) 将Student表中把Sname 字段修改为Sname(VCHAR2,20)且为
非空。
ALTER TABLE Student MODIFY SNAME varchar2(20);
(5) (修改数据库表) 将Student表中把Sname 字段修改为Sname(VCHAR2,20)且为非空。
ALTE