Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2002
    Location
    Madrid - Spain
    Posts
    422
    Provided Answers: 1

    Unanswered: 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.

  2. #2
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    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

  3. #3
    Join Date
    Dec 2002
    Location
    Madrid - Spain
    Posts
    422
    Provided Answers: 1
    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.

  4. #4
    Join Date
    Jan 2009
    Location
    Zoetermeer, Holland
    Posts
    746
    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'))
    );

Posting Permissions

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