作业目的:
熟悉用户方案及方案对象的创建和使用。
作业内容:
2、手写以下SQL代码。
(1)创建学生信息表的SQL,以及插入图中4条数据的SQL。
create table STUDENTS(
Student_ID VARCHAR2(11) PRIMARY KEY,
Sname VARCHAR2(12) NOT NULL,
Ssex varchar2(3) not null,
Sbirth date not null,
Nationality varchar2(40) not null,
Dept_ID varchar2(3) not null,
Class_ID varchar2(5) not null,
constraint students_Dept_ID_fk foreign key (Dept_ID)
references Dept (Dept_ID),
constraint students_Class_ID_fk foreign key (Class_ID)
references Class(Class_ID)
);
insert into students(STUDENT_ID,SNAME,Ssex,Sbirth,Nationality,Dept_ID,Class_ID)
values ('20110810101','王传璐','男','24-4月-90','回族','081','08101');
insert into students(STUDENT_ID,SNAME,Ssex,Sbirth,Nationality,Dept_ID,Class_ID)
values ('20110810102','腾飞','男','01-12月-88','汉族','081','08101');
insert into students(STUDENT_ID,SNAME,Ssex,Sbirth,Nationality,Dept_ID,Class_ID)
values ('20110810103','张继发','男','09-8月-89','汉族','081','08101');
insert into students(STUDENT_ID,SNAME,Ssex,Sbirth,Nationality,Dept_ID,Class_ID)
values ('20110810104','赵济生','男','05-4月-90','汉族','081','08101');
(2)创建学生选课表的SQL,以及插入图中4条数据的SQL。
create table sc(
Student_ID varchar2(11),
Course_ID varchar2(4),
Grade number not null,
constraint sc_scID_pk primary key(Student_ID,Course_ID),
constraint sc_Student_ID_fk foreign key(Student_ID) references students(Student_ID),
constraint sc_Course_ID_fk foreign key(Course_ID) references Courses(Course_ID)
);
insert into SC( STUDENT_ID,COURSE_ID,Grade) values('20110810101','0001',76);
insert into SC( STUDENT_ID,COURSE_ID,Grade) values('20110810101','0002',84);
insert into SC( STUDENT_ID,COURSE_ID,Grade) values('20110810101','0003',59);
insert into SC( STUDENT_ID,COURSE_ID,Grade) values('20110810101','0004',72);
来源:https://blog.csdn.net/qq_41007733/article/details/102750177