data type performace

  • data type char(7), varchar(7), nvarchar[/b](7) which one is best use data type.

    Note:data type length is fixed in this case

  • If your length is fixed and that man characters ( 7 in this case) will always be soted in the column then its better to use char data type. You use nchar/nvarchar to store unicode data to make your column language independent.

    "Keep Trying"

  • according sql statment result

    select len(cast('xxx' as char(7))),datalength(cast('xxx' as char(7))),

    len(cast('xxx' as varchar(7))),datalength(cast('xxx' as varchar(7)))

    char data type store 7 character including space(3+4(space)) , but varchar store ony 3 character only...

  • Char data type will use 7 bytes of space even if the length of the string u r storing is 3 - 3 + 4 space. In the same case Varchar will use only 3 bytes to store the value (no space).

    So if u r not sure about the length of the data being stored in the column use Varchar. If u r sure that the data will be of the same fixed length always use Char.

    "Keep Trying"

Viewing 4 posts - 1 through 3 (of 3 total)

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