SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: SQL Delete

  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2009
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SQL Delete

    Not sure how to word this but...

    1. Trying to Delete any rows from authorsLName of Hull.

    Code SQL:
    DELETE FROM authors WHERE authorsLName = "Hull"

    However get this error:

    Code:
    Cannot delete or update a parent row: a foreign key constraint fails (`books_database/titleauthors`, CONSTRAINT `titleauthors_ibfk_2` FOREIGN KEY (`taAuthorID`) REFERENCES `authors` (`authorID`))
    I have a few other tables which it's drawing the foreign keys from but not sure how else to do it. Not sure if it will be any help but I've attached a file that contains the table and column names if that's any help.

    2. I'm also having trouble with working out how to DELETE the rows with books published by publisher PO1 or PO4 from the table title_authors.

    Thanks.
    Last edited by pritnep; Mar 6, 2009 at 03:56.

  2. #2
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    13.2.5.4. FOREIGN KEY Constraints of the MySQL 5.0 Reference manual might be of help.

    regards
    /k

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,247
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    your foreign key says that you cannot delete an author who has books
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2009
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got it working now, typo in the column name.

    And got the other done.


Bookmarks

Posting Permissions

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