Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 help on txt file import

Author  Topic 

pvn80
Starting Member

5 Posts

Posted - 2005-07-01 : 14:55:33
MS SQL Server 2000
Windows Server 2000

I have a few hundred txt files I need to import into a table, each txt file has approximately 3 to 5 thousand rows space delimited about 200 columns. If I import one file at a time everything goes fine, if I use "type *.* >c:\somefilename.txt" to concactinate the text files into one, I always get a Primary Key violation on the last row that needs to be imported. I have gone through the files and there are no PK violations, by the way I am using a date time stamp as the PK for each row. example "5/8/2005 11:59:49 PM". I have done this with 5 or 6 other tables and everything has gone fine.

any help on this would be very apreciated.
Thank you all in advance

Paul

nosepicker
Constraint Violating Yak Guru

366 Posts

Posted - 2005-07-01 : 15:09:46
Maybe blank lines at the end of some files are causing this problem?
Go to Top of Page

pvn80
Starting Member

5 Posts

Posted - 2005-07-01 : 15:53:24
Nope I opened the txt file and even deleted the last few rows. still same error
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-07-01 : 16:30:18
Import the data into a staging table that is an exact duplicate of the real table minus the primary key constraint. Check for duplicates in the staging table. Here's an example duplicate query:

SELECT Column1, COUNT(*)
FROM Table1
GROUP BY Column1
HAVING COUNT(*) > 1

What does this query return?

Tara
Go to Top of Page
   

- Advertisement -