A fixed-length string reserves storage according to its declared length. CHAR and NCHAR pad shorter values with whitespace, so assuming VARCHAR(10) and CHAR(10) always use the same storage is incorrect. section 3.2
Mistake #7: always choosing variable-length strings.
- Use a fixed-length string when values in a column consistently have the same length; use a variable-length string when their lengths vary. section 3.6
- A ZIP code known to be exactly 10 characters is a candidate for CHAR(10), while city and state names require lengths that accommodate varying values. section 3.2
- Account for padding and SQL Server row-storage metadata when estimating space rather than comparing declared lengths alone. section 3.2
Converting DepartmentCode
When every department code has two characters, convert the column with: ALTER TABLE dbo.Employees ALTER COLUMN DepartmentCode NCHAR(2);
