Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2002
    Posts
    5

    Unanswered: import data and get unique id

    I am trying to import a text file and have sql give it a unique id number but it keeps saying that the id field cannot have null values. What do I need to do to get this to work?

  2. #2
    Join Date
    Dec 2001
    Location
    Toronto, Canada
    Posts
    335
    So the table you are importing to does it have a column defined with IDENTITY property? What are you using to import DTS, BCP, BULK INSERT?
    MCDBA

  3. #3
    Join Date
    Jul 2002
    Posts
    5
    I am using DTS and the table does have a identity field.

  4. #4
    Join Date
    Dec 2001
    Location
    Toronto, Canada
    Posts
    335
    Well that is what you will have to do first. Create your table with a column having the property of IDENTITY.

    Example:
    Code:
    CREATE TABLE new_employees
    (
     id_num int IDENTITY(1,1),
     fname varchar (20),
     minit char(1),
     lname varchar(30)
    )
    See Books online for more info.
    MCDBA

  5. #5
    Join Date
    Jul 2002
    Posts
    5
    I did that but I still get an error saying that column cannot contain a null value when I import the data for the other column out of a text file (csv).

  6. #6
    Join Date
    Jul 2002
    Posts
    9
    I can offer a different perspective,
    You just have to disable the 'enable identity insert' checkbox when you are doing your import.

  7. #7
    Join Date
    Jul 2002
    Posts
    5
    That worked perfectly, Thank you so much.

Posting Permissions

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