Multiple Identity Columns

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • firebirds98
    New Member
    • Feb 2008
    • 15

    Multiple Identity Columns

    I am new to SQL and I am making an asp.net page in which is a small airline service for a project for scool. For one of my tables I have:

    AccountID, CustomerName, FrequentFlierMi les, FrequentFliernu m for my column names. The acount AccountID column can not have duplicated values and FrequentFliernu m can not have duplicated values and the only thing I could think from stopping that is through identity specification, the problem is you can only set one of the columns to have identity specification.

    The AccountID and FrequentFliernu m I would like to automatically increment by 1.


    Anyhelp is appreciated. If this does not make sense I will try re-writing it.
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Originally posted by firebirds98
    I am new to SQL and I am making an asp.net page in which is a small airline service for a project for scool. For one of my tables I have:

    AccountID, CustomerName, FrequentFlierMi les, FrequentFliernu m for my column names. The acount AccountID column can not have duplicated values and FrequentFliernu m can not have duplicated values and the only thing I could think from stopping that is through identity specification, the problem is you can only set one of the columns to have identity specification.

    The AccountID and FrequentFliernu m I would like to automatically increment by 1.


    Anyhelp is appreciated. If this does not make sense I will try re-writing it.
    Let's see if I got this right. You want two unique columns, in this case AccountID and FrequentFliernu m. I did not know you can not have two identity columns in one table, or at least I have not tried it.

    Since the nature of the columns you're trying to use should be unique within the table, but it does not mean they could not be the same (AccountId = FrequentFliernu m). Now, since it would also make sense to make them different (FrequentFliern um could have more digits), you can have the first few digit as the AccountId.

    So you can have AccountId using an IDENTITY column. You can actually use a AccountId + A random number for your FrequentFliernu m. Since AccountId is an IDENTITY which makes it unique, then your entire FrequentFliernu m is unique. You just want it longer (more digits). In the business world, these numbers have some conventions. First few digits could be the AccountId followed by (maybe) Branch ID, followed by (another maybe) type of account like Platinum, Gold, etc...

    Another thing, IDENTITY columns ensures uniqueness, not sequence. Meaning if you have an IDENTITY column on table, and you delete a row, that number will not be reused.

    If you really have to do it the way you describe it, try using a
    1. Calculated/Computed Column
    2. Trigger to implement your formua

    Just some thought...

    Good luck...

    -- CK

    Comment

    • firebirds98
      New Member
      • Feb 2008
      • 15

      #3
      Thank You, I appreciate your help.

      Comment

      Working...