Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unique random key

Status
Not open for further replies.

EdMacDonald

Programmer
Apr 13, 2000
20
CA
I'm creating a users table in my app and don't want the PK of the user to be predictable.&nbsp;&nbsp;I was thinking along the lines of the SID behind an NT user account.<br><br>This seems like a standard type of issue.&nbsp;&nbsp;Is there a standard approach?&nbsp;&nbsp;Anyone have an sp_getNextUserSID() proc in their library?<br><br>Thanks,<br><br>Ed<br>
 
Which version of SQL are you using?<br><br>If you are using 7.0, try using a GUID datatype with a NEWID() default.
 
Thanks,<br><br>I ran across that over the weekend.&nbsp;&nbsp;I feel kinda silly that it was right there staring me in face :-o
 
You can use the scalar function Random. Use it to generate a PK. While inserting , it the statement fails, then it means the PK is already there. Make a loop unless the insert statement is successful.<br><br>Does it answer your question?<br>Thanx<br>Siddhartha Singh<br><A HREF="mailto:ssingh@aztecsoft.com">ssingh@aztecsoft.com</A>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top