oracle SQL 练习

COURSE 表
DROP TABLE "SCOTT"."course";
CREATE TABLE "SCOTT"."course" (
"COURSE_ID" VARCHAR2(20 BYTE) NOT NULL ,
"COURSE_NAME" VARCHAR2(50 BYTE) NOT NULL ,
"TEACHER" VARCHAR2(20 BYTE) NULL 
)
LOGGING
NOCOMPRESS
NOCACHE
;
COMMENT ON COLUMN "SCOTT"."course"."COURSE_ID" IS '课程编号';
COMMENT ON COLUMN "SCOTT"."course"."COURSE_NAME" IS '课程名称';
COMMENT ON COLUMN "SCOTT"."course"."TEACHER" IS '任课教师';
-- ----------------------------
ALTER TABLE "SCOTT"."course" ADD CHECK ("COURSE_ID" IS NOT NULL);
ALTER TABLE "SCOTT"."course" ADD CHECK ("COURSE_NAME" IS NOT NULL);
ALTER TABLE "SCOTT"."course" ADD PRIMARY KEY ("COURSE_ID");

INSERT INTO "SCOTT"."course" VALUES ('x001', '计算机基础', '王洋');
INSERT INTO "SCOTT"."course" VALUES ('x002', 'C语言程序设计', '李峰');
INSERT INTO "SCOTT"."course" VALUES ('x003', 'PHP程序设计', '张婷');
INSERT INTO "SCOTT"."course" VALUES ('x004', 'Java程序设计', '郭强');

student 表
-- ----------------------------
DROP TABLE "SCOTT"."student";
CREATE TABLE "SCOTT"."student" (
"STU_ID" VARCHAR2(20 BYTE) NOT NULL ,
"STU_NAME" VARCHAR2(20 BYTE) NOT NULL ,
"GENDER" VARCHAR2(2 BYTE) NOT NULL ,
"BIRTHDAY" VARCHAR2(20 BYTE) NULL ,
"CLASS_ID" VARCHAR2(10 BYTE) NOT NULL ,
"ADDRESS" VARCHAR2(30 BYTE) NULL 
)
LOGGING
NOCOMPRESS
NOCACHE

;
COMMENT ON COLUMN "SCOTT"."student"."STU_ID" IS '学号';
COMMENT ON COLUMN "SCOTT"."student"."STU_NAME" IS '姓名';
COMMENT ON COLUMN "SCOTT"."student"."GENDER" IS '性别';
COMMENT ON COLUMN "SCOTT"."student"."BIRTHDAY" IS '生日';
COMMENT ON COLUMN "SCOTT"."student"."CLASS_ID" IS '班级编号';
COMMENT ON COLUMN "SCOTT"."student"."ADDRESS" IS '地址';
-- ----------------------------
ALTER TABLE "SCOTT"."student" ADD CHECK ("STU_ID" IS NOT NULL);
ALTER TABLE "SCOTT"."student" ADD CHECK ("STU_NAME" IS NOT NULL);
ALTER TABLE "SCOTT"."student" ADD CHECK ("GENDER" IS NOT NULL);
ALTER TABLE "SCOTT"."student" ADD CHECK ("CLASS_ID" IS NOT NULL);
ALTER TABLE "SCOTT"."student" ADD PRIMARY KEY ("STU_ID");

INSERT INTO "SCOTT"."student" VALUES ('1001', '李海东', '男', '1988-04-05', 'c001', '松原市');
INSERT INTO "SCOTT"."student" VALUES ('1002', '王庆斌', '男', '1990-09-08', 'c001', '长春市');
INSERT INTO "SCOTT"."student" VALUES ('1003', '李敏', '女', '1991-11-22', 'c002', '哈尔滨市');
INSERT INTO "SCOTT"."student" VALUES ('1004', '张强', '男', '1980-10-28', 'c002', '沈阳市');
INSERT INTO "SCOTT"."student" VALUES ('1005', '吴正', '男', '1978-07-06', 'c001', '长春市');
INSERT INTO "SCOTT"."student" VALUES ('1006', '郭东雨', '女', '1990-05-08', 'c003', '吉林市');

class 表
-- ----------------------------
DROP TABLE "SCOTT"."class";
CREATE TABLE "SCOTT"."class" (
"CLASS_ID" VARCHAR2(20 BYTE) NOT NULL ,
"CLASS_NAME" VARCHAR2(20 BYTE) NOT NULL 
)
LOGGING
NOCOMPRESS
NOCACHE

;
COMMENT ON COLUMN "SCOTT"."class"."CLASS_ID" IS '班级编号';
COMMENT ON COLUMN "SCOTT"."class"."CLASS_NAME" IS '班级名称';
-- ----------------------------
ALTER TABLE "SCOTT"."class" ADD UNIQUE ("CLASS_NAME");
ALTER TABLE "SCOTT"."class" ADD CHECK ("CLASS_ID" IS NOT NULL);
ALTER TABLE "SCOTT"."class" ADD CHECK ("CLASS_NAME" IS NOT NULL);
ALTER TABLE "SCOTT"."class" ADD PRIMARY KEY ("CLASS_ID");

INSERT INTO "SCOTT"."class" VALUES ('c001', '111111');
INSERT INTO "SCOTT"."class" VALUES ('c002', '111112');
INSERT INTO "SCOTT"."class" VALUES ('c003', '111141');
INSERT INTO "SCOTT"."class" VALUES ('c004', '111142');

xk  选课表
DROP TABLE "SCOTT"."xk";
CREATE TABLE "SCOTT"."xk" (
"STU_ID" VARCHAR2(20 BYTE) NOT NULL ,
"COURSE_ID" VARCHAR2(20 BYTE) NOT NULL ,
"GRADE" FLOAT NULL 
)
LOGGING
NOCOMPRESS
NOCACHE

;
COMMENT ON COLUMN "SCOTT"."xk"."STU_ID" IS '班级编号';
COMMENT ON COLUMN "SCOTT"."xk"."COUSE_ID" IS '课程编号';
COMMENT ON COLUMN "SCOTT"."xk"."GRADE" IS '成绩';
-- ----------------------------
ALTER TABLE "SCOTT"."xk" ADD CHECK ("STU_ID" IS NOT NULL);
ALTER TABLE "SCOTT"."xk" ADD CHECK ("COURSE_ID" IS NOT NULL);
ALTER TABLE "SCOTT"."xk" ADD PRIMARY KEY ("STU_ID", "COUSE_ID");

INSERT INTO "SCOTT"."xk" VALUES ('1001', 'x001', '95.5');
INSERT INTO "SCOTT"."xk" VALUES ('1002', 'x001', '80');
INSERT INTO "SCOTT"."xk" VALUES ('1001', 'x002', '65');
INSERT INTO "SCOTT"."xk" VALUES ('1003', 'x002', '75');
INSERT INTO "SCOTT"."xk" VALUES ('1004', 'x003', '90');
INSERT INTO "SCOTT"."xk" VALUES ('1005', 'x003', '68');
INSERT INTO "SCOTT"."xk" VALUES ('1005', 'x004', '88');

posted @ 2019-09-10 14:47  lvlin241  阅读(234)  评论(0编辑  收藏  举报