If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > How to use BULK with Identity

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-08-09, 16:18
rajan142 rajan142 is offline
Registered User
 
Join Date: Oct 2008
Posts: 46
How to use BULK with Identity

I have a table call TblA with Id, FN, LN,Tel fields.
ID is Identity FK.

I have to import all the data from csv file. In csv file there is FN, LN and Tel values. So how can i pass ID identity value using BLUK


BULK
INSERT tblA
FROM 'd:\Db_Backup\CSV\impdata.csv'
WITH
(FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
Reply With Quote
  #2 (permalink)  
Old 01-08-09, 18:39
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,359
You don't pass identity values, you omit this from your destination column list
Code:
CREATE TABLE #identity_test (
   id int identity(1, 1)
 , col1 char(1)
)

INSERT INTO #identity_test (col1)
  VALUES ('A')
INSERT INTO #identity_test (col1)
  VALUES ('B')

SELECT id
     , col1
FROM   #identity_test

GO
DROP TABLE #identity_test
__________________
George
Home | Blog
Reply With Quote
  #3 (permalink)  
Old 01-08-09, 18:54
rudba rudba is offline
Registered User
 
Join Date: Jan 2009
Posts: 47
I think, he wants to import data from csv file, using BULK??
Reply With Quote
  #4 (permalink)  
Old 01-09-09, 03:29
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,359
__________________
George
Home | Blog
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On