one character of data

  • Richard M (6/5/2009)


    Alvin Ramard (6/5/2009)


    Have fun loading Unicode characters in your char(1) column!

    ... well, that's part of the problem, the question did not properly specify the rules of the game.....

    In my case, for our use I'd have used char(1) as I don't need unicode chars.....

    Ditto 😀

    Definitely nchar. Think multinational.

    What for... I live on an island 😛

    Far away is close at hand in the images of elsewhere.
    Anon.

  • I chose char(1), but having skimmed the various replies think that there's also an argument for nchar(1). The question is a bit vague as to the supported character set.

    What's clear is that varchar(1) or nvarchar(1) are definitely bad choices due to the 2-byte length overhead and hence the given answer is wrong.

    Derek

  • I've chosen for nchar(1) because it only says that the value won't be NULL or empty, but there's no limitation on the characters used.

  • The correct answer for ME is char(1). I work in the U.S. and don't design for international unless it is in the specs.

    🙂Hugo - How do you store a NULL?🙂

    Tom Garth
    Vertical Solutions[/url]

    "There are three kinds of men. The one that learns by reading. The few who learn by observation. The rest of them have to pee on the electric fence for themselves." -- Will Rogers
  • Tom Garth (6/12/2009)🙂Hugo - How do you store a NULL?🙂

    In the storage area of every row, one or more bytes are reserved for the so-called "null bitmap". If the table has up to 8 columns, 1 bytes is used; for 9 - 16 columns, 2 bytes are used, etc. All columns are included in this bitmap, even if they are not nullable.

    If a column value is NULL, the correpsonding bit in the null bitmap is set, and the storage area reserved for normal values is:

    *) for fixed length columns: unused. I don't know if the bytes are set to some specific value or left as they are, but I do know that the content of this storage area is disregarded on reading when the null bit is set.

    *) for variable length columns: the two bytes representing length are set to a length of zero, so that no other bytes are used. (So a varchar zero-length string ('') ans a varchar NULL are stored exactly the same, except for the bit in the null bitmap.)

    I think I have once read that a different method is used to represent data in SQL Server 2008 "SPARSE" columns, but I don't know the exact details.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • One of the benefits of democracy, is that usually, when so many people agree in certain point of view, that point of view at least, deserve to be discuss. I choose NCHAR(1): I'm outside US, and it was very natural for me, cause I don't have the US-ASCII unique perspective. This is the only one answer that covers that posibility in a so narrow question, and given the fact, that it specify the 1 character for sure, NVARCHAR(1) is a little bit useless, cause we already know that we won't enjoy the 'padding' benefit it provides.

  • Hugo,

    Never have I learned so much from a single dimwitted attempt at humor. Thanks for the info. I wish I could find the humility emoticons.:blush:

    Tom Garth
    Vertical Solutions[/url]

    "There are three kinds of men. The one that learns by reading. The few who learn by observation. The rest of them have to pee on the electric fence for themselves." -- Will Rogers
  • Tom Garth (6/13/2009)


    Never have I learned so much from a single dimwitted attempt at humor.

    Thanks, Tom.

    But boy, do I need to re-adjust my sarcasm detector. Man, you even used TWO emoticons, and I still took it as a serious request... :blush:


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • This is a daft QOD.

    The correct answer is clearly SQL_VARIANT - and that isn't even listed as an option!!!

    Paul

    P.S. Hugo: you may find that your sarcas-ometer just exploded 😉

  • varchar uses 2 extra bytes to save the information about no of characters stored. So varchar is the worst answer.

    The answer should be char(1) as there is no information about unicode or non-unicode characters.

  • With all the replies, it does indicate that varchar(1) is actually not suitable because its carries an overhead for no reason (since the question specifically mention that the one character inserted would never be empty or NULL).

    What's the author of the question is going to response to everyone??

    Simon Liew
    Microsoft Certified Master: SQL Server 2008

  • Another one who chose NCHAR(1). The Netherlands, no score.

    Amidst the 12 pages of reactions I found this:

    Proud member of the Anti-RBAR alliance.

    What did I miss? Where can I join?


    Dutch Anti-RBAR League

  • gserdijn (6/15/2009)


    Another one who chose NCHAR(1). The Netherlands, no score.

    Amidst the 12 pages of reactions I found this:

    Proud member of the Anti-RBAR alliance.

    What did I miss? Where can I join?

    We're very open. Feel free to add it to your sig, and add an anti-rbar to your forum pic and you're in. Course if Jeff catches you promoting RBAR where he can solve it without, he might give you what for, but fighting RBAR everywhere is a good thing.

    One day we'll have our own website, I'm sure... although we might be using it now 🙂



    --Mark Tassin
    MCITP - SQL Server DBA
    Proud member of the Anti-RBAR alliance.
    For help with Performance click this link[/url]
    For tips on how to post your problems[/url]

  • Akhil Kohli (6/14/2009)

    The answer should be char(1) as there is no information about unicode or non-unicode characters.

    Surely that very lack of information indicates the need to code defensively? NCHAR(1) is the defensive option.

    If you were asked to store some string data but had no other information you wouldn't choose the smallest option, varchar(1) or char(1), you'd go for nvarchar(max) as you want to include all that the requirement does not exclude.

    Maybe it's because I'm European, but I'm afraid I don't understand the (many) respondents who claim that if the character type is unknown, you should choose the most limited option? How is that ever going to be the safest option? One foreign character (and even English language apps can have a need for foreign names, for instance) and your application breaks! I don't know any employer who'd prefer that over defensive coding?!? If you are told the character set is restricted to ascii then fine, but the question offered no such restriction.

    Puzzled and somewhat concerned,

    Dave.

  • I agree-- anyone who chose CHAR or VARCHAR is nothing but egocentric.

    Yes-- in most situations I choose VarChar (because I know I am in America, and people speak English).. but in this situation-- I would use NCHAR until I had more requirements (what country am I standing in when they ask me this question, etc)

Viewing 15 posts - 106 through 120 (of 182 total)

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