Violation of PRIMARY KEY constraint

For example, if I have taken the sample data as given below, taken the Sno as a PK in query transform.  Violation of PRIMARY KEY constraint.

Sno;Country;Date;Sales

1;USA;2010.01.12;100

2;INDIA;2011.12.31;100

3;SINGAPORE;2012.09.02;200

4;AUSTRALIA;2013.05.21;600

5;UK;2014.12.05;100

6;CANADA;2010.01.12;100

7;JAPAN;2011.12.31;1200

8;GERMANY;2012.09.02;600

9;SWITZERLAND;2013.05.21;800

10;THAILAND;2014.12.05;1200

6;CANADA-USA;2010.01.12;100

7;JAPAN-ASEA;2011.12.31;1200

8;GERMANY-EU;2012.09.02;600

9;SWITZERLAND-EU;2013.05.21;800

10;THAILAND-ASEA;2014.12.05;1200

Untitled.png

Reason is because of Sno of 10,9,8,7 and 6 as shown in the sample data.

So we need to consider those records only once. Or eliminate Sno column and load the data with new surrogate key.

Finding Duplicate Rows:

Load the data by unchecking PK definition of the Sno column and load the data.

Execute the below SQL once you have loaded the data.

Capture.JPG

Advertisements

One thought on “Violation of PRIMARY KEY constraint

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.