2 Replies Latest reply on Apr 26, 2004 5:10 PM by haninaguib

    CMP Unique fields

    haninaguib Newbie

      Hi I have 2 classes. Item and ItemGroup. An items belongs to one or more ItemGroups. ItemGroup has an unique name.

      My question is this. Should I use the ItemGroup.name field as the primary key for ItemGroup? Or should I use an auto-incremented integer as key and
      make sure that group names are unique either in the ItemGroup's create method or through database enforcement?

      The reason I am having this dilemma is that groups are not created
      often, but Items are accessed VERY regularly and apart from the size of the key (group names can be quite large) I think that an Integer key is probably
      more efficient.

      I don't know much about databases and therefore I am not sure my rationale
      makes sense. Could someone shed some lite.

        • 1. Re: CMP Unique fields
          Raja Master

          Im not very database savvy either, so take this FWIW.
          Basically i would design this with the name as the primary key. This would save things in 2 places. 1) You dont have to check duplicate in create, the DB does it for you.
          2) Whjen u are associating a item to a itemgroup, you are going to reference it through a itemgroup name, not some integer key that maps to a number. You are avoiding a reference if u use the name as the primary key.

          My 2 paisa worth!

          • 2. Re: CMP Unique fields
            haninaguib Newbie

            Hi Raja, thanks for your reply.
            I think I will do that, unless someone can shed a new light on it.