Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jul 2005
    Location
    GMT +7
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Error deleting record due to FK constraint

    I'm getting an error in deleting a record from Customers table (or other tables such as Categories) in Northwind database of SQL Server, due to foreign key constraint. How can I solve it? Thanks a lot!

  • #2
    eak
    eak is offline
    Regular Coder eak's Avatar
    Join Date
    Jun 2002
    Location
    Nashville, TN
    Posts
    354
    Thanks
    0
    Thanked 26 Times in 26 Posts
    It sounds like there is a row in another table that needs the row your trying to delete. You could try deleting the referencing row(s) first then delete the record from the customers table.

    It would help to see the table structure to be sure though.
    eak | "Doing a good deed is like wetting your pants; every one can see the results, but only you can feel the warmth."

  • #3
    New Coder
    Join Date
    Jul 2005
    Location
    GMT +7
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by eak
    It sounds like there is a row in another table that needs the row your trying to delete.
    Right. What if I dont know in advance which tables have that row? How can I play around with this?

    Thanks a lot.

  • #4
    eak
    eak is offline
    Regular Coder eak's Avatar
    Join Date
    Jun 2002
    Location
    Nashville, TN
    Posts
    354
    Thanks
    0
    Thanked 26 Times in 26 Posts
    how can you not know what rows? its your database right?
    eak | "Doing a good deed is like wetting your pants; every one can see the results, but only you can feel the warmth."

  • #5
    New Coder
    Join Date
    Jul 2005
    Location
    GMT +7
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm just testing with the classic Northwind db in SQL Server. Seems I need to study the whole db and check the related tables for deletion.
    I wanted to know if there's an easier way.

    Thanks a lot!

  • #6
    eak
    eak is offline
    Regular Coder eak's Avatar
    Join Date
    Jun 2002
    Location
    Nashville, TN
    Posts
    354
    Thanks
    0
    Thanked 26 Times in 26 Posts
    I am unfamiliar with this Northwind db and I have never use SQL Server (even though I have it on CD somewhere...).
    I know that you can find the reationships with MySQL with this: SHOW TABLE STATUS FROM your_db_name [like 'tabe_name'];

    I don't know what the SQL Server command is for the same thing. I noticed MySQL does things a little differently from my time using Oracle.
    eak | "Doing a good deed is like wetting your pants; every one can see the results, but only you can feel the warmth."

  • #7
    New Coder
    Join Date
    Jul 2005
    Location
    GMT +7
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a lot! I'll check it out.


  •  

    Posting Permissions

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