locked
Why do I copy Table1 contents to Table with the error ? RRS feed

  • Question


  • I have 2 Tables: TABQUANHEGD: destination and TABNGUON: source
    I implemented sql in SQL Server 2005 with an error

    INSERT INTO TABQUANHEGD(IDQHGD, MASTT, NGUOITHAN, NGAYSINH, MAGT, MAQH, MAQT, OHIENTAI, NGHENGHIEP, NOILAM, DIENTHOAI, TRUGIACANH, NGAYBD, NGAYKT, LIENHE, DAMAT, ANH, GHICHU) 
    SELECT IDQHGD, MASTT, NGUOITHAN, NGAYSINH, MAGT, MAQH, MAQT, OHIENTAI, NGHENGHIEP, NOILAM, DIENTHOAI, TRUGIACANH, NGAYBD, NGAYKT, LIENHE, DAMAT, ANH, GHICHU FROM TABNGUON;

    Msg 547, Level 16, State 0, Line 1
    The INSERT statement conflicted with the FOREIGN KEY constraint "FK_TABKHOKIEMKECT_TABKHOKIEMKE". The conflict occurred in database "NhanSu", table "dbo.TABQUANHEGDTT", column 'IDQH'.
    The statement has been terminated.

    In the database I don't have these 2 tables:
    TABKHOKIEMKECT
    TABKHOKIEMKE
    I don't know where to get these 2 Tables to report an error
    I want to copy the content from Table1 to Table2, how do I write an SQL query ?


    Monday, September 7, 2020 1:19 AM

Answers