Hi madhukp,
Your method looks fine, but it may depend on your specific scenario and the random algorithm. If you have a low-volume application, then chances are minimal that you end up with a duplicate key.
The Guid method is pretty similar to this, but Guids are guaranteed to be unique, even if you're inserting your data on multiple machines and / or databases.
If you're using SQL Server, creating a new Guid (which stands for Globally Unique IDentifier) is as simple as calling NewID()
Alternatively, you can use API calls to create your own Guid. If you search Google for
guid vb api I am sure you'll find useful links. .NET has built-in support for Guids, but that requires you to have .NET, of course.
One thing I haven't mentioned before is the use of a natural key. You cannot use this in all scenarios, but when it is applicable, it can be very useful. For example, Members of your Web site can be identified uniquely by an e-mail address or member name, instead of generating a (meaningless) unique ID in the form of a number or random string for them.
Hope this helps,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to:
Let Me Down by
Limp Bizkit (Track 10 from the album:
Results May Vary)
What's This?