--建表
--student表+注释
create table student(sno   varchar2(3) not null,sname varchar2(9) not null,ssex  varchar2(3) not null,sbirthday date,sclass varchar2(5),constraint pk_student primary key(sno)
);
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 '学生所在班级';
--course表+注释
create table course(cno       varchar2(5) not null,cname     varchar2(15) not null,tno       varchar2(3) not null,constraint pk_course primary key(cno)
);
comment on column course.cno is '课程编号(主键)';
comment on column course.cname is '课程名称';
comment on column course.tno is '教工编号(外键)';
--score表+注释
create table score(sno   varchar2(3) not null,cno   varchar2(5) not null,degree   number(4,1),constraint pk_score primary key(sno,cno)
);
comment on column score.sno is '学号(主键)';
comment on column score.cno is '课程编号(主键)';
comment on column score.degree is '成绩';
--teacher表+注释
create table teacher(tno   varchar2(3) not null,tname varchar2(9) not null,tsex  varchar2(3) not null,tbirthday date,prof  varchar2(9),depart varchar2(15) not null,constraint pk_teacher primary key(tno)
);
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 '教工所在单位';
--添加外键
alter table course add constraint fk_tno foreign key(tno) references teacher(tno);
alter table score add constraint fk_sno foreign key(sno) references student(sno);
alter table score add constraint fk_cno foreign key(cno) references course(cno);
--添加数据
--Student表
insert into student(sno,sname,ssex,sbirthday,sclass) values(108,'曾华','男',to_date('1977-09-01','yyyy-mm-dd'),95033);
insert into student(sno,sname,ssex,sbirthday,sclass) values(105,'匡明','男',to_date('1975-10-02','yyyy-mm-dd'),95031);
insert into student(sno,sname,ssex,sbirthday,sclass) values(107,'王丽','女',to_date('1976-01-23','yyyy-mm-dd'),95033);
insert into student(sno,sname,ssex,sbirthday,sclass) values(101,'李军','男',to_date('1976-02-20','yyyy-mm-dd'),95033);
insert into student(sno,sname,ssex,sbirthday,sclass) values(109,'王芳','女',to_date('1975-02-10','yyyy-mm-dd'),95031);
insert into student(sno,sname,ssex,sbirthday,sclass) values(103,'陆君','男',to_date('1974-06-03','yyyy-mm-dd'),95031);
--teacher表
insert into teacher(tno,tname,tsex,tbirthday,prof,depart) values(804,'李诚','男',to_date('1958/12/02','yyyy-mm-dd'),'副教授','计算机系');
insert into teacher(tno,tname,tsex,tbirthday,prof,depart) values(856,'张旭','男',to_date('1969/03/12','yyyy-mm-dd'),'讲师','电子工程系');
insert into teacher(tno,tname,tsex,tbirthday,prof,depart) values(825,'王萍','女',to_date('1972/05/05','yyyy-mm-dd'),'助教','计算机系');
insert into teacher(tno,tname,tsex,tbirthday,prof,depart) values(831,'刘冰','女',to_date('1977/08/14','yyyy-mm-dd'),'助教','电子工程系');
--course表(添加外键后要先填teacher表中数据去满足外键约束)
insert into course(cno,cname,tno) values('3-105','计算机导论',825);
insert into course(cno,cname,tno) values('3-245','操作系统',804);
insert into course(cno,cname,tno) values('6-166','数字电路',856);
insert into course(cno,cname,tno) values('9-888','高等数学',831);
--score表(添加外键后要先填Student,course表中数据去满足外键约束)
insert into score(sno,cno,degree) values(103,'3-245',86);
insert into score(sno,cno,degree) values(105,'3-245',75);
insert into score(sno,cno,degree) values(109,'3-245',68);
insert into score(sno,cno,degree) values(103,'3-105',92);
insert into score(sno,cno,degree) values(105,'3-105',88);
insert into score(sno,cno,degree) values(109,'3-105',76);
insert into score(sno,cno,degree) values(101,'3-105',64);
insert into score(sno,cno,degree) values(107,'3-105',91);
insert into score(sno,cno,degree) values(108,'3-105',78);
insert into score(sno,cno,degree) values(101,'6-166',85);
insert into score(sno,cno,degree) values(107,'6-166',79);
insert into score(sno,cno,degree) values(108,'6-166',81);

Oracle建表及添加数据相关推荐

  1. ORACLE向表中添加数据

    ORACLE向表中添加数据 1.直接插入数据 insert into table_name values('col_text','col_text1'); 顺序一致,给表中的所有列添加一条数据时:(c ...

  2. oracle建表加compress,oracle 建表后添加表注释及字段注释

    oracle添加表注释和表字段注释 创建Oracle数据库表时候加上注释 CREATE TABLE t1( id  varchar2(32) primary key, name VARCHAR2(8) ...

  3. oracle建表后添加数据报错:ORA-01658:无法为表空间中的段创建INITIAL区

    看到这个,是表空间不足咧. 首先呢,我看了下建表时的表空间分配大小,分的挺多了64M,不行,改掉改成64k,ok啦. 别的表也报错.纠结了,决定给表空间大小改了. 1.先看下我的表空的位置 selec ...

  4. oracle添加序列器,Oracle 建表,添加主外键,序列,触发器

    select * from user_objects where object_type='TABLE'; --删除contact表,包括删除与其相关的约束 drop table contact ca ...

  5. oracle建表时添加comment,MYSQL中创建表时可以直接声明comment,ORACLE中似乎不可以,那么oracle该怎样简明地声明comment...

    CREATE TABLE `smbms_user` ( `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID', `userCode` varch ...

  6. PyCharm 2018 for mac 数据库实战:链接SQLite、建表、添加、查询数据

    一.前言 最近开始入门python,当然是要使用PyCharm,然后在项目中遇到.db数据库文件,双击打不开?网上找到了windows版本的教程,版本也比较旧,所以有空就来一发,当备忘也好~ 二.链接 ...

  7. oracle建表备份数据,oracle建表备份脚本,如果update的数据不对,可以从WEB_RI_PLYEDR_CED_BAK找回...

    下面是编程之家 jb51.cc 通过网络收集整理的代码片段. 编程之家小编现在分享给大家,也给大家做个参考. --oracle建表备份脚本,如果update的数据不对,可以从WEB_RI_PLYEDR ...

  8. oracle 创建表空间 pcincrease,oracle建表空间 各种语句

    oracle建表空间 各种语句 在创建用户之前,先要创建表空间: 其格式为:格式: create tablespace 表间名 datafile '数据文件名' size 表空间大小; 如: SQL& ...

  9. TABLE 以及 CONSTRAINT(创建TABLE以及CONSTRAINT、修改TABLE结构、建表后添加CONSTRAINT、删除TABLE和CONSTRAINT)

    文章目录 TABLE 以及 CONSTRAINT 创建 TABLE 以及 CONSTRAINT 修改 TABLE 结构 建表后添加 CONSTRAINT 删除 TABLE 和 CONSTRAINT T ...

最新文章

  1. asp.net 2.0中用GRIDVIEW插入新记录
  2. html透明度_学好Web前端开发,必要了解的HTML+CSS的技巧有哪些
  3. 关于centos6升级python3.6无法使用pip的问题
  4. 软件项目周报_软件产品研发流程
  5. 伟大公司为什么需要技术型领导?
  6. sparksql 保存点_Spark(十二)【SparkSql中数据读取和保存】
  7. android 画面,Android 界面组成
  8. java heap space 解决方法_内存溢出错误:java堆空间
  9. python划分train val test
  10. labelImg安装小记
  11. 基于MATLAB的人脸识别研究
  12. 贪心算法及其经典例题
  13. 计算24点游戏C语言课设
  14. 小福利,用selenium模块爬取qq音乐歌单!
  15. Syntax error on token(s), misplaced construct(s)
  16. 横空出世IDEA画图神器来了,比Visio快10倍
  17. sanic教程-快速开始安装
  18. ModuleNotFoundError: No module named ‘locust.events‘,httprunner执行locust压测报错解决办法~
  19. 读易[14]·远古卜卦算法分析与实现 1
  20. 融资渠道有哪些方式?

热门文章

  1. GNN论文周报 | 来自西湖大学、南京大学、国防科大、华为诺亚方舟实验室、莱斯大学等机构前沿论文研究...
  2. 【模型部署】TFX介绍
  3. 玩转Zadig之(一)helm生产环境部署
  4. dubbo升级至2.7.15后application配置无法生效
  5. 百度地图Api(一看就会系列)
  6. XBee3如何设置“自定义默认值”
  7. (原創) 如何破解Synplify Pro 9.6.2? (SOC) (Synplify)
  8. 小米、资生堂、都乐、发那科、云锋金融等公司高管变动
  9. Guava 本地缓存使用教程
  10. 芝诺悖论——追不上的乌龟