Results 1 to 2 of 2

Thread: Constraint

  1. #1
    Join Date
    May 2013
    Posts
    33

    Unanswered: Constraint

    Code:
    SQL> create table me(id number primary key);
    
    Table created.
    
    SQL> create table u(id number references me(id));
    
    Table created.
    
    SQL> insert into me values(10);
    
    1 row created.
    
    SQL> insert into me values(20);
    
    1 row created.
    
    SQL> select * from me;
    
            ID
    ----------
            10
            20
    
    SQL>  insert into u values(10);
    
    1 row created.
    
    SQL> insert into u values(20);
    
    1 row created.
    
    SQL> select * from me;
    
            ID
    ----------
            10
            20
    
    SQL> select * from u;
    
            ID
    ----------
            10
            20
    
    SQL> Alter table u 
      2  add constraint fk_id id references me(id) on delete cascade;
    add constraint fk_id id references me(id) on delete cascade
                         *
    ERROR at line 2:
    ORA-01430: column being added already exists in table
    
    SQL> alter table u modify(id references me(id) on delete cascade);
    alter table u modify(id references me(id) on delete cascade)
                            *
    ERROR at line 1:
    ORA-02275: such a referential constraint already exists in the table
    Look at my above code and tell me how to alter my foreign key table to add ON DELETE CASCADE option to it.

    Help me friends....

  2. #2
    Join Date
    Jul 2013
    Posts
    11
    Hi,

    Try using the following command:

    alter table u add constraint fk_id FOREIGN KEY (id) REFERENCES me(id) ON DELETE CASCADE;

    I think FOREIGN KEY was missing in your statement.

    Regards,
    Supreeth K

Posting Permissions

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