-
Sep 4th, 2020, 04:51 AM
#1
Thread Starter
Fanatic Member
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 ?
-
Sep 4th, 2020, 06:49 AM
#2
Re: Why do I copy Table1 contents to Table with the error ?
What is the definition of the table TABQUANHEGD I will be that there is a foreign key named FK_TABKHOKIEMKECT_TABKHOKIEMKE on the table that references table TABQUANHEGDTT. If you do not want the key in place drop it.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Sep 6th, 2020, 08:41 PM
#3
Thread Starter
Fanatic Member
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
-
Sep 7th, 2020, 11:23 PM
#4
Lively Member
Re: Why do I copy Table1 contents to Table with the error ?
it's worked good for me
plz try this :
HTML Code:
INSERT INTO DB2.TB1 SELECT * from DB1.TB1;
-
Sep 8th, 2020, 12:11 AM
#5
Re: Why do I copy Table1 contents to Table with the error ?
Originally Posted by dong
In my data there are no these 2 Tables: "FK_TABKHOKIEMKECT_TABKHOKIEMKE" and I have not created a relationship to the Table TABQUANHEGDTT
The error message is telling you that the destination has a foreign key with that name and you are not honouring it. The fix is either to get rid of that foreign key or to honour it. It sounds like you don't want it so you should probably get rid of it. Stop talking about what tables you do and don't have because that's irrelevant. Look for the foreign key with that name as you should have done the moment you saw that error message and also when GaryMazzone told you to. While foreign keys are generally named after the tables they relate, they don't have to be so that you don't have tables that match the foreign key name is irrelevant.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|