Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2008
    Posts
    46

    Unanswered: 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'
    )

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    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

  3. #3
    Join Date
    Jan 2009
    Posts
    47
    I think, he wants to import data from csv file, using BULK??

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •