表空间与表的创建

--修改系统表空间  
  ALTER   TABLESPACE   SYSTEM   DEFAULT   STORAGE   (   INITIAL   64K   NEXT   64K   MINEXTENTS   1   MAXEXTENTS   UNLIMITED   PCTINCREASE   50);  
  ALTER   TABLESPACE   SYSTEM   MINIMUM   EXTENT   64K;  
   
  --创建回滚表空间  
  CREATE   TABLESPACE   RBS   DATAFILE   'D:\Oracle\oradata\test\rbs01.dbf'   SIZE   256M   REUSE  
  AUTOEXTEND   ON   NEXT   5120K  
  MINIMUM   EXTENT   512K  
  DEFAULT   STORAGE   (   INITIAL   512K   NEXT   512K   MINEXTENTS   8   MAXEXTENTS   4096);  
   
  --创建用户表空间  
  CREATE   TABLESPACE   USERS   DATAFILE   'D:\Oracle\oradata\test\users01.dbf'   SIZE   128M   REUSE  
  AUTOEXTEND   ON   NEXT   1280K  
  MINIMUM   EXTENT   128K  
  DEFAULT   STORAGE   (   INITIAL   128K   NEXT   128K   MINEXTENTS   1   MAXEXTENTS   4096   PCTINCREASE   0);  
   
  --创建临时表空间  
  CREATE   TABLESPACE   TEMP   DATAFILE   'D:\Oracle\oradata\test\temp01.dbf'   SIZE   32M   REUSE  
  AUTOEXTEND   ON   NEXT   640K  
  MINIMUM   EXTENT   64K  
  DEFAULT   STORAGE   (   INITIAL   64K   NEXT   64K   MINEXTENTS   1   MAXEXTENTS   UNLIMITED   PCTINCREASE   0)   TEMPORARY;  
   
  --创建工具表空间  
  CREATE   TABLESPACE   TOOLS   DATAFILE   'D:\Oracle\oradata\test\tools01.dbf'   SIZE   64M   REUSE  
  AUTOEXTEND   ON   NEXT   320K  
  MINIMUM   EXTENT   32K  
  DEFAULT   STORAGE   (   INITIAL   32K   NEXT   32K   MINEXTENTS   1   MAXEXTENTS   4096   PCTINCREASE   0);  
   
  --创建索引表空间  
  CREATE   TABLESPACE   INDX   DATAFILE   'D:\Oracle\oradata\test\indx01.dbf'   SIZE   32M   REUSE  
  AUTOEXTEND   ON   NEXT   1280K  
  MINIMUM   EXTENT   128K  
  DEFAULT   STORAGE   (   INITIAL   128K   NEXT   128K   MINEXTENTS   1   MAXEXTENTS   4096   PCTINCREASE   0);  





1.--
连接

conn hu/aaa;

-- 创建表空间

Create tablespace computer2005 nologging datafile 'd:\oracle\product\10.2.0\oradata\test\computer.dbf' size 50m blocksize 8192 extent management local uniform size 256k segment space management auto;

-- 创建学生基本信息表

create table student(学号 varchar2(20 byte) not null,

                          姓名 varchar2(8 byte),

                          性别 varchar2(4 byte),

                          民族 varchar2(8 byte),

constraint pk_stud primary key(学号) using index tablespace computer2005

pctfree 10 initrans 2 maxtrans 255);

-- 创建课程信息表

create table course(课程编号 varchar2(5 byte) not null,

                      课程类型 varchar2(6 byte),

                      课程名 varchar2(20 byte),

                      周学时 integer,

                      任课教师 varchar2(10 byte),

                      开设学期 integer,

                      考核方式 varchar2(4 byte),

constraint pk_cour primary key(课程编号) using index tablespace computer2005

pctfree 10 initrans 2 maxtrans 255);

-- 创建学生成绩表

create table score(学号 varchar2(20 byte) not null,

                      课程编号 varchar2(5 byte) not null,

                      成绩 number,

constraint pk_sc primary key(学号,课程编号)

using index tablespace computer2005 pctfree 10 initrans 2 maxtrans 255);

-- 添加外键

alter table score add constraint fk_stud_score foreign key(学号) references student(学号);

alter table score add constraint fk_cour_score foreign key(课程编号) references course(课程编号);

--移动表到工作表空间

alter table student move tablespace computer2005;

alter table course move tablespace computer2005;

alter table score move tablespace computer2005;

-- 使用SQL loader导入数据

host sqlldr hu/aaa control=d:\oracle\insert4.ctl log=d:\oracle\4.log

host sqlldr hu/aaa control=d:\oracle\insert5.ctl log=d:\oracle\5.log

host sqlldr hu/aaa control=d:\oracle\insert6.ctl log=d:\oracle\6.log

2.-- 创建用户

create user hu identified by aaa;

-- 赋予权限

grant dba,connect to hu with admin option;

-- 连接

conn hu/aaa;

-- 创建表空间

create tablespace student_app nologging datafile 'd:\oracle\product\10.2.0\oradata\test\student.dbf' size 50m blocksize 8192 extent management local uniform size 256k segment space management auto;

-- 创建学生基本信息表

create table 学生基本信息(学号 varchar2(20 byte) not null,

                          姓名 varchar2(8 byte),

                          性别 varchar2(4 byte),

                          民族 varchar2(8 byte),

constraint pk_baseinfo primary key(学号) using index tablespace student_app

pctfree 10 initrans 2 maxtrans 255);

-- 创建课程信息表

create table 课程信息(课程编号 varchar2(5 byte) not null,

                      课程类型 varchar2(6 byte),

                      课程名 varchar2(20 byte),

                      周学时 integer,

                      任课教师 varchar2(10 byte),

                      开设学期 integer,

                      考核方式 varchar2(4 byte),

constraint pk_course primary key(课程编号) using index tablespace student_app

pctfree 10 initrans 2 maxtrans 255);

-- 创建学生成绩表

create table 学生成绩(学号 varchar2(20 byte) not null,

                      课程编号 varchar2(5 byte) not null,

                      成绩 number,

constraint pk_grade primary key(学号,课程编号)

using index tablespace student_app pctfree 10 initrans 2 maxtrans 255);

-- 添加外键

alter table 学生成绩 add constraint fk_info_grade foreign key(学号) references 学生基本信息(学号);

alter table 学生成绩 add constraint fk_course_grade foreign key(课程编号) references 课程信息(课程编号);

--移动表到工作表空间

alter table 学生基本信息 move tablespace student_app;

alter table 课程信息 move tablespace student_app;

alter table 学生成绩 move tablespace student_app;

-- 使用SQL lpader导入数据

host sqlldr hu/aaa control=d:\oracle\insert1.ctl log=d:\oracle\1.log

host sqlldr hu/aaa control=d:\oracle\insert2.ctl log=d:\oracle\2.log

host sqlldr hu/aaa control=d:\oracle\insert3.ctl log=d:\oracle\3.log

原文地址:https://www.cnblogs.com/linsond/p/1572228.html