Welcome to SPN

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

Sign Up Now!

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?
     

Share This Page