How to delete records with foriegn key constraint in Mysql?

Discussion in 'MySQL' started by computerzworld, Oct 1, 2007.

  1. #1
    Hi. I have two tables with primary-foreign key constraint. I want to forcibly delete these values without considering this relationship. Is there any way to delete these values? Please reply me. Thanks.
     
    computerzworld, Oct 1, 2007 IP
  2. gostats

    gostats Peon

    Messages:
    325
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Have your tried altering the table to disable the constraint - manipulate your data and then re-add the contraint?
    -But why do you want to delete these values without considering the relationship? If so, what is the purpose of this relationship in the first place?
     
    gostats, Oct 3, 2007 IP
  3. ValDD

    ValDD Banned

    Messages:
    171
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    As far as I know, no real way to do this. You have 2 options:
    1) Obey the constraint and delete the foreign records too
    2) The foreign constraint is just wrong and doesn't belong there. So just remove the constraint.
     
    ValDD, Oct 10, 2007 IP
  4. trailerpark

    trailerpark Peon

    Messages:
    37
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It is a relational database so it's main purpose is to enforce the relationship between the set of tables.

    So, like the other posters have said, you have to alter the table constraints and break the relationship between the tables.
     
    trailerpark, Oct 11, 2007 IP