Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2008
    Posts
    11

    Unanswered: deletion from 2 tables in a single query

    I wants to know if we can delete data from 2 tables using a single delete query ?is it possible?

  2. #2
    Join Date
    Jan 2008
    Posts
    11
    actually i have to delete data from hd_spares table and hd_Receiving table

    hd_spare table contains
    SNo(PK)SerialNo ,ModelNo,Receiving_Id

    hd_Receiving table contains
    Receiving_Id,ReceivedBy,EquipmentDetail

    when i write query like this
    delete from HD_Receiving where Receiving_ID=81

    error is:
    DELETE statement conflicted with COLUMN REFERENCE constraint 'FK_HD_Spares_HD_Receiving'. The conflict occurred in database 'LNH_Helpdesk', table 'HD_Spares', column 'Receiving_Id'.
    The statement has been terminated.

    now what can i do to delete row from both tables

  3. #3
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    You need to delete from hd_spares before you can delete from hd_receiving.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    alternatively, go back and redefine the constraint so that it specifies ON DELETE CASCADE

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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