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. The Lounge
  3. Database - Use number or character?

Database - Use number or character?

Scheduled Pinned Locked Moved The Lounge
databasequestion
36 Posts 15 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.
  • M Marc Clifton

    I prefer to keep state in separate table with an FK in whatever other tables need to reference the record state. So, we're really just dealing with ID's, and then you can put whatever short description, long description, "token" char/value, into the lookup table for the UI and it can be easily changed.

    julian@giant wrote:

    so that they can easily be turned into an enum at the code end

    Yuck. That locks your code with to your data/state. What if some day the user wants a new state, like "Cancelled", "Deleted", "Under Review", whatever? The code should look up all the current possible states from the database! If you have code that does something specific because of state, put it in a stored procedure if possible on the DB side or a separate DLL for application specific stuff on the client side, unless it's a web page in which case the whole maintenance model is somewhat different. Marc

    Latest Articles - APOD Scraper and Hunt the Wumpus Short video on Membrane Computing Hunt the Wumpus (A HOPE video)

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

    Marc Clifton wrote:

    a new state, like "Cancelled", "Deleted", "Under Review",

    That's an application change -- "new features".

    Marc Clifton wrote:

    look up all the current possible states from the database

    Yes, at compile time, and generate the enumeration therefrom.

    You'll never get very far if all you do is follow instructions.

    M 1 Reply Last reply
    0
    • J julian giant

      What are people's preferences for using numbers or letters for a field that indicates the status of something? If something is 'In Progress' you might use the letter 'I' in a Char field or a 1 in a number field for instance. As soon as the record is 'Complete' it get updated to a 'C' or a 2 for instance. My preference is number, so that they can easily be turned into an enum at the code end. It causes arguments at work like you wouldn't believe....! Anyone care to make a view? Julian

      B Offline
      B Offline
      BobJanova
      wrote on last edited by
      #17

      It should be a simple key referring to another table that gives further information about what the status means. Whether you use an int or a char for that field is not particularly important.

      1 Reply Last reply
      0
      • P PIEBALDconsult

        Marc Clifton wrote:

        a new state, like "Cancelled", "Deleted", "Under Review",

        That's an application change -- "new features".

        Marc Clifton wrote:

        look up all the current possible states from the database

        Yes, at compile time, and generate the enumeration therefrom.

        You'll never get very far if all you do is follow instructions.

        M Offline
        M Offline
        Marc Clifton
        wrote on last edited by
        #18

        PIEBALDconsult wrote:

        Yes, at compile time, and generate the enumeration therefrom.

        Personally I don't like that approach, simply because it requires redistributing the code when configuration information in the database changes, and probably not worth arguing the pros and cons unless we find ourselves working together on a project. :) Marc

        Latest Articles - APOD Scraper and Hunt the Wumpus Short video on Membrane Computing Hunt the Wumpus (A HOPE video)

        P 1 Reply Last reply
        0
        • P PIEBALDconsult

          Brady Kelly wrote:

          can get referential integrity

          True. But the use of characters may lead to laziness and therefore no such table, whereas it's much more important when using numbers.

          Brady Kelly wrote:

          it's more readable

          Not to the user -- who should never see the codes. The computer doesn't care and the developers shouldn't either.

          Brady Kelly wrote:

          230 other possible values

          Don't sell yourself short; you're not limited to alphabetic characters -- a status of ( could be the start of something and ] the end of something else, and Ctrl-C could be the termination of some process. :-D Also, when I worked on a system that used characters, it was in Oracle, so we had case sensitivity. :omg: I could never remember the codes so I always had to look them up anyway. Where I am now I use numeric codes and keep a print-out of the translations pinned to my wall. Oh, oh, oh, I just remembered -- one of the applications I maintain a little bit here uses GUIDs for all foreign keys, including things like type and status values! :laugh:

          You'll never get very far if all you do is follow instructions.

          F Offline
          F Offline
          Frank Alviani
          wrote on last edited by
          #19

          GUIDs for keys - ick!

          According to my calculations, I should be able to retire about 5 years after I die.

          P 1 Reply Last reply
          0
          • J julian giant

            What are people's preferences for using numbers or letters for a field that indicates the status of something? If something is 'In Progress' you might use the letter 'I' in a Char field or a 1 in a number field for instance. As soon as the record is 'Complete' it get updated to a 'C' or a 2 for instance. My preference is number, so that they can easily be turned into an enum at the code end. It causes arguments at work like you wouldn't believe....! Anyone care to make a view? Julian

            T Offline
            T Offline
            thatraja
            wrote on last edited by
            #20

            I create separate child table with values & store the ID value in transaction table(Chris way). Transaction Table

            ----------------
            Work Status

            Work1 O
            Work2 O
            Work3 I
            Work4 C

            Child Table

            ----------------
            StatusID StatusDesc

            O Open
            I In-Progress
            H Hold
            C Closed

            Long time ago, I have used bit datatype for 2 value columns(0 or 1). But later I had to change insert one more value based on requirement. After that, I never used bit datatype. Even for simple things(like Gender, Marital Staus) I use Child table like above. Currently I use Char datatype so I could use many values. In number datatypes you can't store any characters & number values are not easy to recognize. If it's character datatype it's easy to recognize(Like C for Closed, O for Open & so on).

            thatraja

            Code converters | Education Needed | Improve EverythingNew

            1 Reply Last reply
            0
            • M Matt U

              That's how I've always done it as well. However, the place I contract for right now has some status tables and they use the characters with a text description, instead of a number.

              djj55: Nice but may have a permission problem Pete O'Hanlon: He has my permission to run it.

              W Offline
              W Offline
              Worried Brown Eyes
              wrote on last edited by
              #21

              That's one of the big advantages of contracting - you see stacks of ways of doing the same thing, some good, some bad & you add the knowledge to your range of experience.

              M 1 Reply Last reply
              0
              • M Marc Clifton

                PIEBALDconsult wrote:

                Yes, at compile time, and generate the enumeration therefrom.

                Personally I don't like that approach, simply because it requires redistributing the code when configuration information in the database changes, and probably not worth arguing the pros and cons unless we find ourselves working together on a project. :) Marc

                Latest Articles - APOD Scraper and Hunt the Wumpus Short video on Membrane Computing Hunt the Wumpus (A HOPE video)

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

                Marc Clifton wrote:

                Personally I don't like that approach

                I do, but I haven't gotten to write such an application for some time now. :sigh:

                Marc Clifton wrote:

                redistributing the code when configuration information in the database changes

                I don't think we're talking about configuration changes. In cases where I need to allow such flexibility, I wouldn't use an enumeration. Adding/removing such codes as are being discussed in this thread is a change to the application (a new feature perhaps) so of course it has to be redeployed. I'll use enumerations when it makes sense to do so and I'll generate them from the database at compile time (or before).

                You'll never get very far if all you do is follow instructions.

                1 Reply Last reply
                0
                • F Frank Alviani

                  GUIDs for keys - ick!

                  According to my calculations, I should be able to retire about 5 years after I die.

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

                  I like GUIDs, but not for codes.

                  You'll never get very far if all you do is follow instructions.

                  1 Reply Last reply
                  0
                  • W Worried Brown Eyes

                    That's one of the big advantages of contracting - you see stacks of ways of doing the same thing, some good, some bad & you add the knowledge to your range of experience.

                    M Offline
                    M Offline
                    Matt U
                    wrote on last edited by
                    #24

                    I agree, and I do enjoy contract work. Plenty of exposure to various technologies, environments, concepts, etc.

                    djj55: Nice but may have a permission problem Pete O'Hanlon: He has my permission to run it.

                    1 Reply Last reply
                    0
                    • J julian giant

                      What are people's preferences for using numbers or letters for a field that indicates the status of something? If something is 'In Progress' you might use the letter 'I' in a Char field or a 1 in a number field for instance. As soon as the record is 'Complete' it get updated to a 'C' or a 2 for instance. My preference is number, so that they can easily be turned into an enum at the code end. It causes arguments at work like you wouldn't believe....! Anyone care to make a view? Julian

                      W Offline
                      W Offline
                      Wendelius
                      wrote on last edited by
                      #25

                      Numbers, definitely numbers. And not just any numbers but enumerated numbers :) And preferrably even listed in a look up table and enforced with constraints.

                      1 Reply Last reply
                      0
                      • J julian giant

                        What are people's preferences for using numbers or letters for a field that indicates the status of something? If something is 'In Progress' you might use the letter 'I' in a Char field or a 1 in a number field for instance. As soon as the record is 'Complete' it get updated to a 'C' or a 2 for instance. My preference is number, so that they can easily be turned into an enum at the code end. It causes arguments at work like you wouldn't believe....! Anyone care to make a view? Julian

                        J Offline
                        J Offline
                        Jeremy Falcon
                        wrote on last edited by
                        #26

                        SQL Server really needs to have an ENUM data type like MySQL.

                        Jeremy Falcon

                        P 1 Reply Last reply
                        0
                        • J Jeremy Falcon

                          SQL Server really needs to have an ENUM data type like MySQL.

                          Jeremy Falcon

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

                          Ummm... no. X| Well, OK, it should, but no one should use it, not even with MySql. It's the wrong solution to a non-problem.

                          You'll never get very far if all you do is follow instructions.

                          J 1 Reply Last reply
                          0
                          • P PIEBALDconsult

                            Ummm... no. X| Well, OK, it should, but no one should use it, not even with MySql. It's the wrong solution to a non-problem.

                            You'll never get very far if all you do is follow instructions.

                            J Offline
                            J Offline
                            Jeremy Falcon
                            wrote on last edited by
                            #28

                            PIEBALDconsult wrote:

                            Well, OK, it should, but no one should use it, not even with MySql. It's the wrong solution to a non-problem.

                            Not at all. It's a solution to a problem that exists if you care about, say it with me now... per form mance.

                            Jeremy Falcon

                            P 1 Reply Last reply
                            0
                            • J Jeremy Falcon

                              PIEBALDconsult wrote:

                              Well, OK, it should, but no one should use it, not even with MySql. It's the wrong solution to a non-problem.

                              Not at all. It's a solution to a problem that exists if you care about, say it with me now... per form mance.

                              Jeremy Falcon

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

                              Jeremy Falcon wrote:

                              if you care about, say it with me now... per form mance.

                              I do, therefore I would never use that; I'd use a regular translation table just like I can have with any other database and only translate when it makes sense to do so -- which is basically only needed in reporting -- certainly not needed by an application, where it would likely lead to needless operations and therefore reduced performance.

                              You'll never get very far if all you do is follow instructions.

                              J 1 Reply Last reply
                              0
                              • P PIEBALDconsult

                                Jeremy Falcon wrote:

                                if you care about, say it with me now... per form mance.

                                I do, therefore I would never use that; I'd use a regular translation table just like I can have with any other database and only translate when it makes sense to do so -- which is basically only needed in reporting -- certainly not needed by an application, where it would likely lead to needless operations and therefore reduced performance.

                                You'll never get very far if all you do is follow instructions.

                                J Offline
                                J Offline
                                Jeremy Falcon
                                wrote on last edited by
                                #30

                                PIEBALDconsult wrote:

                                I do, therefore I would never use that; I'd use a regular translation table just like I can have with any other database and only translate when it makes sense to do so

                                Translation tables are useful for a variable / large amount of data, but for a quick short constant that's only particular to one table and not reused ENUMS are great. They're more meaningful than a number and they can lead to less DB clutter. They shouldn't be abused, but they have their place.

                                Jeremy Falcon

                                P 1 Reply Last reply
                                0
                                • J Jeremy Falcon

                                  PIEBALDconsult wrote:

                                  I do, therefore I would never use that; I'd use a regular translation table just like I can have with any other database and only translate when it makes sense to do so

                                  Translation tables are useful for a variable / large amount of data, but for a quick short constant that's only particular to one table and not reused ENUMS are great. They're more meaningful than a number and they can lead to less DB clutter. They shouldn't be abused, but they have their place.

                                  Jeremy Falcon

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

                                  Jeremy Falcon wrote:

                                  a variable / large amount of data

                                  That doesn't sound like a translation table.

                                  Jeremy Falcon wrote:

                                  quick short constant that's only particular to one table

                                  Yeah, like that. Small amounts of static data; as with status codes, transaction types, etc.

                                  You'll never get very far if all you do is follow instructions.

                                  J 1 Reply Last reply
                                  0
                                  • P PIEBALDconsult

                                    Jeremy Falcon wrote:

                                    a variable / large amount of data

                                    That doesn't sound like a translation table.

                                    Jeremy Falcon wrote:

                                    quick short constant that's only particular to one table

                                    Yeah, like that. Small amounts of static data; as with status codes, transaction types, etc.

                                    You'll never get very far if all you do is follow instructions.

                                    J Offline
                                    J Offline
                                    Jeremy Falcon
                                    wrote on last edited by
                                    #32

                                    PIEBALDconsult wrote:

                                    That doesn't sound like a translation table.

                                    Using your terminology. I usually call them a look-up table, but when in Rome.

                                    PIEBALDconsult wrote:

                                    Yeah, like that. Small amounts of static data; as with status codes, transaction types, etc.

                                    Which is my point, SQL Server needs a type for that. A good example would be like a three state Boolean. Sure you can use 0, 1, and 2 but something like F, T, and * is much more readable.

                                    Jeremy Falcon

                                    P 1 Reply Last reply
                                    0
                                    • J Jeremy Falcon

                                      PIEBALDconsult wrote:

                                      That doesn't sound like a translation table.

                                      Using your terminology. I usually call them a look-up table, but when in Rome.

                                      PIEBALDconsult wrote:

                                      Yeah, like that. Small amounts of static data; as with status codes, transaction types, etc.

                                      Which is my point, SQL Server needs a type for that. A good example would be like a three state Boolean. Sure you can use 0, 1, and 2 but something like F, T, and * is much more readable.

                                      Jeremy Falcon

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

                                      Jeremy Falcon wrote:

                                      look-up table

                                      Same thing -- look up the translation for some code. They were called translation tables when I was using Oracle in the 90s.

                                      Jeremy Falcon wrote:

                                      SQL Server needs a type for that

                                      I see no need to have a special type and all the added functionality it entails; it's just another table.

                                      Jeremy Falcon wrote:

                                      F, T, and * is much more readable

                                      Well, that's what this whole thread is discussing, but it seems you have a camp all your own :-D , right in between the others -- insert a character but actually store a number. I work with a lot of databases, including MySQL, and I prefer to stay within the common areas as much as possible, and I need a pretty good reason to use something that only one database supports. So sure, just as SQL Server recently added sequences (which Oracle has had for longer than I can recall), it seems like a reasonable feature to add -- to increase that common area. But this particular feature seems like it could hurt performance with very little benefit -- I don't see how it can perform better than the current way that translation/look-up tables are used, and may be (slightly) worse. As with SELECT *, I think it's a boon to interactive users who can benefit from a way to reduce command length and complexity (primarily by eliminating JOINs), but not something that an application benefits from. You've probably heard the arguments against SELECT * in code. Performance is also not as big a concern with interactive users writing ad hoc queries as it is with 24/7 enterprise applications.

                                      You'll never get very far if all you do is follow instructions.

                                      J 1 Reply Last reply
                                      0
                                      • P PIEBALDconsult

                                        Jeremy Falcon wrote:

                                        look-up table

                                        Same thing -- look up the translation for some code. They were called translation tables when I was using Oracle in the 90s.

                                        Jeremy Falcon wrote:

                                        SQL Server needs a type for that

                                        I see no need to have a special type and all the added functionality it entails; it's just another table.

                                        Jeremy Falcon wrote:

                                        F, T, and * is much more readable

                                        Well, that's what this whole thread is discussing, but it seems you have a camp all your own :-D , right in between the others -- insert a character but actually store a number. I work with a lot of databases, including MySQL, and I prefer to stay within the common areas as much as possible, and I need a pretty good reason to use something that only one database supports. So sure, just as SQL Server recently added sequences (which Oracle has had for longer than I can recall), it seems like a reasonable feature to add -- to increase that common area. But this particular feature seems like it could hurt performance with very little benefit -- I don't see how it can perform better than the current way that translation/look-up tables are used, and may be (slightly) worse. As with SELECT *, I think it's a boon to interactive users who can benefit from a way to reduce command length and complexity (primarily by eliminating JOINs), but not something that an application benefits from. You've probably heard the arguments against SELECT * in code. Performance is also not as big a concern with interactive users writing ad hoc queries as it is with 24/7 enterprise applications.

                                        You'll never get very far if all you do is follow instructions.

                                        J Offline
                                        J Offline
                                        Jeremy Falcon
                                        wrote on last edited by
                                        #34

                                        PIEBALDconsult wrote:

                                        Well, that's what this whole thread is discussing, but it seems you have a camp all your own

                                        Because this is mainly MS devs that never used an ENUM in a DB before. Of course I'm going to be "in a camp all my own" here.

                                        PIEBALDconsult wrote:

                                        But this particular feature seems like it could hurt performance with very little benefit

                                        You must be bored and just want to argue. Seriously, do I have to explain why a join on a look-up table is slower? You're just arguing man. I use your term, you argue with that on semantics. I explain my term, then you explain to me why you use yours, which tells me we were on the same page by using your term in the first place and you know what I meant. Seriously, do you really like to argue that much?

                                        Jeremy Falcon

                                        P 1 Reply Last reply
                                        0
                                        • J Jeremy Falcon

                                          PIEBALDconsult wrote:

                                          Well, that's what this whole thread is discussing, but it seems you have a camp all your own

                                          Because this is mainly MS devs that never used an ENUM in a DB before. Of course I'm going to be "in a camp all my own" here.

                                          PIEBALDconsult wrote:

                                          But this particular feature seems like it could hurt performance with very little benefit

                                          You must be bored and just want to argue. Seriously, do I have to explain why a join on a look-up table is slower? You're just arguing man. I use your term, you argue with that on semantics. I explain my term, then you explain to me why you use yours, which tells me we were on the same page by using your term in the first place and you know what I meant. Seriously, do you really like to argue that much?

                                          Jeremy Falcon

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

                                          Jeremy Falcon wrote:

                                          Of course I'm going to be "in a camp all my own"

                                          I usually am too.

                                          Jeremy Falcon wrote:

                                          do I have to explain why a join on a look-up table is slower?

                                          Perhaps you could explain how it would implement the automatic translation/look-up without performing a JOIN behind the scenes?

                                          Jeremy Falcon wrote:

                                          you know what I meant

                                          You appeared to not know what I meant.

                                          Jeremy Falcon wrote:

                                          do you really like to argue

                                          No, but I want to be sure talking about the same thing. I think we are now.

                                          You'll never get very far if all you do is follow instructions.

                                          J 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