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. MS SQL - Tinyint - Default Value

MS SQL - Tinyint - Default Value

Scheduled Pinned Locked Moved Database
databasequestion
6 Posts 4 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
    JammoD87
    wrote on last edited by
    #1

    Hi All, Can someone enlighten me as to why you would need a default value of 0 on a tinyint field. I'm not even sure if you do need to set it on all tinyint fields but I was told this by our previous DBA. If the field "Allows Nulls", can it by default be left null without causing any problems? Thanks, JammoD

    J M J 3 Replies Last reply
    0
    • J JammoD87

      Hi All, Can someone enlighten me as to why you would need a default value of 0 on a tinyint field. I'm not even sure if you do need to set it on all tinyint fields but I was told this by our previous DBA. If the field "Allows Nulls", can it by default be left null without causing any problems? Thanks, JammoD

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

      The same reason you'd want (need?) a default on any field - to save space. You see, by making a field nullable it requires 1 extra byte of info per field per record to determine if the field is null.

      1 Reply Last reply
      0
      • J JammoD87

        Hi All, Can someone enlighten me as to why you would need a default value of 0 on a tinyint field. I'm not even sure if you do need to set it on all tinyint fields but I was told this by our previous DBA. If the field "Allows Nulls", can it by default be left null without causing any problems? Thanks, JammoD

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        I don't see saving 1 extra byte per field a relevant issue. I suspect it is an internal convention, default to 0 and the dba/developers/coder/us lazy bastards do not need to test for null values.

        Never underestimate the power of human stupidity RAH

        J 1 Reply Last reply
        0
        • J JammoD87

          Hi All, Can someone enlighten me as to why you would need a default value of 0 on a tinyint field. I'm not even sure if you do need to set it on all tinyint fields but I was told this by our previous DBA. If the field "Allows Nulls", can it by default be left null without causing any problems? Thanks, JammoD

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

          Thanks guys answers my question!

          1 Reply Last reply
          0
          • M Mycroft Holmes

            I don't see saving 1 extra byte per field a relevant issue. I suspect it is an internal convention, default to 0 and the dba/developers/coder/us lazy bastards do not need to test for null values.

            Never underestimate the power of human stupidity RAH

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

            If both of the following are true then it could be relevant. 1. High volume system. 2. Many columns of this type. (Really high volumes even a couple might be relevant.) However since the vast majority of systems will never have both of these it isn't going to be relevant.

            Mycroft Holmes wrote:

            and the dba/developers/coder/us lazy bastards do not need to test for null values.

            And maybe a bit stupid too since zero and null are not necessarily the same thing.

            M 1 Reply Last reply
            0
            • J jschell

              If both of the following are true then it could be relevant. 1. High volume system. 2. Many columns of this type. (Really high volumes even a couple might be relevant.) However since the vast majority of systems will never have both of these it isn't going to be relevant.

              Mycroft Holmes wrote:

              and the dba/developers/coder/us lazy bastards do not need to test for null values.

              And maybe a bit stupid too since zero and null are not necessarily the same thing.

              M Offline
              M Offline
              Mycroft Holmes
              wrote on last edited by
              #6

              jschell wrote:

              since zero and null are not necessarily the same thing

              The is always a debating point, do we allow null to represent a value in a numeric field? As I'm a lazy sod I disallow null in numeric field as my default position and until the business can convince me otherwise that is the way it is designed.

              Never underestimate the power of human stupidity RAH

              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