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 to store a standard selection?

How to store a standard selection?

Scheduled Pinned Locked Moved Database
questioncsharpcomtutoriallearning
6 Posts 3 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 Offline
    J Offline
    Jorgen Andersson
    wrote on last edited by
    #1

    I have a question that's more of the hypothetical kind. I have two tables:

    Users

    userid

    username

    1

    John Doe

    2

    Jane Doe

    email

    userid

    email

    1

    john.doe@myworkmail.com

    1

    john.doe@myprivatemail.net

    1

    john.doe@someothermail.org

    2

    jane.doe@myworkmail.com

    2

    jane.doe@myprivatemail.net

    2

    jane.doe@someothermail.org

    Now I'd like to make one (or zero) email address per user the default address. On an ANSI compliant system I could simply add a nullable column to the email table and add a check so that the value can only be 'DEFAULT' or null and add a unique composite key on this column and the userid column. This would of course not work on certain databases that don't allow more than one null value when having a unique key. So what other solutions are there? Preferrably not allowing null values.

    Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions

    R L 2 Replies Last reply
    0
    • J Jorgen Andersson

      I have a question that's more of the hypothetical kind. I have two tables:

      Users

      userid

      username

      1

      John Doe

      2

      Jane Doe

      email

      userid

      email

      1

      john.doe@myworkmail.com

      1

      john.doe@myprivatemail.net

      1

      john.doe@someothermail.org

      2

      jane.doe@myworkmail.com

      2

      jane.doe@myprivatemail.net

      2

      jane.doe@someothermail.org

      Now I'd like to make one (or zero) email address per user the default address. On an ANSI compliant system I could simply add a nullable column to the email table and add a check so that the value can only be 'DEFAULT' or null and add a unique composite key on this column and the userid column. This would of course not work on certain databases that don't allow more than one null value when having a unique key. So what other solutions are there? Preferrably not allowing null values.

      Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions

      R Offline
      R Offline
      R Giskard Reventlov
      wrote on last edited by
      #2

      How about a bit field (0/1;true/false)? Set the default to 0, not null.

      "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

      J 1 Reply Last reply
      0
      • R R Giskard Reventlov

        How about a bit field (0/1;true/false)? Set the default to 0, not null.

        "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

        J Offline
        J Offline
        Jorgen Andersson
        wrote on last edited by
        #3

        How would that allow only one emailaddress to be set to default?

        Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions

        R 1 Reply Last reply
        0
        • J Jorgen Andersson

          I have a question that's more of the hypothetical kind. I have two tables:

          Users

          userid

          username

          1

          John Doe

          2

          Jane Doe

          email

          userid

          email

          1

          john.doe@myworkmail.com

          1

          john.doe@myprivatemail.net

          1

          john.doe@someothermail.org

          2

          jane.doe@myworkmail.com

          2

          jane.doe@myprivatemail.net

          2

          jane.doe@someothermail.org

          Now I'd like to make one (or zero) email address per user the default address. On an ANSI compliant system I could simply add a nullable column to the email table and add a check so that the value can only be 'DEFAULT' or null and add a unique composite key on this column and the userid column. This would of course not work on certain databases that don't allow more than one null value when having a unique key. So what other solutions are there? Preferrably not allowing null values.

          Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions

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

          An extra table to store only a reference to the user, and a reference to his default email;

          userId

          emailId

          1

          1

          2

          4

          ..which would work best if email would get an identity-like field. --edit; Add a UNIQUE constraint on the userId-column :)

          Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

          J 1 Reply Last reply
          0
          • L Lost User

            An extra table to store only a reference to the user, and a reference to his default email;

            userId

            emailId

            1

            1

            2

            4

            ..which would work best if email would get an identity-like field. --edit; Add a UNIQUE constraint on the userId-column :)

            Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

            J Offline
            J Offline
            Jorgen Andersson
            wrote on last edited by
            #5

            Where's the 'slapping my forehead' icon when I need it? I guess :doh: will have to do. :thumbsup:

            Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions

            1 Reply Last reply
            0
            • J Jorgen Andersson

              How would that allow only one emailaddress to be set to default?

              Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions

              R Offline
              R Offline
              R Giskard Reventlov
              wrote on last edited by
              #6

              The default is set to true, the rest to false.

              "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

              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