Click here to Skip to main content
15,891,766 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I want to create a table in sql server 2008 with 4 columns i.e MemberId,MemberName,MemberAge and MemberAddress. My requirement is that i want the MemberId column to be autogenerate 16 digit random number.
How can I do it ?
Posted
Comments
AspDotNetDev 1-Nov-12 13:03pm    
Are you talking about a GUID (also known in SQL Server as uniqueidentifier)?
NayakMamuni 1-Nov-12 13:38pm    
No, not actually GUID but should be 16 digit unique id.

1 solution

SQL
select CAST(round(RAND()*10000000000000000,0) AS BIGINT)

I would suggest looking up the following in BOL:
CAST
ROUND
RAND
BIGINT
 
Share this answer
 
Comments
NayakMamuni 2-Nov-12 2:22am    
Bur what should be the query to create the table with this ??
Corporal Agarn 2-Nov-12 6:38am    
What do you have so far? My code would work for MemberID then wherever you are getting your other columns from. Since you said AUTO generate maybe you need to add this code as the default to the table column. See BOL ALTER TABLE

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900