Showing posts with label dbcolumn. Show all posts
Showing posts with label dbcolumn. Show all posts

Monday, March 26, 2012

Suggestion for generating unique identifier.

Anyone have any suggestions for generating a unique identifier for a DB
column. I don't want to use an IDENTITY column because two seperate tables
will have PK columns that cannot have duplicate key values amongst the
tables. I thought about something to do with Date/Time. It can be any
datatype for that matter, it does not have to be an int type. I just need
something to uniquely identify records from two seperate tables.
Thanks
Marty UMarty U. <Marty U.@.discussions.microsoft.com> typed:
> Anyone have any suggestions for generating a unique identifier for a
> DB column. I don't want to use an IDENTITY column because two
> seperate tables will have PK columns that cannot have duplicate key
> values amongst the tables. I thought about something to do with
> Date/Time. It can be any datatype for that matter, it does not have
> to be an int type. I just need something to uniquely identify records
> from two seperate tables.
> Thanks
> Marty U
You could use a GUID. In C#:
string myGuid = Guid.NewGuid().ToString();
Davide Vernole
MVP ASP/ASP.NET
Microsoft Certified Solution Developer
GUID
SQL Server datatype "uniqueidentifier"
Greg
"Marty U." <Marty U.@.discussions.microsoft.com> wrote in message
news:D6C67BD9-3AA6-4125-9F4D-E16C63E94A89@.microsoft.com...
> Anyone have any suggestions for generating a unique identifier for a DB
> column. I don't want to use an IDENTITY column because two seperate tables
> will have PK columns that cannot have duplicate key values amongst the
> tables. I thought about something to do with Date/Time. It can be any
> datatype for that matter, it does not have to be an int type. I just need
> something to uniquely identify records from two seperate tables.
> Thanks
> Marty U
Marty U. wrote:
> Anyone have any suggestions for generating a unique identifier for a DB
> column. I don't want to use an IDENTITY column because two seperate tables
> will have PK columns that cannot have duplicate key values amongst the
> tables. I thought about something to do with Date/Time. It can be any
> datatype for that matter, it does not have to be an int type. I just need
> something to uniquely identify records from two seperate tables.
>
GUIDs are often used for that:
Guid id = Guid.NewGuid();
this corresponds to SQL Server's UniqueIdentifier type.
The SQL server can generate one using the NEWID() function - you can set
the column's default value to NEWID() to have the GUID generated
automatically for new records.
mikeb