你真懒!ALTER TABLE JL.EMP 
    ADD CONSTRAINT SYS_C005888
    FOREIGN KEY (JOB)
    REFERENCES JL.EMP_P (JOB)
     ON DELETE CASCADE
/ALTER TABLE STGAJK.USERB
    ADD     CONSTRAINT K_USERB
    PRIMARY KEY (USERID)
        USING INDEX PCTFREE 10
                    INITRANS 2
                    MAXTRANS 255
                    TABLESPACE TBS
                    STORAGE(INITIAL 16K
                           NEXT 16K
                           MINEXTENTS 1
                           MAXEXTENTS 121
                           PCTINCREASE 50
                           FREELISTS 1
                           FREELIST GROUPS 1
                           BUFFER_POOL DEFAULT)
LOGGING
/

解决方案 »

  1.   

    alter table add primary key(a);
    alter table add constraint 外键约束名 foreign key (b) reference test2 (b);
      

  2.   

    CREATE TABLE SCOTT.EMP
    (
        EMPNO                          NUMBER(4,0) NOT NULL,
        ENAME                          VARCHAR2(10),
        JOB                            VARCHAR2(9),
        MGR                            NUMBER(4,0),
        HIREDATE                       DATE,
        SAL                            NUMBER(7,2),
        COMM                           NUMBER(7,2),
        DEPTNO                         NUMBER(2,0),
        CONSTRAINT FK_DEPTNO FOREIGN KEY (DEPTNO) REFERENCES SCOTT.DEPT (DEPTNO),
        CONSTRAINT PK_EMP PRIMARY KEY (EMPNO)
    )
    /
      

  3.   

    例:
    CREATE TABLE classes (
      department       CHAR(3),
      course           NUMBER(3),
      description      VARCHAR2(2000),
      max_students     NUMBER(3),
      current_students NUMBER(3),
      num_credits      NUMBER(1),
      room_id          NUMBER(5),
      CONSTRAINT classes_department_course
        PRIMARY KEY (department, course),
      CONSTRAINT classes_room_id
        FOREIGN KEY (room_id) REFERENCES rooms (room_id)
      );
      

  4.   

    -- Create table
    create table T_PXRS
    (
      XMBH   CHAR(20) not null,
      JGBH   CHAR(15) not null,
      XQRS   NUMBER,
      SZDWBH CHAR(15)
    )
    tablespace USERS
      pctfree 10
      pctused 40
      initrans 1
      maxtrans 255
      storage
      (
        initial 128K
        next 128K
        minextents 1
        maxextents 4096
        pctincrease 0
      );
    -- Create/Recreate primary, unique and foreign key constraints 
    alter table T_PXRS
      add primary key (XMBH,JGBH)
      using index 
      tablespace USERS
      pctfree 10
      initrans 2
      maxtrans 255
      storage
      (
        initial 128K
        next 128K
        minextents 1
        maxextents 4096
        pctincrease 0
      );
    -- Create/Recreate indexes 
    create index XIF39T_PXRS on T_PXRS (JGBH)
      tablespace USERS
      pctfree 10
      initrans 2
      maxtrans 255
      storage
      (
        initial 128K
        next 128K
        minextents 1
        maxextents 4096
        pctincrease 0
      );
    create index XIF9T_PXRS on T_PXRS (XMBH)
      tablespace USERS
      pctfree 10
      initrans 2
      maxtrans 255
      storage
      (
        initial 128K
        next 128K
        minextents 1
        maxextents 4096
        pctincrease 0
      );