你的位置:首页 > 数据库

[数据库]Oracle 建表


 1 -- Create table 2 create table STUDENT 3 ( 4  sno    VARCHAR2(3) not null, 5  sname   VARCHAR2(8) not null, 6  ssex   VARCHAR2(3) not null, 7  sbirthday DATE, 8  class   VARCHAR2(5) 9 )10 tablespace TEST.DBF11  pctfree 1012  initrans 113  maxtrans 25514  storage15  (16   initial 64K17   next 1M18   minextents 119   maxextents unlimited20  );21 -- Add comments to the table 22 comment on table STUDENT23  is '学生表';24 -- Add comments to the columns 25 comment on column STUDENT.sno26  is '学号(主键)';27 comment on column STUDENT.sname28  is '学生姓名';29 comment on column STUDENT.ssex30  is '学生性别';31 comment on column STUDENT.sbirthday32  is '学生出生年月';33 comment on column STUDENT.class34  is '学生所在班级';

添加数据:

课程表:

 1 -- Create table 2 create table COURSE 3 ( 4  cno  VARCHAR2(5) not null, 5  cname VARCHAR2(20) not null, 6  tno  VARCHAR2(3) not null 7 ) 8 tablespace TEST.DBF 9  pctfree 1010  initrans 111  maxtrans 25512  storage13  (14   initial 64K15   next 1M16   minextents 117   maxextents unlimited18  );19 -- Add comments to the table 20 comment on table COURSE21  is '课程表';22 -- Add comments to the columns 23 comment on column COURSE.cno24  is '课程号(主键)';25 comment on column COURSE.cname26  is '课程名称';27 comment on column COURSE.tno28  is '教工编号(外键)';

添加数据:

成绩表:

 1 -- Create table 2 create table SCORE 3 ( 4  sno  VARCHAR2(3) not null, 5  cno  VARCHAR2(5) not null, 6  degree NUMBER(4,1) not null 7 ) 8 tablespace TEST.DBF 9  pctfree 1010  initrans 111  maxtrans 25512  storage13  (14   initial 64K15   next 1M16   minextents 117   maxextents unlimited18  );19 -- Add comments to the table 20 comment on table SCORE21  is '成绩表';22 -- Add comments to the columns 23 comment on column SCORE.sno24  is '学号(外键)';25 comment on column SCORE.cno26  is '课程号(外键)';27 comment on column SCORE.degree28  is '成绩';

添加数据:

教师表:

 1 -- Create table 2 create table TEACHER 3 ( 4  tno    VARCHAR2(3) not null, 5  tname   VARCHAR2(10) not null, 6  tsex   VARCHAR2(3) not null, 7  tbirthday DATE, 8  prof   VARCHAR2(9), 9  depart  VARCHAR2(20) not null10 )11 tablespace TEST.DBF12  pctfree 1013  initrans 114  maxtrans 25515  storage16  (17   initial 64K18   next 1M19   minextents 120   maxextents unlimited21  );22 -- Add comments to the table 23 comment on table TEACHER24  is '教师表';25 -- Add comments to the columns 26 comment on column TEACHER.tno27  is '教工编号(主键)';28 comment on column TEACHER.tname29  is '教工姓名';30 comment on column TEACHER.tsex31  is '教工性别';32 comment on column TEACHER.tbirthday33  is '教工出生年月';34 comment on column TEACHER.prof35  is '职称';36 comment on column TEACHER.depart37  is '教工所在部门';

添加数据: