If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > constraints

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-24-08, 13:31
jaguar_miraj jaguar_miraj is offline
Registered User
 
Join Date: May 2008
Posts: 1
constraints

hey frens !
i have a command ....
ALTER TABLE
DISABLE CONSTRAINT constraint CASCADE;


now if i have two table with foreign key relationship den plzz tell me which constraint to disable and when n why to use "cascade".
Reply With Quote
  #2 (permalink)  
Old 05-24-08, 14:40
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
plzz stop da shorthands

i have the answers, let me show you them

which constraint to disable? i don't know... which ones have you got?

when to disable them? when you don't want them any more ever

why to use cascade? if you only want to disable them temporarily


which database system are you using?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 05-27-08, 05:47
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
The CASCADE option allows you to drop a primary key or unique constraint that is referenced by foreign key constraints: the referencing foreign key constraints are also dropped.

Example (Oracle):
Code:
SQL> create table a (aid integer, constraint a_pk primary key (aid));

Table created.

SQL> create table b (bid integer, aid integer,
  2  constraint b_pk primary key (bid),
  3  constraint b_fk foreign key(aid) references a);

Table created.

SQL> select constraint_name from user_constraints where table_name='B';

CONSTRAINT_NAME
------------------------------
B_FK
B_PK

SQL> insert into a values (1);

1 row created.

SQL> insert into b values (11,1);

1 row created.

SQL> alter table a drop constraint a_pk;
alter table a drop constraint a_pk
                              *
ERROR at line 1:
ORA-02273: this unique/primary key is referenced by some foreign keys


SQL> alter table a drop constraint a_pk CASCADE;

Table altered.

SQL> select constraint_name from user_constraints where table_name='B';

CONSTRAINT_NAME
------------------------------
B_PK
As you can see, dropping the primary key of A with cascade caused the foreign key referencing A from B to be dropped also.
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On