Sql Server Unique Identifier

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
devsonali
Premium Member
Premium Member
Posts: 155
Joined: Sun Mar 18, 2007 2:31 pm

Sql Server Unique Identifier

Post by devsonali »

Hello Gurus

Here is the problem

I need to insert Columns A and B from say table T1 to Table T2 . Table T2 has primary key defined as column PK1(GUID) .

Now lets say I have one row corresponding to Column A and B from T1 that I need to insert into T2 .
When I do the usual insert into Table T2 (Sql Server ) , Should I be using User Defined SQL to load into T2, if yes how would I take care of the GUID (PK1) here ?
Any help is appreciated .

I have searched for this topic with Key works GUID and SQL Server Unique ID but could not find any direct answers .
Last edited by devsonali on Mon Sep 17, 2012 11:26 am, edited 1 time in total.
devsonali
Premium Member
Premium Member
Posts: 155
Joined: Sun Mar 18, 2007 2:31 pm

Post by devsonali »

Missed to add this information :

When I use insert option instead of user defined SQL

It fails with " Cannot insert the value NULL into column . "
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I'm an Oracle person but don't you need to use custom SQL and include a call to newid() in there for that column? :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
devsonali
Premium Member
Premium Member
Posts: 155
Joined: Sun Mar 18, 2007 2:31 pm

Post by devsonali »

Yup , I we would need one (I am new to sql server too ) but what about metadata , Should this pk be the part of metadata ? (If Yes then since there is no value for this new column coming in it wouldn't compile ?)
or should it be like insert into table T1 ( pk1,a,b ) VALUES (newid(),'value1','Value2')
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

No, don't include the PK in the metadata or (I assume) it will want to bind an input column to it - and you won't have one. Your example insert should be pretty close to the mark.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Does the SQL-Server DDL specify that the key column has "IDENTITY" set to on? If so, you may not specify that key column on writing; if not, then you need to fill that column with a value at runtime.
Post Reply