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 942789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:19:53+00:00 2026-05-15T22:19:53+00:00

I want to create a PIN that is unique within a table but not

  • 0

I want to create a PIN that is unique within a table but not incremental to make it harder for people to guess.
Ideally I’d like to be able to create this within SQL Server but I can do it via ASP.Net if needed.

EDIT

Sorry if I wasn’t clear: I’m not looking for a GUID as all I need is a unique id for that table; I just don’t want it to be incremental.

  • 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-05-15T22:19:53+00:00Added an answer on May 15, 2026 at 10:19 pm

    Add a uniqueidentifier column to your table, with a default value of NEWID(). This will ensure that each column gets a new unique identifier, which is not incremental.

    CREATE TABLE MyTable (
       ...
       PIN uniqueidentifier NOT NULL DEFAULT newid()
       ...
    )
    

    The uniqueidentifier is guaranteed to be unique, not just for this table, but for all tables.

    If it’s too large for your application, you can derive a smaller PIN from this number, you can do this like:

       SELECT RIGHT(REPLACE((SELECT PIN from MyTable WHERE UserID=...), '-', ''), 4/*PinLength*/)
    

    Note that the returned smaller PIN is not guaranteed to be unique for all users, but may be more manageable, depending upon your application.

    EDIT: If you want a small PIN, with guaranteed uniqueness, the tricky part is that you need to know at least the maximum number of users, in order to choose the appropriate size of the pin. As the number of users increases, the chances of a PIN collision increases. This is similar to the Coupon Collector’s problem, and approaches n log n complexity, which will cause very slow inserts (insert time proportional to the number of existing elements, so inserting M items then becomes O(N^2)). The simplest way to avoid this is to use a large unique ID, and select only a portion of that for your PIN, assuming that you can forgo uniqueness of PIN values.

    EDIT2:

    If you have a table definition like this

    CREATE TABLE YourTable (
        [id] [int] IDENTITY(1,1) NOT NULL,
        [pin]  AS (CONVERT(varchar(9),id,0)+RIGHT(pinseed,3)) PERSISTED,
        [pinseed] [uniqueidentifier] NOT NULL
    )
    

    This will create the pin from the pinseed a unique ID and the row id. (RAND does not work – since SQL server will use the same value to initialize multiple rows, this is not the case with NEWID())

    Just so that it is said, I advise that you do not consider this in any way secure. You should consider it always possible that another user could guess someone else’s PIN, unless you somehow limit the number of allowed guesses (e.g. stop accepting requests after 3 attempts, similar to a bank witholding your card after 3 incorrect PIN entries.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a new field (or two) in my table that is
Hi i want to create a generic style for pin button. <Window x:Class=TooglePinButtonStyle.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
I want create wordpress website into which I want create user management... That means
i want create a custom json data from the mssql 2008 results so that
I want create module which update list of usb devices automatically (not only mass
I want to create an Android application that has a MapView at the top
I want to create a GAS standalone web app that will have a google
i want create multiple search where statement $where_search is a multiple condition from post
I want create an application with animate button? how can i do? after click
i want create Dynamic Slideshow in Jquery i'm Write this code var ctx =

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.