dropping a foreign key in mysql table(innodb engine)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pradeepjain
    Contributor
    • Jul 2007
    • 563

    dropping a foreign key in mysql table(innodb engine)

    hii i need to drop a foreign key for a table and create a new foreign key how do i do it ..i tried
    Code:
     SHOW TABLE STATUS FROM ratingd LIKE 'fourwheeler_rating';
    +--------------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+-----------------------+
    | Name               | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time         | Update_time | Check_time | Collation       | Checksum | Create_options | Comment               |
    +--------------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+-----------------------+
    | fourwheeler_rating | InnoDB |      10 | Compact    |    0 |              0 |       16384 |               0 |        16384 |         0 |              1 | 2010-03-16 15:54:11 | NULL        | NULL       | utf8_unicode_ci |     NULL |                | InnoDB free: 41984 kB | 
    +--------------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+-----------------------+
    1 row in set (0.01 sec)
    they asked to check the comment column for the foreign key so as to delete it by using

    Code:
    alter table  fourwheeler_rating drop foreign key 0_172;

    but the comment column consist of anything like the code...any help on this?
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    I didn't really understand what the problem was, but for instructions on how to drop foreign keys, see: 13.6.4.4. FOREIGN KEY Constraints in the manual.

    Comment

    • pradeepjain
      Contributor
      • Jul 2007
      • 563

      #3
      the foreign keys were combination of 2 keys earlier.i need to make it a combination of 3 .so need to change it,

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Then you drop it, as described in the link I posted earlier, and re-create it.

        Comment

        • pradeepjain
          Contributor
          • Jul 2007
          • 563

          #5
          which is the correct method to create a foreign key which is a combination of fields?

          i basically do like foreign key(property1,p roperty2,proper ty3) references table1(property 1,property2,pro perty3) is this the correct way

          ?

          Comment

          Working...