create table tablename(
colone 类型 
.......
constraint 主键名 primary key(colname) using index tablespace spacename,
constraint 外键名 foreign key (colname) references tablename(colname));
默认主键就是索引!

解决方案 »

  1.   

    表空间定义呢?
    还有需要另建索引时也需要定义索引空间spacename从何而来?
      

  2.   

    -- Create table
    create table APPLY_EXPORT_GOODS
    (
      HANDBOOK_ID     VARCHAR2(20) not null,
      LINE_NO         NUMBER(4) not null,
      GOODS_CODE      VARCHAR2(20) not null,
      DESCRIPTION     VARCHAR2(30),
      SPEC_UM         VARCHAR2(30),
      APPLY_QTY       NUMBER(16,4) not null,
      EXPORTED_QTY    NUMBER(16,4) not null,
      STOCK_UM        VARCHAR2(10),
      UNIT_PRICE      NUMBER(16,4) not null,
      APPLY_AMOUNT    NUMBER(16,4) not null,
      EXPORTED_AMOUNT NUMBER(16,4) not null,
      STATUS          VARCHAR2(10) not null,
      USER_1          NUMBER(16,4) default 0,
      USER_2          VARCHAR2(20),
      USER_3          VARCHAR2(20),
      USER_4          VARCHAR2(20) not null
    )
    -- Create/Recreate primary, unique and foreign key constraints 
    alter table APPLY_EXPORT_GOODS
      add constraint APPLY_EXPORT_PK primary key (HANDBOOK_ID,LINE_NO);
    alter table APPLY_EXPORT_GOODS
      add constraint APPLY_EXPORT_FK foreign key (HANDBOOK_ID)
      references HANDBOOK (ID);
    -- Create/Recreate indexes 
    create index IDX_APPLY_EXPORT on APPLY_EXPORT_GOODS (HANDBOOK_ID,LINE_NO)
      

  3.   

    阿张:
    下面这段的 EM_DATA是什么时候定义的?tablespace EM_DATA
      pctfree 10
      initrans 1
      maxtrans 255
      storage
      (
        initial 64K
        minextents 1
        maxextents unlimited
      );
      

  4.   

    -- Create table
    create table P_ZJRB
    (
      WELLNO    VARCHAR2(20) not null,
      USEUNITID VARCHAR2(18) not null,
      RBXH      NUMBER(10) not null,
      RBRQ      DATE,
      ZZRQ      DATE,
      ZZJS      NUMBER(8,2),
      LJJC      NUMBER(8,2),
      DC        VARCHAR2(20),
      ZTXINGH   VARCHAR2(20),
      ZTXJ      VARCHAR2(1) default '1',
      ZTCC      NUMBER(8,2),
      QSJS      NUMBER(8,2),
      GZNR      VARCHAR2(1000),
      ZDTS      VARCHAR2(60),
      ANJL      VARCHAR2(24),
      ZBGB      VARCHAR2(24),
      GZZT      VARCHAR2(20),
      ZS        NUMBER(4),
      BY1       NUMBER(6,1),
      PL        NUMBER(6,2),
      ZY        NUMBER(4),
      ZJYMD     NUMBER(4,2),
      QYJS      NUMBER(8,2),
      SXZD      NUMBER(5,1),
      HSL       NUMBER(4,1),
      ZYSS      NUMBER(5,1),
      NB        NUMBER(5,2),
      QL10M     NUMBER(5,1),
      QL10F     NUMBER(5,1),
      DQL       NUMBER(8,2),
      PHZ       NUMBER(3,1),
      LDZD      NUMBER(4),
      XZZDJ3ZD  NUMBER(4,1),
      XZZDJ300  NUMBER(4,1),
      XZZDJ600  NUMBER(4,1),
      BSFLAG    VARCHAR2(1),
      COMNAME   VARCHAR2(30),
      ZJRBSHR   VARCHAR2(24)
    )
    tablespace USERS
      pctfree 10
      pctused 40
      initrans 1
      maxtrans 255
      storage
      (
        initial 18688K
        next 128K
        minextents 1
        maxextents unlimited
        pctincrease 0
      );
    -- Add comments to the table 
    comment on table P_ZJRB
      is '钻井日报';
    -- Add comments to the columns 
    comment on column P_ZJRB.WELLNO
      is '单井编码';
    comment on column P_ZJRB.USEUNITID
      is '机构编码';
    comment on column P_ZJRB.RBXH
      is '日报序号';
    comment on column P_ZJRB.RBRQ
      is '日报日期';
    comment on column P_ZJRB.ZZRQ
      is '终止日期';
    comment on column P_ZJRB.ZZJS
      is '终止井深';
    comment on column P_ZJRB.LJJC
      is '全日累计进尺';
    comment on column P_ZJRB.DC
      is '地层';
    comment on column P_ZJRB.ZTXINGH
      is '钻头型号';
    comment on column P_ZJRB.ZTXJ
      is '钻头新旧';
    comment on column P_ZJRB.ZTCC
      is '钻头尺寸';
    comment on column P_ZJRB.QSJS
      is '起始井深';
    comment on column P_ZJRB.GZNR
      is '工作内容';
    comment on column P_ZJRB.ZDTS
      is '重点提示';
    comment on column P_ZJRB.ANJL
      is '安全监理';
    comment on column P_ZJRB.ZBGB
      is '值班干部';
    comment on column P_ZJRB.GZZT
      is '工作状态';
    comment on column P_ZJRB.ZS
      is '转数';
    comment on column P_ZJRB.BY1
      is '泵压';
    comment on column P_ZJRB.PL
      is '排量';
    comment on column P_ZJRB.ZY
      is '钻压';
    comment on column P_ZJRB.ZJYMD
      is '钻井液密度';
    comment on column P_ZJRB.QYJS
      is '取样井深';
    comment on column P_ZJRB.SXZD
      is '塑性粘度';
    comment on column P_ZJRB.HSL
      is '含砂量';
    comment on column P_ZJRB.ZYSS
      is '失水';
    comment on column P_ZJRB.NB
      is '泥饼';
    comment on column P_ZJRB.QL10M
      is '初切(10秒静切力)';
    comment on column P_ZJRB.QL10F
      is '终切(10分切力)';
    comment on column P_ZJRB.DQL
      is '动切力';
    comment on column P_ZJRB.PHZ
      is 'PH值';
    comment on column P_ZJRB.LDZD
      is '漏斗粘度';
    comment on column P_ZJRB.XZZDJ3ZD
      is '旋转粘度计3转读数';
    comment on column P_ZJRB.XZZDJ300
      is '旋转粘度计300转读数';
    comment on column P_ZJRB.XZZDJ600
      is '旋转粘度计600转读数';
    comment on column P_ZJRB.BSFLAG
      is '报送标志';
    comment on column P_ZJRB.COMNAME
      is '公司名称(储存井队上级机构ID号)';
    comment on column P_ZJRB.ZJRBSHR
      is '审核人';
    -- Create/Recreate primary, unique and foreign key constraints 
    alter table P_ZJRB
      add constraint PK_P_ZJRB primary key (WELLNO,USEUNITID,RBXH)
      using index 
      tablespace USERS
      pctfree 10
      initrans 2
      maxtrans 255
      storage
      (
        initial 6528K
        next 128K
        minextents 1
        maxextents unlimited
        pctincrease 0
      );
    alter table P_ZJRB
      add constraint FK_P_ZJRB_RELATIONS_USEUNITC foreign key (USEUNITID)
      references USEUNITCODE (USEUNITID) on delete cascade;
    -- Create/Recreate indexes 
    create index RELATIONSHIP_127_FK on P_ZJRB (WELLNO)
      tablespace USERS
      pctfree 10
      initrans 2
      maxtrans 255
      storage
      (
        initial 4M
        next 128K
        minextents 1
        maxextents unlimited
        pctincrease 0
      );
    create index RELATIONSHIP_128_FK on P_ZJRB (USEUNITID)
      tablespace USERS
      pctfree 10
      initrans 2
      maxtrans 255
      storage
      (
        initial 4608K
        next 128K
        minextents 1
        maxextents unlimited
        pctincrease 0
      );
      

  5.   

    tablespace USERS
    USERS
    这个表空间的含义究竟是什么?
    搞明白了这个问题就结帖
      

  6.   

    说错了,应该是
    USERS
    这个表空间名称的含义究竟是什么?
    搞明白了这个问题就结帖
      

  7.   

    数据对象(表、索引等)是存放在表空间里面的
    创建表空间
    create tablespace spname datafile 'c:\oracle\datafile\data1.ora'
    size 10M ...;
      

  8.   

    bzszp(www.bzszp.533.net) 
    您理解错了,我想知道表空间USERS 和前面老兄用到的EM_DATA有什么不同,既然在下面给出了详细定义了,为什么还要指定名称?
      

  9.   

    CREATE TABLE 生产商
    (       编码 VARCHAR2(8),
    名称 VARCHAR2(40),
    简码 VARCHAR2(40),
            地址 varchar2(50),
            联系人 varchar2(20),
            联系方式 varchar2(20))
    PCTFREE 5 
    PCTUSED 90
    STORAGE (INITIAL 256 NEXT 128 PCTINCREASE 0)
    TABLESPACE MErc; 
    ALTER TABLE 生产商 ADD CONSTRAINT 生产商_UQ_编码 UNIQUE (编码) USING INDEX PCTFREE 10 TABLESPACE MErc; 
    ALTER TABLE 生产商 ADD CONSTRAINT 生产商_UQ_名称 UNIQUE (名称) USING INDEX PCTFREE 10 TABLESPACE MErc; 
    create public synonym 生产商 for 生产商;
    是不是这个样子的。
    另外如果用的话再加其它的外键。
      

  10.   

    pl/sql用户指南与参考.  上面有各种数据库对象的详细介绍.