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 > Database Server Software > DB2 > Drop foreign key in some tables.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-27-11, 15:04
georgipa georgipa is offline
Registered User
 
Join Date: Dec 2002
Location: Madrid - Spain
Posts: 282
Drop foreign key in some tables.

Hi Colleagues,

Somebody can say me what in the best method to drop all foreign key in one or more tables in db2 9.5.

Thank you for advanced.
Reply With Quote
  #2 (permalink)  
Old 02-28-11, 09:40
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
If you don't need the tables, just drop the tables. Otherwise, ALTER TABLE ... DROP CONSTRAINT ...
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #3 (permalink)  
Old 02-28-11, 15:28
georgipa georgipa is offline
Registered User
 
Join Date: Dec 2002
Location: Madrid - Spain
Posts: 282
I have database with 1000 tables, i need drop the foreign key for tables xxx, table yyy and table zzz. Not for all tables.

Thank you for advanced.
Reply With Quote
  #4 (permalink)  
Old 03-01-11, 06:43
dr_te_z dr_te_z is offline
Registered User
 
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
You can run db2look and extract to FK-data. Or run this query:
Code:
select varchar(  
  'alter table  '  
|| lcase(rtrim(a.fktable_name))
|| space (32 - length(rtrim(a.fktable_name)))
|| 'drop constraint '  
|| lcase(rtrim(a.fk_name))
|| ';' 
,80) as cmdline 
from	sysibm.sqlforeignkeys a
where key_seq = 1
and	(   (pktable_schem = current_schema and pktable_name in ('XXX' , 'YYY'))
         or (fktable_schem = current_schema and fktable_name in ('XXX' , 'YYY'))
);
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