SQL Primary Key Issue
-
Hello,
I have imported a CSV file into SQL, the wizard has added this as a new table.
I am trying to run a SQL Statement to insert the data from the imported table into the one I need to use in the new data table.
However I am getting the following error.
Collapse | Copy Code
Msg 2627, Level 14, State 1, Line 4
Violation of PRIMARY KEY constraint 'PK_Customer'. Cannot insert duplicate key in object 'dbo.Customer'. The duplicate key value is (105).
The statement has been terminated.This is my statement:
Collapse | Copy Code
INSERT INTO dbo.Customer
(custID,lastName,firstName,title,address1,address2,address3,postCode,email,fax)
SELECT ACCOUNT,SURNAME,FORENAMES,TITLE,ADD1,ADD2,ADD3,POSTCODE,EMAIL,FAX
FROM dbo.[NCCUST CSV FORMAT PFS 9.1.14];Any pointers would be great Smile | :)
Thanks
-
Hello,
I have imported a CSV file into SQL, the wizard has added this as a new table.
I am trying to run a SQL Statement to insert the data from the imported table into the one I need to use in the new data table.
However I am getting the following error.
Collapse | Copy Code
Msg 2627, Level 14, State 1, Line 4
Violation of PRIMARY KEY constraint 'PK_Customer'. Cannot insert duplicate key in object 'dbo.Customer'. The duplicate key value is (105).
The statement has been terminated.This is my statement:
Collapse | Copy Code
INSERT INTO dbo.Customer
(custID,lastName,firstName,title,address1,address2,address3,postCode,email,fax)
SELECT ACCOUNT,SURNAME,FORENAMES,TITLE,ADD1,ADD2,ADD3,POSTCODE,EMAIL,FAX
FROM dbo.[NCCUST CSV FORMAT PFS 9.1.14];Any pointers would be great Smile | :)
Thanks
Well, the error says it all. There are obviously 2 customers with the value 105 in the ACCOUNT field in the 'CSV' table. You need to either remove the Primary key restraint on dbo.customer (not recommended) or remove one of the customers in the 'CSV' table with ACCOUNT 105.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
-
Hello,
I have imported a CSV file into SQL, the wizard has added this as a new table.
I am trying to run a SQL Statement to insert the data from the imported table into the one I need to use in the new data table.
However I am getting the following error.
Collapse | Copy Code
Msg 2627, Level 14, State 1, Line 4
Violation of PRIMARY KEY constraint 'PK_Customer'. Cannot insert duplicate key in object 'dbo.Customer'. The duplicate key value is (105).
The statement has been terminated.This is my statement:
Collapse | Copy Code
INSERT INTO dbo.Customer
(custID,lastName,firstName,title,address1,address2,address3,postCode,email,fax)
SELECT ACCOUNT,SURNAME,FORENAMES,TITLE,ADD1,ADD2,ADD3,POSTCODE,EMAIL,FAX
FROM dbo.[NCCUST CSV FORMAT PFS 9.1.14];Any pointers would be great Smile | :)
Thanks
-
Hello,
I have imported a CSV file into SQL, the wizard has added this as a new table.
I am trying to run a SQL Statement to insert the data from the imported table into the one I need to use in the new data table.
However I am getting the following error.
Collapse | Copy Code
Msg 2627, Level 14, State 1, Line 4
Violation of PRIMARY KEY constraint 'PK_Customer'. Cannot insert duplicate key in object 'dbo.Customer'. The duplicate key value is (105).
The statement has been terminated.This is my statement:
Collapse | Copy Code
INSERT INTO dbo.Customer
(custID,lastName,firstName,title,address1,address2,address3,postCode,email,fax)
SELECT ACCOUNT,SURNAME,FORENAMES,TITLE,ADD1,ADD2,ADD3,POSTCODE,EMAIL,FAX
FROM dbo.[NCCUST CSV FORMAT PFS 9.1.14];Any pointers would be great Smile | :)
Thanks
Well, the error says it all. There are obviously 2 customers with the value 105 in the ACCOUNT field in the 'CSV' table. You need to either remove the Primary key restraint on dbo.customer (not recommended) or remove one of the customers in the 'CSV' table with ACCOUNT 105.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman