Results 1 to 3 of 3

Thread: Constraints

  1. #1
    Join Date
    May 2013
    Posts
    33

    Unanswered: Constraints

    Hi Everyone,

    Here, i am having doubt in the constraints:

    SQL> create table a(id number primary key,name varchar(20));

    Table created.

    SQL> create table b(id number references a(id) , name varchar(20));

    Table created.


    Here i have created 2 tables in which table b references to table a....Now i want to drop foreign key constraint in table b.I mean i dont want table b ID to refer table a ID primary key.



    suggest me with solution.

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Query USER_CONSTRAINTS and then, when you locate constraint you need, drop it:
    Code:
    SQL> select constraint_name, constraint_type from user_constraints where table_name = 'B';
    
    CONSTRAINT_NAME                C
    ------------------------------ -
    SYS_C00188644                  R
    
    SQL> alter table b drop constraint SYS_C00188644;
    
    Table altered.
    
    SQL>
    It would be MUCH simpler if you named constraints, such as:
    Code:
    SQL> create table a
      2    (id   number constraint pk_a primary key,
      3     name varchar(20));
    
    Table created.
    
    SQL> create table b
      2    (id   number constraint fk_ba references a(id),
      3     name varchar(20));
    
    Table created.
    
    SQL> alter table b drop constraint fk_ba;
    
    Table altered.
    
    SQL>

  3. #3
    Join Date
    May 2013
    Posts
    33
    Thanks MR.LittleFoot.....

Posting Permissions

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