0

Is it possible to create an unique constraint on a table column, which ignores any non-alphanumeric characters? Especially spaces, dashes and slashes? The constraint should, for example, trigger, if the table already contains a string "test" and the user create a new dataset with the text "te-st" or "t e s t" or even "t - es/t". The table only allows lowercase letters.

André Reichelt
  • 1,484
  • 18
  • 52
  • 4
    yes. create a computed column with the cleaned result and add the unique constraint on that – Martin Smith Aug 29 '19 at 12:21
  • @MartinSmith I've added the function by Amy below and now I'm trying to insert the computed column, but I constatly get the weird error message: "Either the object doesn't exist, or the reference is ambigious, because it could mean either [dbo].[StripCharacter] or [dbo].[Trailer].[dbo]::[StripCharacter]." The error message is in German on my system, so I've translated it by hand. The column is defined as `[RegistrationNumberSimplified] AS [dbo].StripCharacters([RegistrationNumber], '^A-Z0-9'),`. – André Reichelt Aug 29 '19 at 12:59

0 Answers0