Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

I realize that CHAR is recommended if all my values are fixed-width. But, so what? Why not just pick VARCHAR for all text fields just to be safe.

1 Answer

0 votes
by (40.7k points)
edited by

Following cases are mentioned below for selecting CHAR over VARCHAR in SQL:

Are you interested in learning SQL from the basics! Refer to this video on SQL provided by Intellipaat:

  • If the column's data does not vary widely in length, then we should consider using a fixed-length char field instead of the varchar.
  • It may take a little more space to store the data. But in SQL Server, processing the fixed-length columns is faster than processing the variable-length columns (in most cases).
  • In several cases the length of Name values will be more than 80, that’s why char will be a better choice than varchar as it will save some extra space.
  • If you are using char datatype then the search becomes faster than the VARCHAR. In the case of varchar, the SQL Server verifies the length of each record and search through the file in order to locate it, but for char datatype, as it is fixed, SQL Server doesn’t calculate the length of record each time it processes, and this helps to save some time.

Related questions

0 votes
1 answer
0 votes
1 answer
+2 votes
1 answer

Browse Categories

...