Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Database design question

Database design question

Scheduled Pinned Locked Moved Database
questiondatabasevisual-studiodesignwindows-admin
13 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J J4amieC

    I would go with 1 (ok solution) or 2 (better solution) Solution 3 was just dumb to the max.

    A Offline
    A Offline
    Alivemau5
    wrote on last edited by
    #3

    With (1) you would have to hardcode any combobox (for example) containing the different possible entries. With (2) you wouldn't know which one is each.. Diff between 2 and 3 would be that in the program itself you would have to use: someMatch.Status.Finished == true vs someMatch.Status.Description == 'finished' But im not convinced, though, of solution (3)

    J P 2 Replies Last reply
    0
    • A Alivemau5

      With (1) you would have to hardcode any combobox (for example) containing the different possible entries. With (2) you wouldn't know which one is each.. Diff between 2 and 3 would be that in the program itself you would have to use: someMatch.Status.Finished == true vs someMatch.Status.Description == 'finished' But im not convinced, though, of solution (3)

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #4

      Alivemau5 wrote:

      With (2) you wouldn't know which one is each..

      public enum MatchStatus
      {
      NotStarted = 1,
      FirstHalf = 2,
      HalfTimeBreak = 3
      //.. etc
      }

      If you have code relying on this, the enumerate it in code.

      A 1 Reply Last reply
      0
      • A Alivemau5

        I have a table of football matches, and each match can have 5 different statuses: Not started, 1st halftime, Break, 2nd halftime, Ended My question is, what is the correct way of modeling this?: Matches (MatchId, Status, ...) where Status is an integer or a string corresponding to each status vs Matches (MatchId, StatusId, ...) where StatusId is a foreign key to MatchStatuses, MatchStatuses (MatchStatusId, Description) vs Matches (MatchId, StatusId, ...) where StatusId is a foreign key to MatchStatuses, MatchStatuses (MatchStatusId, Description, IsNotStarted, IsFirstHT, IsBreak, IsSecondHT, IsEnded) for example, a registry in this case would be: (1, "First Half time", false, true, false, false, false) THANKS!

        R Offline
        R Offline
        riced
        wrote on last edited by
        #5

        Depends on what questions you want to answer. If the only question you want to answer is 'What is the status of a match?' then first suggestion is good enough. This effectively means you have a one-one relation between matches and statuses. If you want to answer questions like 'What were half-time and full-time scores of a match?' then you have a one-many relation between matches and statuses so you need to use your second suggestion. Your third suggestion seems to offend first order normalization. I'd go for the second approach because it's more flexible. This may also mean moving some columns from Matches into the statuses table (e.g. the score since you have both half and full time scores).

        Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis

        A 1 Reply Last reply
        0
        • J J4amieC

          Alivemau5 wrote:

          With (2) you wouldn't know which one is each..

          public enum MatchStatus
          {
          NotStarted = 1,
          FirstHalf = 2,
          HalfTimeBreak = 3
          //.. etc
          }

          If you have code relying on this, the enumerate it in code.

          A Offline
          A Offline
          Alivemau5
          wrote on last edited by
          #6

          You have convinced me. And for users privileges do you think its a good idea to have the following?: Users (UserId, UserTypeId, ..) UserTypes (UserTypeId, Name, MayAddMatch, MayDelMatch, May..., May.., May... ) with registries like (1, "Admin", true, true, true...) (i'm not doing an offtopic.. its a similar question)

          1 Reply Last reply
          0
          • R riced

            Depends on what questions you want to answer. If the only question you want to answer is 'What is the status of a match?' then first suggestion is good enough. This effectively means you have a one-one relation between matches and statuses. If you want to answer questions like 'What were half-time and full-time scores of a match?' then you have a one-many relation between matches and statuses so you need to use your second suggestion. Your third suggestion seems to offend first order normalization. I'd go for the second approach because it's more flexible. This may also mean moving some columns from Matches into the statuses table (e.g. the score since you have both half and full time scores).

            Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis

            A Offline
            A Offline
            Alivemau5
            wrote on last edited by
            #7

            Well my second suggestion was more like a table with 5 registries than a table with n registries, that is: (1, Not started) (2, First Half) (3, Break) (4, Second half) (5, Ended) And no more columns.. not this: (1, Not started) ... (23, Not started) I think you understood that This second suggestion was thinking on that I could fill any later combo (for example) without hardcoding it.. but the enum solution works and I wouldnt need to hardcode.

            1 Reply Last reply
            0
            • A Alivemau5

              I have a table of football matches, and each match can have 5 different statuses: Not started, 1st halftime, Break, 2nd halftime, Ended My question is, what is the correct way of modeling this?: Matches (MatchId, Status, ...) where Status is an integer or a string corresponding to each status vs Matches (MatchId, StatusId, ...) where StatusId is a foreign key to MatchStatuses, MatchStatuses (MatchStatusId, Description) vs Matches (MatchId, StatusId, ...) where StatusId is a foreign key to MatchStatuses, MatchStatuses (MatchStatusId, Description, IsNotStarted, IsFirstHT, IsBreak, IsSecondHT, IsEnded) for example, a registry in this case would be: (1, "First Half time", false, true, false, false, false) THANKS!

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #8

              Alivemau5 wrote:

              My question is, what is the correct way of modeling this?

              Normalization[^] would be the way to go, with most tables ending up in the third normal form. A joking reference during design would be "The Key, the whole Key, and nothing but the Key, so help me Codd[^]" :)

              I are Troll :suss:

              1 Reply Last reply
              0
              • A Alivemau5

                I have a table of football matches, and each match can have 5 different statuses: Not started, 1st halftime, Break, 2nd halftime, Ended My question is, what is the correct way of modeling this?: Matches (MatchId, Status, ...) where Status is an integer or a string corresponding to each status vs Matches (MatchId, StatusId, ...) where StatusId is a foreign key to MatchStatuses, MatchStatuses (MatchStatusId, Description) vs Matches (MatchId, StatusId, ...) where StatusId is a foreign key to MatchStatuses, MatchStatuses (MatchStatusId, Description, IsNotStarted, IsFirstHT, IsBreak, IsSecondHT, IsEnded) for example, a registry in this case would be: (1, "First Half time", false, true, false, false, false) THANKS!

                P Offline
                P Offline
                programmervb netc
                wrote on last edited by
                #9

                I say 2 because that would be normalized. The enum would prevent hard coding but you really don't want to have to refer to app anytime you want to know what the value is... For instance if you are just looking at the data in the table not in the app. Also if you do it the second way rather then the enum you don't have to modify the enum every time you add a row.

                Humble Programmer

                1 Reply Last reply
                0
                • A Alivemau5

                  With (1) you would have to hardcode any combobox (for example) containing the different possible entries. With (2) you wouldn't know which one is each.. Diff between 2 and 3 would be that in the program itself you would have to use: someMatch.Status.Finished == true vs someMatch.Status.Description == 'finished' But im not convinced, though, of solution (3)

                  P Offline
                  P Offline
                  programmervb netc
                  wrote on last edited by
                  #10

                  Alivemau5 wrote:

                  With (2) you wouldn't know which one is each..

                  You could know which one is which this is how we do it. This may not be the cleanest way but it is very easy to maintain. We create an integer array such as Dim blah() as Integer and set a default size for it close to what we think the number of records will be to minimize the use of redim. Then do something like this with the record set you retrieve.

                  While myReader.Read
                  cmbControl.Items.Add(myReader.GetString(1))
                  lKeyIndex(lIndex) = myReader.GetValue(0)
                  '
                  lIndex += 1
                  ' see if we need to redimension the array...
                  If lIndex Mod iCurrentDim = 0 Then
                  iCurrentDim = iCurrentDim + iDefaultDim
                  ReDim Preserve lKeyIndex(iCurrentDim)
                  End If
                  End While

                  Here is a example query.

                  SELECT `UniqueNumber`, `Description` FROM `ct_contsources_master` WHERE `Inactive` = 0 ORDER BY `Description`

                  Notice the Inactive flag... If you use this than if a row is no longer valid you can set it to 1...therefore not populate the combo. EDIT.. Oh yeah this will help..

                  Public Function fiSetComboIndex(ByVal lKey As Long, ByRef cboControl As ComboBox, ByRef lKeyIndex() As Long) As Integer
                  ' this routine sets the current "SelectedIndex" to the lKey passed in...
                  Dim iII As Integer
                  Dim iKeyIndexLength As Integer = lKeyIndex.Length - 1
                  '
                  fiSetComboIndex = 0
                  For iII = 0 To iKeyIndexLength
                  If lKeyIndex(iII) = 0 And iII > 0 Then
                  Exit For
                  End If
                  If lKeyIndex(iII) = lKey Then
                  fiSetComboIndex = iII
                  Exit For
                  End If
                  Next
                  End Function

                  Use this to get the value that is selected.

                  blah(comboBoxName.SelectedIndex)

                  Store the result of that in the main table.

                  Humble Programmer

                  1 Reply Last reply
                  0
                  • A Alivemau5

                    I have a table of football matches, and each match can have 5 different statuses: Not started, 1st halftime, Break, 2nd halftime, Ended My question is, what is the correct way of modeling this?: Matches (MatchId, Status, ...) where Status is an integer or a string corresponding to each status vs Matches (MatchId, StatusId, ...) where StatusId is a foreign key to MatchStatuses, MatchStatuses (MatchStatusId, Description) vs Matches (MatchId, StatusId, ...) where StatusId is a foreign key to MatchStatuses, MatchStatuses (MatchStatusId, Description, IsNotStarted, IsFirstHT, IsBreak, IsSecondHT, IsEnded) for example, a registry in this case would be: (1, "First Half time", false, true, false, false, false) THANKS!

                    P Offline
                    P Offline
                    PIEBALDconsult
                    wrote on last edited by
                    #11

                    The second way, definitely -- plus an enumeration in your code. P.S. See my GenOmatic[^].

                    A 1 Reply Last reply
                    0
                    • P PIEBALDconsult

                      The second way, definitely -- plus an enumeration in your code. P.S. See my GenOmatic[^].

                      A Offline
                      A Offline
                      Alivemau5
                      wrote on last edited by
                      #12

                      Isn't bad that the table with states would be finite (5 registries) and readonly?

                      P 1 Reply Last reply
                      0
                      • A Alivemau5

                        Isn't bad that the table with states would be finite (5 registries) and readonly?

                        P Offline
                        P Offline
                        PIEBALDconsult
                        wrote on last edited by
                        #13

                        No, and it would leave room for more in the future. And maybe you would use it as the base for other sports, like American football or baseball or who knows what. It's a proper pattern to use anyway, even if there are only two entries.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups