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. How it is Better to Store Multiple Options

How it is Better to Store Multiple Options

Scheduled Pinned Locked Moved Database
databasequestion
6 Posts 5 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.
  • Richard Andrew x64R Offline
    Richard Andrew x64R Offline
    Richard Andrew x64
    wrote on last edited by
    #1

    I am going to have data that will be represented in code by multiple flag-type enums. Is it preferable to store this data in a database record as the integer value of the enum instance, or should I have a separate field for each value and store either a zero or a one to indicate whether that field is in use?

    The difficult we do right away... ...the impossible takes slightly longer.

    P L 2 Replies Last reply
    0
    • Richard Andrew x64R Richard Andrew x64

      I am going to have data that will be represented in code by multiple flag-type enums. Is it preferable to store this data in a database record as the integer value of the enum instance, or should I have a separate field for each value and store either a zero or a one to indicate whether that field is in use?

      The difficult we do right away... ...the impossible takes slightly longer.

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

      Store the numeric value and have a translation/referential integrity table. And see my GenOmatic[^] article.

      1 Reply Last reply
      0
      • Richard Andrew x64R Richard Andrew x64

        I am going to have data that will be represented in code by multiple flag-type enums. Is it preferable to store this data in a database record as the integer value of the enum instance, or should I have a separate field for each value and store either a zero or a one to indicate whether that field is in use?

        The difficult we do right away... ...the impossible takes slightly longer.

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

        Richard Andrew x64 wrote:

        I [...] have data that will be represented in code by multiple flag-type enums.

        ..and what's the relational representation of the same data?

        I are Troll :suss:

        Richard Andrew x64R 1 Reply Last reply
        0
        • L Lost User

          Richard Andrew x64 wrote:

          I [...] have data that will be represented in code by multiple flag-type enums.

          ..and what's the relational representation of the same data?

          I are Troll :suss:

          Richard Andrew x64R Offline
          Richard Andrew x64R Offline
          Richard Andrew x64
          wrote on last edited by
          #4

          Well, I'm writing a rules engine and it will go something like this:

          Where subject A, B, C, and/or D

          performs function A, B, C, and/or D

          raise alert A, B, C, and/or D.

          And each record in the database will represent one rule. So the choices from A to D will be represented in code by flag enums. And I'm wondering if it's better to store each of the choices as the int value of the enum, or as separate fields.

          The difficult we do right away... ...the impossible takes slightly longer.

          L J 2 Replies Last reply
          0
          • Richard Andrew x64R Richard Andrew x64

            Well, I'm writing a rules engine and it will go something like this:

            Where subject A, B, C, and/or D

            performs function A, B, C, and/or D

            raise alert A, B, C, and/or D.

            And each record in the database will represent one rule. So the choices from A to D will be represented in code by flag enums. And I'm wondering if it's better to store each of the choices as the int value of the enum, or as separate fields.

            The difficult we do right away... ...the impossible takes slightly longer.

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Then think of the typical searches you expect to perform on the data; that should tell you the most fitting answer. :)

            Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

            1 Reply Last reply
            0
            • Richard Andrew x64R Richard Andrew x64

              Well, I'm writing a rules engine and it will go something like this:

              Where subject A, B, C, and/or D

              performs function A, B, C, and/or D

              raise alert A, B, C, and/or D.

              And each record in the database will represent one rule. So the choices from A to D will be represented in code by flag enums. And I'm wondering if it's better to store each of the choices as the int value of the enum, or as separate fields.

              The difficult we do right away... ...the impossible takes slightly longer.

              J Offline
              J Offline
              jschell
              wrote on last edited by
              #6

              Richard Andrew x64 wrote:

              So the choices from A to D will be represented in code by flag enums.

              That description sounds more like a 'name' to me rather than an enum.

              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