Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2005
    Posts
    26

    Unanswered: foreign key question

    Is there anway to add a foreign key to a table and forcing it not to check every row for validation? I know there is a NO VALIDATE on an enable foreign key, but will this work on an addition of a foreign key?

  2. #2
    Join Date
    Nov 2005
    Posts
    17
    Did you try it?

    Code:
    SQL> CREATE TABLE t (c NUMBER PRIMARY KEY);
    
    Table created.
    
    SQL> CREATE TABLE r (c NUMBER);
    
    Table created.
    
    SQL> INSERT INTO t VALUES (1);
    
    1 row created.
    
    SQL> INSERT INTO r VALUES (4);
    
    1 row created.
    
    SQL> ALTER TABLE r
      2  ADD CONSTRAINT r_fk
      3  FOREIGN KEY (c)
      4  REFERENCES t (c)
      5  ENABLE NOVALIDATE;
    
    Table altered.
    
    SQL> INSERT INTO r VALUES (2);
    INSERT INTO r VALUES (2)
    *
    ERROR at line 1:
    ORA-02291: integrity constraint (SCOTT.R_FK) violated - parent key not found
    
    
    SQL> INSERT INTO r VALUES (1);
    
    1 row created.
    Guess it works

  3. #3
    Join Date
    Oct 2005
    Posts
    26

    thanks

    thanks for the info

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •