dbTalk Databases Forums  

violation of primary key constraint

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss violation of primary key constraint in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Douglas Gaynor
 
Posts: n/a

Default violation of primary key constraint - 08-11-2003 , 11:19 AM






While attempting to use DTS, to import an ASCII text
file, comma delimited, I get this error.

violation of primary key constraint

I checked the file, it is perfect. The problem was, we
had to restore a database to an earlier date, due to
problems, we later found were caused by a user.

After restoring, they starting adding information into it.

The OLD database, the one we thought was grunged, and
unfixable, was backed up to a test server. After making
sure everything was OK, we used DTS to export the
information contained in it, that was needed to bring the
database in use, up to date. Why me???? It just won't
work. Currently running SQL 7, SP2.

Reply With Quote
  #2  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: violation of primary key constraint - 08-12-2003 , 01:18 AM






Not sure if I understand but

You have a text file of information
You have a table that needs to receive the information
You try and it vio;ates the PK constraint.

How'm I doing ?

I would

1. Grab the definition of the PK from the table
2. Check the for duplicates. If as you say this is clean then it has to be
in the table
3. Import the file into a staging area (exact match of the real table)(BTW
this is what I always do with a text file)
4. Now using TSQL do a comparison on Key columns using an INNER join
between the two tables.
5 The records you get back are the violations



--

----------------------------
Allan Mitchell (Microsoft SQL Server MVP)
MCSE,MCDBA
www.SQLDTS.com
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org



"Douglas Gaynor" <doug (AT) q-express (DOT) net> wrote

Quote:
While attempting to use DTS, to import an ASCII text
file, comma delimited, I get this error.

violation of primary key constraint

I checked the file, it is perfect. The problem was, we
had to restore a database to an earlier date, due to
problems, we later found were caused by a user.

After restoring, they starting adding information into it.

The OLD database, the one we thought was grunged, and
unfixable, was backed up to a test server. After making
sure everything was OK, we used DTS to export the
information contained in it, that was needed to bring the
database in use, up to date. Why me???? It just won't
work. Currently running SQL 7, SP2.



Reply With Quote
  #3  
Old   
Douglas Gaynor
 
Posts: n/a

Default Importing data with DTS - 08-12-2003 , 07:36 AM



Close. The text file with information came from using a
copy of the SAME database, but contains information that
is NOT in the database that is in use.

The main problem is, I know close to nothing about SQL.

1. We had a database that "APPEARED" to be corrupt. We
backed it up, and restored it to an SQL test bed.

2. We restored a copy of the database, from 4 days
previous.

3. I used DTS on the Test Server, to export the missing 4
days of data

4. I cannot import it into the operational database,
because of the primary key constraint error.

5. I am now considering weapons of mass destruction.

Thanks.. <G>

********************************
Not sure if I understand but

You have a text file of information
You have a table that needs to receive the information
You try and it vio;ates the PK constraint.

How'm I doing ?

I would

1. Grab the definition of the PK from the table
2. Check the for duplicates. If as you say this is
clean then it has to be
in the table
3. Import the file into a staging area (exact match of
the real table)(BTW
this is what I always do with a text file)
4. Now using TSQL do a comparison on Key columns using
an INNER join
between the two tables.
5 The records you get back are the violations


Reply With Quote
  #4  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Importing data with DTS - 08-12-2003 , 08:16 AM



1. Import the text file into a scratch table as is (Table needs to be the
same structure as the real table)
2. Compare the scratch table records to itself (will tell you if you have
duplicates in the text file)

SELECT <key cols>, COUNT(*) FROM ScratchTable
GROUP BY <key Cols>
HAVING COUNT(*) > 1

3. Compare it to the real table (This will tell you how many records in the
text file already exist in the source)

SELECT COUNT(*) FROM ScratchTable ST JOIN RealTable RT
ON ST.<Key Cols> = RT.<KeyCols>



--

----------------------------
Allan Mitchell (Microsoft SQL Server MVP)
MCSE,MCDBA
www.SQLDTS.com
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org



"Douglas Gaynor" <doug (AT) q-express (DOT) net> wrote

Quote:
Close. The text file with information came from using a
copy of the SAME database, but contains information that
is NOT in the database that is in use.

The main problem is, I know close to nothing about SQL.

1. We had a database that "APPEARED" to be corrupt. We
backed it up, and restored it to an SQL test bed.

2. We restored a copy of the database, from 4 days
previous.

3. I used DTS on the Test Server, to export the missing 4
days of data

4. I cannot import it into the operational database,
because of the primary key constraint error.

5. I am now considering weapons of mass destruction.

Thanks.. <G

********************************
Not sure if I understand but

You have a text file of information
You have a table that needs to receive the information
You try and it vio;ates the PK constraint.

How'm I doing ?

I would

1. Grab the definition of the PK from the table
2. Check the for duplicates. If as you say this is
clean then it has to be
in the table
3. Import the file into a staging area (exact match of
the real table)(BTW
this is what I always do with a text file)
4. Now using TSQL do a comparison on Key columns using
an INNER join
between the two tables.
5 The records you get back are the violations




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.