Wrox Programmer Forums
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old September 30th, 2007, 01:47 AM
Authorized User
Join Date: Dec 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Bulk Insert question

I need to use bulk insert to populate a table. How do I get the DBMS to supply a primary key? When I try to execute the T-SQL command I get a primary key violation error as expected since the key is not incorporated in the datafile. I've been staring at the syntax, but don't see how to get a key assigned automatically. The code I am using is:

    FROM 'E:\ICS 321\HW2\Dependent View\DEPENDENT_data.txt'
Old October 2nd, 2007, 03:48 PM
SQLScott's Avatar
Wrox Author
Join Date: Dec 2004
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts

Does your table have a defined primary key on it that you are populating? Is the primary key an identity column?

Scott Klein
Author - Professional SQL Server 2005 XML
Old October 2nd, 2007, 06:51 PM
Friend of Wrox
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts

Ummm... I never import directly to the final table... too dangerous with the lousy data that may be out there. You may want to consider importing into a "staging table" and then do data validations, data cleansing, etc, prior to inserting anything into a production table.

--Jeff Moden

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bulk Insert snufse SQL Server 2000 9 December 17th, 2007 07:53 AM
bulk insert hymavathy_kr VB Databases Basics 1 May 17th, 2007 07:47 AM
BULK INSERT NULL(s) nathansevugan SQL Server 2000 2 November 29th, 2005 01:11 AM
Bulk Insert luma SQL Server DTS 1 July 13th, 2005 01:48 AM
Bulk insert deyakhatib SQL Server 2000 6 March 4th, 2004 04:09 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.