3

I have a table in MS SQL where I have a TERMINAL varchar(50) column and I have a unique key on it. I get a UK key violation exception when I try to insert record 'HOST1' and then 'HOST1 '. Why MS sql handles these two strings as they would be the same?

Thanks Z

HamoriZ
  • 2,370
  • 18
  • 38

1 Answers1

5

I believe that MS SQL strips the white space at the end for VARCHAR.

James Culshaw
  • 1,047
  • 8
  • 19
  • 1
    1) ANSI SQL feature. 2) [sqlservercentral.com](http://www.sqlservercentral.com/Forums/Topic1079506-338-1.aspx#bm1080070) – Bogdan Sahlean Feb 07 '13 at 11:17
  • Per the standard, what it technically does is *add* spaces to the shorter string. I've never managed to construct a scenario where adding spaces will obtain a different result than stripping them, but that's what the standard says. – Damien_The_Unbeliever Feb 07 '13 at 13:39