Question : SQL Server Column Sizes

Referring to a previous question of mine - http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_24359640.html
Specifically the point in the 2nd reply -

1) A varchar(20) and a varchar(50) both holding the same string will be the same size in the db.  A varchar is terminated by an internal temination character which has to be there no matter what size the value in it is.

When I SELECT this data it always comes out with 50 characters as spaces.  So is the above still true as there is 50 characters in it with the spaces even if there are only 20 characters in a name for example.

Many Thanks.

Answer : SQL Server Column Sizes

If spaces are explicitly inserted, they are stored.

So if you...

insert into SomeTable (Varchar50Field1) values ('Hello                                              ')

The spaces WILL be inserted.  If you have trailing spaces in a varchar field, they were inserted as such and are not related to the storage engine.  Perhaps somewhere along the line the data was contained in a char(50) variable.
Random Solutions  
 
programming4us programming4us