Extra spaces being added at the tail in the column

SKumar picture SKumar · Dec 29, 2010 · Viewed 11.7k times · Source

When I am saving data into a table, extra spaces being added to the valued at the tail. I observed that as the column length is 5, if I am inserting a value of 3 char length, 2 extra spaces are being added. Can any one how to solve this problem.

Answer

Chris Shaffer picture Chris Shaffer · Dec 29, 2010

Is the column type CHAR(5) instead of VARCHAR(5)?

  • CHAR(x) creates a column that always stores x characters, and pads the data with spaces.
  • VARCHAR(x) creates a column that varies the lengths of the strings to match the data inserted.