Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!
  1. Guest ji, please consider donating today!   Become a Supporter    ::   Make a Contribution   
    Monthly (Recurring) Target: $300 :: Achieved: $95

Create primary key with pre-defined prefix

Discussion in 'Information Technology' started by CLU73, Nov 13, 2005.

  1. CLU73

    CLU73
    Expand Collapse
    Guest

    I was wondering if there was a way to create a primary key with a pre-defined
    prefix. For instance. I would like my primary key to be FF### where FF
    would be the start for all the primary keys in this particular table and then
    the ### would represent the rest of the primary key.

    Can anyone tell me how to do this?
     
  2. Loading...


  3. Ofer

    Ofer
    Expand Collapse
    Guest

    I think that the easiest way will be to create a table with ID (AutoNumber)
    and then create a query on each table adding the prefix

    Select "FF" & [ID_Field] As NewId From TableName

    That way you can avoid extra programming, as to calculate the next key

    Good Luck

    "CLU73" wrote:

    > I was wondering if there was a way to create a primary key with a pre-defined
    > prefix. For instance. I would like my primary key to be FF### where FF
    > would be the start for all the primary keys in this particular table and then
    > the ### would represent the rest of the primary key.
    >
    > Can anyone tell me how to do this?
     
  4. Jeff Boyce

    Jeff Boyce
    Expand Collapse
    Guest

    If every row will have the same prefix, you don't need to save the prefix.
    Create a query that returns the primary key and concatenate (i.e., pre-pend)
    your 'constant' (e.g., "FF"). Use the query as a source rather than
    directly using the table.

    I may be reading too much into your post, but it seems to imply that you
    wish to do this with other tables as well. Do you have multiple tables that
    store similar data, but with differing tablenames? For example, it might be
    that you have an "AA" table, and a "BB" table, ... and an "FF" table, all of
    which have the same data fields. If so, you have a spreadsheet, not a
    relational database, and there are much better ways to get at Access'
    functionality.

    --
    Regards

    Jeff Boyce
    <Office/Access MVP>

    "CLU73" <CLU73@discussions.microsoft.com> wrote in message
    news:83EB078C-BD5B-4AC0-A490-16DB08E90817@microsoft.com...
    > I was wondering if there was a way to create a primary key with a

    pre-defined
    > prefix. For instance. I would like my primary key to be FF### where FF
    > would be the start for all the primary keys in this particular table and

    then
    > the ### would represent the rest of the primary key.
    >
    > Can anyone tell me how to do this?
     
Since you're here... we have a small favor to ask...

More people are visiting & reading SPN than ever but far fewer are paying to sustain it. Advertising revenues across the online media have fallen fast. So you can see why we need to ask for your help. Donating to SPN's is vote for free speech, for diversity of opinions, for the right of the people to stand up to religious bigotry. Without any affiliation to any organization, this constant struggle takes a lot of hard work to sustain as we entirely depend on the contributions of our esteemed writers/readers. We do it because we believe our perspective matters – because it might well be your perspective, too... Fund our efforts and together we can keep the world informed about the real Sikh Sikhi Sikhism. If everyone who writes or reads our content, who likes it, helps us to pay for it, our future would be much more secure. Every Contribution Matters, Contribute Generously!

    Become a Supporter      ::     Make a Contribution     



Share This Page