Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8528441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:48:08+00:00 2026-06-11T08:48:08+00:00

Our Customer table has an int Identity column for ID. This was going to

  • 0

Our Customer table has an int Identity column for ID. This was going to be given out to customers, so when they phone they could just give their ID.

It is now obvious that our competitors would easily be able to register twice on our site, say a month apart and find out exactly how many people have registered.

Therefore, is there a nice simple way to create a “Customer ID” (in SQL or c#) which we could give to customers that is:
(a) 6 digits long
(b) is unique
(c) is not sequential(

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:48:09+00:00Added an answer on June 11, 2026 at 8:48 am

    Maybe this is insane, but here is my way of generating the Customer Numbers up front.

    This will generate however many UNIQUE keys you want very quickly.

    You could obviously save these into a real table.

    Here is a SQLFiddle of the below: http://www.sqlfiddle.com/#!3/d41d8/3884

    DECLARE @tbl TABLE
    (
        ID INT IDENTITY(1,1),
        CustNo INT UNIQUE
    )
    
    DECLARE @Upper INT
    DECLARE @Lower INT
    DECLARE @NumberRequired INT
    
    SET @Lower = 100000 ---- The lowest random number allowed
    SET @Upper = 999999 ---- The highest random number allowed
    SET @NumberRequired = 1000 -- How many IDs do we want?
    
    WHILE (SELECT COUNT(*) FROM @tbl) < @NumberRequired
    BEGIN
        BEGIN TRY
            INSERT INTO @tbl SELECT (ROUND(((@Upper - @Lower -1) * RAND() + @Lower), 0))
        END TRY
        BEGIN CATCH
            -- If it goes wrong go round the loop again
        END CATCH
    END
    
    SELECT  *
    FROM    @tbl
    

    EDIT: Actually this is probably faster. It generates all 900000 possible keys in around 30 seconds on my dev machine, which is okay for a one-off job.

    DECLARE @tbl TABLE
    (
        ID INT
    )
    
    DECLARE @Upper INT
    DECLARE @Lower INT
    DECLARE @i INT;
    
    SET @Lower = 100000 ---- The lowest random number allowed
    SET @Upper = 999999 ---- The highest random number allowed
    
    SET @i = @Lower
    
    WHILE @i <= @Upper
    BEGIN
        INSERT INTO @tbl SELECT @i
        SET @i = @i + 1
    END
    
    SELECT  ID
    FROM    @tbl ORDER BY NEWID()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our app (before authentication) has Customers and Widgets. As you'd expect each customer has
http://reps.michebagshows.com/forums/ Recently, our customer forums popped up with this slew of errors from settings.php
I hope someone can help me out. I have a table that logs our
We have the following table: CREATE TABLE [dbo].[CampaignCustomer]( [ID] [int] IDENTITY(1,1) NOT NULL, [CampaignID]
Imagine that I have a Customer table. And in this table is an ID
Rails v3.0.3 Original schema has customers table, and the app has data for 100
One of our customer has a 35 Gb database with average active connections count
Is there any way to determine in JDBC that a column or table has
We have the following table: CREATE TABLE [dbo].[CampaignCustomer]( [ID] [int] IDENTITY(1,1) NOT NULL, [CampaignID]
This may be the dumbest question ever but our customer really wants this. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.