一、            设有一数据库,包括四个表:学生表(Student)、课程表(Course)、成绩表(Score)以及教师信息表(Teacher)。四个表的结构分别如表1-1的表(一)~表(四)所示,数据如表1-2的表(一)~表(四)所示。用SQL语句创建四个表并完成相关题目。

表1-1数据库的表结构

表(一)Student (学生表)

字段名 数据类型 可否为空 含 义

Sno Varchar2(3) 否 学号(主键)

Sname Varchar2(8) 否 学生姓名

Ssex Varchar2(2) 否 学生性别

Sbirthday Date 可 学生出生年月

SClass Varchar2(5) 可 学生所在班级

表(二)Course(课程表)

属性名 数据类型 可否为空 含 义

Cno Varchar2(5) 否 课程号(主键)

Cname Varchar(10) 否 课程名称

Tno Varchar2(3) 否 教工编号(外键)

表(三)Score(成绩表)

属性名 数据类型 可否为空 含 义

Sno Varchar2(3) 否 学号(外键)

Cno Varchar2(5) 否 课程号(外键)

Degree Number(4,1) 可 成绩

主键:Sno+ Cno

表(四)Teacher(教师表)

属性名 数据类型 可否为空 含 义

Tno Varchar2(3) 否 教工编号(主键)

Tname Varchar2(4) 否 教工姓名

Tsex Varchar2(2) 否 教工性别

Tbirthday Date 可 教工出生年月

Prof Varchar2(6) 可 职称

Depart Varchar(10) 否 教工所在部门

表1-2数据库中的数据

表(一)Student

Sno Sname Ssex Sbirthday class

108 曾华 男 1977/09/01 95033

105 匡明 男 1975/10/02 95031

107 王丽 女 1976/01/23 95033

101 李军 男 1976/02/20 95033

109 王芳 女 1975/02/10 95031

103 陆君 男 1974/06/03 95031

 

表(二)Course

Cno Cname Tno

3-105 计算机导论 825

3-245 操作系统 804

6-166 数字电路 856

9-888 高等数学 831

表(三)Score

Sno Cno Degree

103 3-245 86

105 3-245 75

109 3-245 68

103 3-105 92

105 3-105 88

109 3-105 76

101 3-105 64

107 3-105 91

108 3-105 78

101 6-166 85

107 6-166 79

108 6-166 81

表(四)Teacher

Tno Tname Tsex Tbirthday Prof Depart

804 李诚 男 1958/12/02 副教授 计算机系

856 张旭 男 1969/03/12 讲师 电子工程系

825 王萍 女 1972/05/05 助教 计算机系

831 刘冰 女 1977/08/14 助教 电子工程系

建表:

-- Create table

create table STUDENT

(

sno VARCHAR2(3) not null,

sname VARCHAR2(12) not null,

ssex VARCHAR2(3) not null,

sbirthday DATE,

sclass VARCHAR2(5)

)

tablespace USERS

pctfree 10

initrans 1

maxtrans 255

storage

(

initial 64K

next 1M

minextents 1

maxextents unlimited

);

-- Add comments to the columns

comment on column STUDENT.sno

is '学号(主键)';

comment on column STUDENT.sname

is '学生姓名';

comment on column STUDENT.ssex

is '学生性别';

comment on column STUDENT.sbirthday

is '学生生日';

comment on column STUDENT.sclass

is '学生班级';

-- Create/Recreate primary, unique and foreign key constraints

alter table STUDENT

add constraint PK_STUDENT primary key (SNO)

using index

tablespace USERS

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 64K

next 1M

minextents 1

maxextents unlimited

);

-- Create table

create table COURSE

(

cno VARCHAR2(5) not null,

cname VARCHAR2(15) not null,

tno VARCHAR2(3) not null

)

tablespace USERS

pctfree 10

initrans 1

maxtrans 255

storage

(

initial 64K

next 1M

minextents 1

maxextents unlimited

);

-- Add comments to the columns

comment on column COURSE.cno

is '课程号(主键)';

comment on column COURSE.cname

is '课程名称';

comment on column COURSE.tno

is '教工编号(外键)';

-- Create/Recreate primary, unique and foreign key constraints

alter table COURSE

add constraint PK_COURSE primary key (CNO)

using index

tablespace USERS

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 64K

next 1M

minextents 1

maxextents unlimited

);

alter table COURSE

add constraint PK_TNO foreign key (TNO)

references TEACHER (TNO);

-- Create table

create table SCORE

(

sno VARCHAR2(3) not null,

cno VARCHAR2(5) not null,

degree NUMBER(4,1)

)

tablespace USERS

pctfree 10

initrans 1

maxtrans 255

storage

(

initial 64K

next 1M

minextents 1

maxextents unlimited

);

-- Add comments to the columns

comment on column SCORE.sno

is '学号(外键)';

comment on column SCORE.cno

is '课程号(外键)';

comment on column SCORE.degree

is '成绩';

-- Create/Recreate primary, unique and foreign key constraints

alter table SCORE

add constraint PK_SCORE primary key (SNO, CNO)

using index

tablespace USERS

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 64K

next 1M

minextents 1

maxextents unlimited

);

alter table SCORE

add constraint FK_CNO foreign key (CNO)

references COURSE (CNO);

alter table SCORE

add constraint FK_SNO foreign key (SNO)

references STUDENT (SNO);

-- Create table

create table TEACHER

(

tno VARCHAR2(3) not null,

tname VARCHAR2(6) not null,

tsex VARCHAR2(3) not null,

tbirthday DATE,

prof VARCHAR2(9),

depart VARCHAR2(15) not null

)

tablespace USERS

pctfree 10

initrans 1

maxtrans 255

storage

(

initial 64K

next 1M

minextents 1

maxextents unlimited

);

-- Add comments to the columns

comment on column TEACHER.tno

is '教工编号(主键)';

comment on column TEACHER.tname

is '教工姓名';

comment on column TEACHER.tsex

is '教工性别';

comment on column TEACHER.tbirthday

is '教工出生年月';

comment on column TEACHER.prof

is '职称';

comment on column TEACHER.depart

is '教工所在部门';

-- Create/Recreate primary, unique and foreign key constraints

alter table TEACHER

add constraint PA_TEACHER primary key (TNO)

using index

tablespace USERS

pctfree 10

initrans 2

maxtrans 255

storage

(

initial 64K

next 1M

minextents 1

maxextents unlimited

);

20_学生选课数据库SQL语句练习题的更多相关文章

  1. 20_学生选课数据库SQL语句练习题1

    25.查询95033班和95031班全体学生的记录. select * from STUDENT t,SCORE s where t.sclass=95033 or t.sclass=95031 26 ...

  2. 学生选课数据库SQL语句练习题

    一.            设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表( ...

  3. _学生选课数据库SQL语句练习题

    1. 查询Student表中的所有记录的Sname.Ssex和Class列. select Sname,Ssex,t.sclass from STUDENT t 2. 查询教师所有的单位即不重复的De ...

  4. (10.09作业)学生选课数据库SQL语句练习题

  5. 学生选课数据库SQL语句45道练习题整理及mysql常用函数(20161019)

    学生选课数据库SQL语句45道练习题: 一.            设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四 ...

  6. SQL Server T—SQL 学生选课数据库SQL语句考试题(45道题)

    题目  设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表(四)所示,数据如表1 ...

  7. 选课数据库SQL语句练习题

    表(一)Student (学生表) 属性名 数据类型 可否为空 含 义 Sno varchar (20) 否 学号(主码) Sname varchar (20) 否 学生姓名 Ssex varchar ...

  8. 学生选课数据库MySQL语句练习题45道

    1. 查询Student表中的所有记录的Sname.Ssex和Class列. select Sname,Ssex,Class from Student;2. 查询教师所有的单位即不重复的Depart列 ...

  9. 数据库SQL语句练习题

    一.            设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表( ...

随机推荐

  1. contentType设置类型导致ajax post data 获取不到数据

    ajax post  data  获取不到数据,注意 content-type的设置 .post/get关于 jQuery data 传递数据.网上各种获取不到数据,乱码之类的. 好吧今天我也遇到了, ...

  2. <蛇形填数>--算法竞赛 入门经典(第2版)- 3.1 数组 程序3-3 蛇形填数

     蛇形填数: 在n×n方阵里填入1,2,....,n×n,要求填成蛇形.例如,n = 4 时方阵为:    10  11  12  1   9  16  13  2 8  15  14  3 7   ...

  3. css,js零散知识的整理

    在同一个dom上以冒泡和捕获的方式绑定一个事件,如果事件源是该元素,则是先绑定的哪一个就先执行哪一个,事件源是dom的子孙节点,则先执行捕获事件

  4. some idea for my personal page

    firstly, dump the old personal page source from Github to Dropbox.then the idea is: 1: make a fake s ...

  5. chrome手动添加拓展

    https://www.crx4chrome.com/crx/978/ Free Download Postman REST Client CRX 0.8.4.19 for ------------- ...

  6. freemarker + spring mvc + spring + mybatis + mysql + maven项目搭建

    今天说说搭建项目,使用freemarker + spring mvc + spring + mybatis + mysql + maven搭建web项目. 先假设您已经配置好eclipse的maven ...

  7. JQuery常用API 核心 效果 JQueryHTML 遍历 Event事件

    JQuery 常用API 参考资料:JQuery 官网   jQuery API 中文文档 核心 jQuery 对象 jQuery() 返回匹配的元素集合,无论是通过在DOM的基础上传递的参数还是创建 ...

  8. 关于安装第三方模块和PILLOW

    看廖雪峰老师这一节的教程卡在这里挺久了 在谷歌上了搜了很久,最后根据这个教程上解决了这个问题 http://www.yihaomen.com/article/python/566.htm 觉得自己好蠢 ...

  9. 微信小程序学习总结(1)

    1.一个小程序文件最基本包含app.js.app.json.app.wxss和pages文件夹结构,pages中的页面必须要在app.json的pages项进行配置,app.json也提供窗口表现,t ...

  10. 设计模式--命令模式(Command)

    基本概念:  Command模式也叫命令模式 ,是行为设计模式的一种.Command模式通过被称为Command的类封装了对目标对象的调用行为以及调用参数,命令模式将方法调用给封装起来了. 命令模式的 ...