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
 SQL Server 2000 Forums
 Import/Export (DTS) and Replication (2000)
 Impoting data from excel and the Identity column

Author  Topic 

LuisC
Starting Member

6 Posts

Posted - 2007-11-07 : 14:09:17
I am new to MS SQL. I created a table and inserted an Identity field
to generate a unique number for every row. I then proceeded to
import data into that new table hoping that when the import process
finished the Identity column would have a unique number. I first
placed the identity field in the last position of the table but an
error showed saying that such field does not accept nulls.

I then placed the identity field as the first column and it game me
another error.

I would truly appreciate it if someone can explain to me how to
import data from an excel file into a table containing an identity
column, and for that column to generate a unique number once the
import process ends.

Thanks

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2007-11-07 : 14:19:50
Specify the Identity (seed,increment) as ID within the import itself.

Refer to BOL for Identity information...

Go to Top of Page

anonymous1
Posting Yak Master

185 Posts

Posted - 2007-11-07 : 15:01:14
if the import is using tsql and openrowset use a column list that does not include the identity column. if the import is using dts, treat the identity column like it does not exist when mapping columns.
Go to Top of Page

LuisC
Starting Member

6 Posts

Posted - 2007-11-07 : 17:07:46
I am using the DTS wizard. I tried to import the records into the table having the identity in the 1st column and the import process attempts to insert the first column of the data in excel into the identity field. If I move the identity field to the last column and try to import the data it says that such column does not accept nulls.
Go to Top of Page

anonymous1
Posting Yak Master

185 Posts

Posted - 2007-11-07 : 17:47:42
the error about nulls means in the mapping you are trying to supply values to the destination identity field. when you run through the wizard pick the source and destination. then click the "..." for the transformation. make sure the enable identity insert is not checked and in the mappings list the destination field that is the identity field has a source field of "<ignore>".
Go to Top of Page

LuisC
Starting Member

6 Posts

Posted - 2007-11-09 : 10:29:34
I can thank you enough for your great help I just tried your suggestion and it worked just fine. Thanks again.
Go to Top of Page

LuisC
Starting Member

6 Posts

Posted - 2007-11-09 : 10:30:23
I can’t thank you enough for your great help I just tried your suggestion and it worked just fine. Thanks again
Go to Top of Page
   

- Advertisement -