What is the Difference Between CHAR and VARCHAR Datatypes in SQL Server ?

VARCHARS are variable-length strings with a specified maximum length. If a string is less than the maximum length, then it is stored verbatim without any extra characters, e.g. names and emails. CHARS are fixed-length strings with a specified set length.

If a string is less than the set length, then it is padded with extra characters, e.g. phone number and zip codes. For instance, for a column that is declared as VARCHAR(30) and populated with the word "SQL Server", only 10 bytes will be stored in it. However, if we have declared the column as CHA (30) and populated it with the word "SQL Server", it will still occupy 30 bytes in the database.



You May Interest

What are the Limitations of Indexed Views in SQL Server ?

What are the Various Limitations of the Views in SQL Server ?

What is NOLOCK Hint in SQL Server ?

What Have INCLUDED Columns With SQL Server Indexes ?

Making a MS SQL Database Offline