Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

What do I call this SQL item?

Options
  • 10-12-2012 8:56pm
    #1
    Registered Users Posts: 196 ✭✭


    Hi. I have a reference to an SQL key(ish) that I have to give a generic name.

    The key can be either a Primary Key or a Unique Index. Is there a term which encompasses both?

    i.e. If the term is "X" it would be true to say:
    "A SQL primary key is an X" and
    "A SQL unique index is an X"


Comments

  • Registered Users Posts: 2,781 ✭✭✭amen


    by definition a Primary Key is an Unique Index


  • Registered Users Posts: 196 ✭✭AnonymousPrime


    amen wrote: »
    by definition a Primary Key is an Unique Index

    Cheers, but I can't call it a unique index, because that is the name of my (non primary key) unique indexes.


  • Registered Users Posts: 607 ✭✭✭brianwalshcork


    candidate key?


  • Registered Users Posts: 419 ✭✭Mort5000


    Hi. I have a reference to an SQL key(ish) that I have to give a generic name.

    Where? On another table? In code? In a view / procedure?

    Why? What happens if you do give it a generic name? What happens if you don't?


  • Registered Users Posts: 23,212 ✭✭✭✭Tom Dunne


    I'm not really sure I understand what you are asking, but as amen says, a Primary Key is always going to be a Unique Index.

    So, by referring to it as a Primary Key, the implication is always that it is also a Unique Index.

    However, the converse is not true - a Unique Index does not have to be a primary key.


  • Advertisement
  • Registered Users Posts: 196 ✭✭AnonymousPrime


    candidate key?

    Its ugly but it is the best I have heard so far.
    Mort5000 wrote: »
    Where? On another table? In code? In a view / procedure?

    Why? What happens if you do give it a generic name? What happens if you don't?

    It is in an application, e.g.

    class Table
    {
    PrimaryKey PrimaryKey;
    IList<UniqueIndex> UniqueIndexes;
    IList<ForeignKey> ForeignKeys;
    // UniqueKey class inherits PrimaryKey class
    IList<PrimaryKey> CombinationOfPrimaryKeysAndUniqueIndexes;
    }

    So I really just want a suitable variable name, and after 3 weeks it is starting to annoy me

    (p.s. I know us coders can be a pedantic bunch, but please don't comment on my code, this is an over simplified version)
    Tom Dunne wrote: »
    I'm not really sure I understand what you are asking, but as amen says, a Primary Key is always going to be a Unique Index.

    So, by referring to it as a Primary Key, the implication is always that it is also a Unique Index.

    However, the converse is not true - a Unique Index does not have to be a primary key.

    My comments on the previous quote hopefully outline why this will not work for me :(


  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    I'd go with "Identity" or "Identifier" or something along those lines, since both a Primary Key and a Unique Index can uniquely identify a record.


  • Registered Users Posts: 2,781 ✭✭✭amen


    IList<PrimaryKey> CombinationOfPrimaryKeysAndUniqueIndexes;

    sorry but I understand what you are trying to do here. Why do you have this list of Keys they are PrimaryKeysAndUniqueIndexes?

    In you model is the PrimaryKey recorded three times, once in PrimaryKey, once in UniqueIndexes and once in CombinationOfPrimaryKeysAndUniqueIndexes;?

    Why not have a single Column Keys and have a bit mask for ?


  • Registered Users Posts: 196 ✭✭AnonymousPrime


    amen wrote: »
    sorry but I understand what you are trying to do here. Why do you have this list of Keys they are PrimaryKeysAndUniqueIndexes?

    In you model is the PrimaryKey recorded three times, once in PrimaryKey, once in UniqueIndexes and once in CombinationOfPrimaryKeysAndUniqueIndexes;?

    Why not have a single Column Keys and have a bit mask for ?

    Like I said, above, this is not how my app is, it is an over simplified version.
    Primary keys are as defined by the INFORMATION_SCHEMA
    Unique Indexes are as defined by the INFORMATION_SCHEMA
    CombinationOfPrimaryKeysAndUniqueIndexes is dynamically generated, it is not an actual list.

    I do have need to separate my primary keys and indexes


  • Registered Users Posts: 203 ✭✭shakedown


    Unique Constraint?


  • Advertisement
  • Registered Users Posts: 2,781 ✭✭✭amen


    Are you using MS SQL Server ? Your use of INFORMATION_SCHEMA suggests so.

    Are you thinking of composite keys?


Advertisement