Search code examples
sql-serversql-server-2005database-designsql-server-2000

Extra spaces being added at the tail in the column


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.


Solution

  • 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.