Friday, February 24, 2012

Default value of a GUID field?!

I have a column named "ID" and its type is "uniqueidentifier" in SQL Server
2005 Express.
this column is the primary key and its default value is "newid()" in SQL
Server.
I have generated a DataSet in C# that has this column but its default value
is DBNull what can I do to make the default value be the return value of
this function ( or I want the Id be generated by default in the DataSet)?
System.Guid.NewGuid()
H? Leon
Have you cons?dered to create the guid from code and then insert it into the
table, in stead of letting the sql server generate it for you ?. Otherwise it
is possible to query the table for the inserted row, and reading the guid.
(if the guid isn't the primary key)
Hope this helps.
TIA
/Allan
"Leon_Amirreza" wrote:

> I have a column named "ID" and its type is "uniqueidentifier" in SQL Server
> 2005 Express.
> this column is the primary key and its default value is "newid()" in SQL
> Server.
> I have generated a DataSet in C# that has this column but its default value
> is DBNull what can I do to make the default value be the return value of
> this function ( or I want the Id be generated by default in the DataSet)?
> System.Guid.NewGuid()
>
>
|||Thanks but this gets very tricky
and sorry for the clock problem
"Allan Bentsen" <Allan.Bentsen@.discussions.microsoft.com> wrote in message
news:6FDCD5BC-DC5F-4FC9-A4E4-D23E855F651F@.microsoft.com...[vbcol=seagreen]
> H? Leon
> Have you cons?dered to create the guid from code and then insert it into
> the
> table, in stead of letting the sql server generate it for you ?. Otherwise
> it
> is possible to query the table for the inserted row, and reading the guid.
> (if the guid isn't the primary key)
> Hope this helps.
> --
> TIA
> /Allan
>
> "Leon_Amirreza" wrote:
|||becuase I am using offline Typed DataSets and the GUID field is the Primary
Key of the table
"Leon_Amirreza" <amirreza_rahmaty@.yahoo.com> wrote in message
news:uhK4HNz%23GHA.4472@.TK2MSFTNGP05.phx.gbl...
> Thanks but this gets very tricky
> and sorry for the clock problem
> "Allan Bentsen" <Allan.Bentsen@.discussions.microsoft.com> wrote in message
> news:6FDCD5BC-DC5F-4FC9-A4E4-D23E855F651F@.microsoft.com...
>
|||Ouch!! That's not a good idea.
GUID -Identity and Primary Keys
http://sqlteam.com/item.asp?ItemID=2599
GUID -Is not Always GOOD
http://bloggingabout.net/blogs/wellink/archive/2004/03/15/598.aspx
GUID -The Cost of GUIDs as Primary Keys
http://www.informit.com/articles/article.asp?p=25862&rl=1
GUID -Uniqueidentifier vs. IDENTITY
http://sqlteam.com/item.asp?ItemID=283
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf
"Leon_Amirreza" <amirreza_rahmaty@.yahoo.com> wrote in message
news:O1BfFPz%23GHA.3352@.TK2MSFTNGP03.phx.gbl...
> becuase I am using offline Typed DataSets and the GUID field is the
> Primary Key of the table
> "Leon_Amirreza" <amirreza_rahmaty@.yahoo.com> wrote in message
> news:uhK4HNz%23GHA.4472@.TK2MSFTNGP05.phx.gbl...
>

No comments:

Post a Comment