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
 SQL Server Development (2000)
 Generating 'Random' String based Primary Keys

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-12-16 : 11:58:02
Tim writes "SQL Server 2000

If anyone is familiar with the ACT Contact Management System database, they use a 12 char field as the primary key for most records.

This key is generated using the current date/time and some other random component.

Example: R/M%! (WE!Y

I decided I prefer this to an integer identity because it isn't easily predictable, and removes the sequential nature of identity fields.

They also use this format for date fields: W=L Z (same level
of detail as DATETIME datatype). I don't know why they do this though.

Anyway, not having much experience with CS algorithms, has anyone got some pseudo-type code with enough detail to build some TSQL or C code to generate this 'random' key?

I also welcome your thoughts on the use of this as a primary key in itself (the records have no natural key/s).

Tim"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2001-12-16 : 13:50:30
graz has a section on "Randomness", and if you search SQL Team for "random":

http://www.sqlteam.com/SearchResults.asp?SearchTerms=random

You'll get a few ideas that you could adapt without too much trouble.

You could also create a GUIDCOL, which generates a unique identifier. This is a 16 byte binary value that is guaranteed unique. Books Online will have details under "GUID" and "uniqueidentifier".

Since this is built into SQL Server it will work with much less hassle than other methods, however the GUID values are completely cryptic (don't think you'll mind, just an FYI).

The datetime format they use is probably a binary representation of a datetime value. I don't know if you'll be able to convert it to datetime, if it doesn't convert automatically.

Go to Top of Page
   

- Advertisement -