Difference between varchar, varchar2, char datatypes

  • Hi,

    May I know the exact difference between varchar, varchar2, char datatypes ?

    As most of the sites does not give the proper & exact difference, I thought of getting help from you guys.

    Which datatype will retain null chars and which one will discard the null chars?

    Thanks in advance,

    Ramanathan

     

     

  • There is quite a bit of difference between these data types. Rather than try to answer it myself you will find more of a definitive refrence in sql server books online under the heading "Using char and varchar Data".

     

    If you are new to sql server, goto:

    start/all programs/microsoft sql server/books online. Type in "varchar" in the index and select the topic highlghted in the pane.

     

     


    ------------------------------
    The Users are always right - when I'm not wrong!

  • Also, VARCHAR2 is an Oracle Datatype which in version 7 was limited to 2000 chracters, with 8 went to 4000 and may be higher now. VARCHAR and CHAR in SQL hold up to 8000 starting with version 7. CHAR on Oracle was limited to 255 in 7 but I believe still only goes to 2000 with the current version.

  • Char is fixed length.  If you put ANIMAL in a char(15) field, 9 spaces will be appended onto the end of ANIMAL.

    Varchar is variable length.  In the same example, only 6 character of teh possible 15 would be used to store ANIMAL.

    Both will retain a null value if you allow nulls in the column.  Neither will if you do not.

    As mentioned before, varchar2 is not valid for SQL Server.

    Both char and varchar can have an n prefixed to them and will then store double byte data, i.e. Chinese characters.  But, they will also take up twice the space; 15 becomes 30.

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

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