I am trying to generate unique "referral codes" for unique entries into a "customer" table upon INSERT. I want to do this with a default value constraint.
My question is, how do I guarantee that randomly generated values will be unique? I know I can do something like:
SELECT ABS(CAST(CAST(NEWID() AS VARBINARY) AS INT)) AS [ReferralCode]
Will give me a random integer, but I suspect that it's non-unique.
Help?
Thanks!