1 --建表
 2 --student表+注释
 3 create table student(
 4        sno   varchar2(3) not null,
 5        sname varchar2(9) not null,
 6        ssex  varchar2(3) not null,
 7        sbirthday date,
 8        sclass varchar2(5),
 9        constraint pk_student primary key(sno)
10 );
11 comment on column student.sno is '学号(主键)';
12 comment on column student.sname is '学生姓名';
13 comment on column student.ssex is '学生性别';
14 comment on column student.sbirthday is '学生出生年月日';
15 comment on column student.sclass is '学生所在班级';

16 --course表+注释
17 create table course(
18        cno       varchar2(5) not null,
19        cname     varchar2(15) not null,
20        tno       varchar2(3) not null,
21        constraint pk_course primary key(cno)
22 );
23 comment on column course.cno is '课程编号(主键)';
24 comment on column course.cname is '课程名称';
25 comment on column course.tno is '教工编号(外键)';

26 --score表+注释
27 create table score(
28         sno   varchar2(3) not null,
29         cno   varchar2(5) not null,
30         degree   number(4,1),
31         constraint pk_score primary key(sno,cno)
32 );
33 comment on column score.sno is '学号(主键)';
34 comment on column score.cno is '课程编号(主键)';
35 comment on column score.degree is '成绩';

36 --teacher表+注释
37 create table teacher(
38        tno   varchar2(3) not null,
39        tname varchar2(9) not null,
40        tsex  varchar2(3) not null,
41        tbirthday date,
42        prof  varchar2(9),
43        depart varchar2(15) not null,
44        constraint pk_teacher primary key(tno)
45 );
46 comment on column teacher.tno is '教工编号(主键)';
47 comment on column teacher.tname is '教工姓名';
48 comment on column teacher.tsex is '教工性别';
49 comment on column teacher.tbirthday is '教工出生年月';
50 comment on column teacher.prof is '职称';
51 comment on column teacher.depart is '教工所在单位';

52 --添加外键
53 alter table course add constraint fk_tno foreign key(tno) references teacher(tno);
54 alter table score add constraint fk_sno foreign key(sno) references student(sno);
55 alter table score add constraint fk_cno foreign key(cno) references course(cno); 

56 --添加数据
57 --Student表
58 insert into student(sno,sname,ssex,sbirthday,sclass) values(108,'曾华','男',to_date('1977-09-01','yyyy-mm-dd'),95033);
59 insert into student(sno,sname,ssex,sbirthday,sclass) values(105,'匡明','男',to_date('1975-10-02','yyyy-mm-dd'),95031);
60 insert into student(sno,sname,ssex,sbirthday,sclass) values(107,'王丽','女',to_date('1976-01-23','yyyy-mm-dd'),95033);
61 insert into student(sno,sname,ssex,sbirthday,sclass) values(101,'李军','男',to_date('1976-02-20','yyyy-mm-dd'),95033);
62 insert into student(sno,sname,ssex,sbirthday,sclass) values(109,'王芳','女',to_date('1975-02-10','yyyy-mm-dd'),95031);
63 insert into student(sno,sname,ssex,sbirthday,sclass) values(103,'陆君','男',to_date('1974-06-03','yyyy-mm-dd'),95031);

64 --teacher表
65 insert into teacher(tno,tname,tsex,tbirthday,prof,depart) values(804,'李诚','男',to_date('1958/12/02','yyyy-mm-dd'),'副教授','计算机系');
66 insert into teacher(tno,tname,tsex,tbirthday,prof,depart) values(856,'张旭','男',to_date('1969/03/12','yyyy-mm-dd'),'讲师','电子工程系');
67 insert into teacher(tno,tname,tsex,tbirthday,prof,depart) values(825,'王萍','女',to_date('1972/05/05','yyyy-mm-dd'),'助教','计算机系');
68 insert into teacher(tno,tname,tsex,tbirthday,prof,depart) values(831,'刘冰','女',to_date('1977/08/14','yyyy-mm-dd'),'助教','电子工程系');

69 --course表(添加外键后要先填teacher表中数据去满足外键约束)
70 insert into course(cno,cname,tno) values('3-105','计算机导论',825);
71 insert into course(cno,cname,tno) values('3-245','操作系统',804);
72 insert into course(cno,cname,tno) values('6-166','数字电路',856);
73 insert into course(cno,cname,tno) values('9-888','高等数学',831);

74 --score表(添加外键后要先填Student,course表中数据去满足外键约束)
75 insert into score(sno,cno,degree) values(103,'3-245',86);
76 insert into score(sno,cno,degree) values(105,'3-245',75);
77 insert into score(sno,cno,degree) values(109,'3-245',68);
78 insert into score(sno,cno,degree) values(103,'3-105',92);
79 insert into score(sno,cno,degree) values(105,'3-105',88);
80 insert into score(sno,cno,degree) values(109,'3-105',76);
81 insert into score(sno,cno,degree) values(101,'3-105',64);
82 insert into score(sno,cno,degree) values(107,'3-105',91);
83 insert into score(sno,cno,degree) values(108,'3-105',78);
84 insert into score(sno,cno,degree) values(101,'6-166',85);
85 insert into score(sno,cno,degree) values(107,'6-166',79);
86 insert into score(sno,cno,degree) values(108,'6-166',81);

转载于:https://www.cnblogs.com/ssC2H4/p/8548695.html

oracle基础建表相关推荐

  1. oracle数据库等级,[数据库]Oracle数据库建表并用SQL编程分等级

    [数据库]Oracle数据库建表并用SQL编程分等级 0 2016-06-15 23:00:13 --创建学生表 create table XS_543 ( XH char(6) not null , ...

  2. PowerDesigner,如何将Mysql数据库建表语句转化成Oracle数据库建表语句。

    在实际工作中,一张表,我们可能需要在Mysql数据库中建表,又要在Oracle数据库中建表.表中每个字段的数据类型.中文注释.是否可为NULL 问题,非常影响我们建表的效率.本篇文章,以Mysql数据 ...

  3. Oracle数据库建表 Oracle数据库的统一命名与编码规范

    本文转载自:http://chinaxxren.iteye.com/blog/889590 如有疑问请咨询原博主,谢谢!! 写在前边: 规范是一种习惯,在Oracle数据库中笔者认为表中的字段命名规范 ...

  4. oracle数据库建表、修改字段名称类型、增加字段、ID自动增长写法

    oracle建表: create table INDEX_POLICY_TBL       (        ID NUMBER(10) NOT NULL PRIMARY KEY,        PO ...

  5. oracle怎样建表,oracle怎样建表?_数据库

    oracle建表的要领:1.必需以字母开头:2.不必SQL里的保留字, 肯定要用时可用双引号把字符串括起来:3.用和实体或属性相干的英文标记长度有肯定的限定. oracle建表的要领: 1.建立表格语 ...

  6. oracle的建表语句

    oracle数据库的建表语句,具体语法如下: CREATE TABLE tablename(column_name datatype [null,not null],column_name datat ...

  7. oracle数据库建表

    建表 create table 表名 (列名1 数据类型 [列级约束],列名2 数据类型 [列级约束]-): create table 表名(列名1 数据类型,列名2 数据类型,[表级约束],[表级约 ...

  8. oracle数据库建表语句

    1.一个用户可以有多个角色 2.一个用户可以有多个权限 3.一个权限也可以给多个用户 Oracle 系统默认用户 system:是数据库内置的一个普通管理员 sys:用数据库的超级用户,必须以 sys ...

  9. Oracle 基础篇 --- 表空间的操作

    2019独角兽企业重金招聘Python工程师标准>>> ###更改表空间 ####1 重命名表空间 将表空间 /home/oracle/app/oracle/product/11.2 ...

最新文章

  1. 为SQL Server Express 2012启用远程连接
  2. oracle10g库连接报错
  3. “三通一达”创始人均来自桐庐 有的村人均GDP上亿
  4. python column stack_Python基础 | pandas中dataframe的整合与形变(merge reshape)
  5. Cypress 的条件测试
  6. Android系统的智能指针(轻量级指针、强指针和弱指针)的实现原理分析(3)...
  7. 让用户闭着眼睛买东西可还行?雷军谈小米的目标...
  8. docker hive nagasuga_制作一个用来调试hive的docker镜像
  9. ENVI遥感处理(9):遥感影像镶嵌和图像裁剪
  10. 配置keepalived实现Nginx高可用(单主、双主模式)
  11. 书评 《编码: 隐匿在计算机软硬件背后的语言》
  12. 智能手环APP有哪些功能,具体解决方案是什么?
  13. 捣鼓PlantUML(三、时序图)
  14. python eel 多线程_Python + Eel + Sqlite 实现个人密码管理器
  15. 为什么我的同花顺选股服务器列表为空,同花顺选股公式,为什么我就选不出股票来呢数......
  16. COI2016 Palinilap(manacher+后缀数组)
  17. 3DMAX高级光照相关的名词解释
  18. python恶搞代码-Python里最搞怪的招式是啥 |初探生成器
  19. (附源码)ssm医药销售管理系统 毕业设计 042322
  20. 理论物理极础9:相空间流体和吉布斯-刘维尔定理

热门文章

  1. IdentityServer4 配置负载均衡
  2. Html5 音效播放器
  3. (树)判断二叉树是否为BST
  4. Python开发【第八篇】:网络编程 Socket
  5. boost库在工作(20)线程之五
  6. 数字万用表的四位半,三位半都是什么意思?
  7. 十种创业病 你得了几个?
  8. 设计模式复习-模板方法模式
  9. POJ 2516 基础费用流
  10. 计算机网络第二章:物理层