Data type for Gender

  • What is the recommended datatype for Gender?

  • could think of a few rather un pc answers but don't think that will help your database issue

  • In reality its a boleean

    so bit is fine just have to decide

    0 = Male, 1 = Female

    or 1 = Male, 0 = Female

    How bout

    Char(1)

    M (Male)

    F (Female)

    U (Unknown)

    B (Both)

  • Char(1) sound better. I think Boolean might give problems for NULL data.

  • Char(1) sound better. I think Boolean might give problems for NULL data.

  • I would go for char(1).  Many poorer countries do not perform gender assignment surgery for those babies whose bits are not obvious. 

    Original author: https://github.com/SQL-FineBuild/Common/wiki/ 1-click install and best practice configuration of SQL Server 2019, 2017 2016, 2014, 2012, 2008 R2, 2008 and 2005.

    When I give food to the poor they call me a saint. When I ask why they are poor they call me a communist - Archbishop Hélder Câmara

  • i typically use a char(1) with a check constraint to allow only two values:

    ie ALTER TABLE BLAH ADD GENDER CHAR(1) NULL CHECK (GENDER='M' OR GENDER='F')

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • varchar(1)

    Null is unknown. That is the purpose of null.

    >How bout

    >Char(1)

    >M (Male)

    >F (Female)

    >U (Unknown)

    >B (Both)

  • I see that char or varchar is recommended. Any reason to choose one over the other? What is the selection process to select char, varchar, nvarchar?

  • Because of my indoctrination by Oracle DBAs, I use varchar and never use char.  The reason for nvarchar would be for international character purposes.  I have never seen a compelling reason to use char.

  • Since each varchar column requires an additional 2 bytes to store the column length, I would recommend using char on any column that has a maximum length of 2 bytes or less.

     

  • Agreed, For SQL Server a general rule that I use anything less than 10 characters should be char. Of course it always "Depends"

    when calculating size of a row.

    Maximum size of all variable-length columns = Max_Var_Size

    Total size of variable-length columns (Variable_Data_Size) = 2 + (Num_Variable_Cols x 2) + Max_Var_Size

     

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/createdb/cm_8_des_02_92k3.asp

  • Char will perfom in its best at sinlgle character length and the best practice is to use char for fixed length string instead of varchar. If i were u I would have used char(1) one with one default value as per requirement.

  • Well actually the purpose of null is 'unitialized', not the same as unknown.

    Gender may be unknown where the available data do not specify a gender, but null where no data (including the unknown value) has been entered. Usually this indicates data entry problems.

     

    ...

    -- FORTRAN manual for Xerox Computers --

  • "the purpose of null is 'unitialized'"  Not in any of the books that I have read. 

    If you are worried about performance problems based on varchar(1) and char(1) then there are other design issues in the database that are causing them, not the use of varchar in this case. 

    After designing multi-terrabyte systems in Oracle for the last 3-1/2 years, I will stick with the principles learned there.  I will be glad for the partioning capability in the next release.

Viewing 15 posts - 1 through 15 (of 24 total)

You must be logged in to reply to this topic. Login to reply