4
Answers

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
  1. INSERT INTO TABQUANHEGD(IDQHGD, MASTT, NGUOITHAN, NGAYSINH, MAGT, MAQH, MAQT, OHIENTAI, NGHENGHIEP, NOILAM, DIENTHOAI, TRUGIACANH, NGAYBD, NGAYKT, LIENHE, DAMAT, ANH, GHICHU)  
  2. 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 ? 

Answers (4)

3
Photo of Nilesh Shah
13 54.3k 1.4m 4y
hi
 
It seems there's a trigger on table  TABQUANHEGD which inserts something into table
TABQUANHEGDTT.
 
I think you are only given limited access in database hence you dont see other tables
3
Photo of Nisha Regil
868 857 21.3k 4y
The error message says that there is table TABQUANHEGDTT in database "NhanSu" with FOREIGN KEY constraint "FK_TABKHOKIEMKECT_TABKHOKIEMKE".
 
So isue is occurring due to that constraint. If not needed you can drop that constraint from TABQUANHEGDTT table.
2
Photo of Dong Lam Trien
794 986 161.6k 4y
I have not created a relationship for the tables yet, here is my data file, you see my attached file
 http://www.mediafire.com/file/4a4fj4en9zlxzki/DatabaseErr.rar/file
2
Photo of Dong Lam Trien
794 986 161.6k 4y
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?