CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Sep 2007
    Posts
    405

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

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

    Code:
      
    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 ?

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Why do I copy Table1 contents to Table with the error ?

    What are the table definitions?

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Why do I copy Table1 contents to Table with the error ?

    Quote Originally Posted by dongtrien View Post
    I have 2 Tables: TABQUANHEGD: destination and TABNGUON: source
    ...
    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
    You have to look at the table TABQUANHEGDTT as it is stated in the error message!
    So as Arjay already asked you, please show us the definitions of the tables:
    TABQUANHEGD
    TABNGUON
    TABQUANHEGDTT
    Victor Nijegorodov

  4. #4
    Join Date
    Sep 2007
    Posts
    405

    Re: Why do I copy Table1 contents to Table with the error ?

    In my data there are no these 2 Tables: "FK_TABKHOKIEMKECT_TABKHOKIEMKE" and I have not created a relationship to the Table TABQUANHEGDTT, how to fix this? you see my database attachment.
    http://www.mediafire.com/file/4a4fj4...seErr.rar/file

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Why do I copy Table1 contents to Table with the error ?

    Quote Originally Posted by dongtrien View Post
    In my data there are no these 2 Tables: "FK_TABKHOKIEMKECT_TABKHOKIEMKE" and I have not created a relationship to the Table TABQUANHEGDTT, how to fix this? you see my database attachment.
    http://www.mediafire.com/file/4a4fj4...seErr.rar/file
    Again, please attach files DIRECTLY to this site. If you put files in a 3rd party site we can't help you.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Why do I copy Table1 contents to Table with the error ?

    Quote Originally Posted by dongtrien View Post
    In my data there are no these 2 Tables: "FK_TABKHOKIEMKECT_TABKHOKIEMKE" and I have not created a relationship to the Table TABQUANHEGDTT
    "FK_TABKHOKIEMKECT_TABKHOKIEMKE" is not a table name. It is a key (relation) name.

    Quote Originally Posted by dongtrien View Post
    ... you see my database attachment.
    http://www.mediafire.com/file/4a4fj4...seErr.rar/file
    Please, attach it to your post in this Forum! Read the Announcement: Before you post.....
    Victor Nijegorodov

  7. #7
    Join Date
    Sep 2007
    Posts
    405

    Re: Why do I copy Table1 contents to Table with the error ?

    Attached file 10MB website server cannot be uploaded, upload is suspended, so I use the 3rd service

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Why do I copy Table1 contents to Table with the error ?

    Quote Originally Posted by dongtrien View Post
    Attached file 10MB website server cannot be uploaded, upload is suspended, so I use the 3rd service
    What did you try to upload? The whole database?

    I have no idea how it was implemented in SQL Server 2005 (and why are you still using it!?)
    In 2008 and later versions it is like:
    Attachment 35899
    Victor Nijegorodov

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured