CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2007
    Posts
    1

    Talking I'd like to know

    Hello everybody!
    I'd like to know what is really difference between Char and Varchar?

  2. #2
    Join Date
    Jul 2007
    Location
    Sweden
    Posts
    331

    Re: I'd like to know

    A char will always take up the specified length, while a varchar will only take up the length of its value. I.e.:

    A char(10) value set to 'Hello' will become
    Code:
    'Hello     '
    (five spaces in the end; 10 characters in total.)

    A varchar(10) value will remain as 'Hello'.

  3. #3
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,210

    Re: I'd like to know

    In addition, SQL server stores extra data (2 bytes long as i remember) to determine the length of varchar and nvarchar data types.
    In general to optimize both storage and data retrieval time, if your data does not exceed 10 characters, you should use char, if data will exceed 20 characters you should use varchar.
    Hesham A. Amin
    My blog , Articles


    <a rel=https://twitter.com/HeshamAmin" border="0" /> @HeshamAmin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured