SQLTeam.com | Weblogs | Forums

Field Uniqueidentifier


#1

Hello

I have a table that contains a field of type Uniqueidentifier (not null)

This table is populated correctly from the application

But, I need filling the departing from an EXCEL file

Example:

col1 (Uniqueidentifier not null)
col2 varchar (10)
col3 varchar (50)

My excel file contains only col2 and col3

col2 col3

001 Henry
002 Nancy

.....
how col1 filling?


#2

Is there a default on the column?


#3

As djj55 suggested, if you have a default on col1, you can simply insert col2 and col3, and col1 will be automatically populated.

Another option is to insert the data from Excel file into a staging table, and then insert the data from the staging table to your final destination table.

INSERT INTO YourFinalTable
(Col1, Col2, Col3)
SELECT NEWID(), Col2, Col3 FROM StagingTable

How are you importing the data from Excel into the database table if you had data for all 3 columns in the excel file?
If you are using SSIS, you should be able to generate a UUID using an ExecuteSQL task.
Alternatively, you could write a VBA macro in Excel to create the UUID and insert the data.