Click here to Skip to main content
15,889,860 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing a WebApp using ASP.net C#.
I am trying to generate the primary key in the table in this format ID-45000-200 (VARCHAR(900))

It increments in this format
ID-1-1
ID-1-2
ID-1-3
ID-2-1

I am trying to develop a SQL UDF for generating this ID value.
The number part is BigInt so I want to know if there is any way to check if the positive BigInt Max value limit is reached in SQL SERVER 2012.

What I have tried:

I have tried hardcoding the min & max values in variables & checking against that, But that seems dumb. I want to know if there is a cleaner way of doing that in SQL Server 2012.
Posted
Updated 28-Jun-18 5:10am
v2

1 solution

Why check, bigint is 2^63 ?

Even if you create 10000 every second you wouldn't reach the limit in 29 million years!
 
Share this answer
 
Comments
Christopher Fernandes 28-Jun-18 23:24pm    
I know BigInt is 2^63. But by my estimates, The app will be generating 250,000 ID every day.
As you can see there are 3 parts to the ID value a)ID b) bigint middle number c) bigint outer number
So whenever outer number reaches the upper limit of bigint I want it to increment the middle number by one and set outer number to one again.
Mehdi Gholam 28-Jun-18 23:47pm    
10000 (/s) * 3600 (s/h) * 24 (h/day) = 864,000,000 /day

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