I have a user defined table type where I want to make sure that a certain column is within a given range. This range however is defined in another table. So I thought I can use a check constraint on this column with a scalar valued function.
CREATE TYPE [dbo].[Accounts] AS TABLE(
[AccountName] [varchar](25) NOT NULL
CONSTRAINT CHK_AccountName CHECK (dbo.validateAccountName(AccountName) = 1),
[Sales] [int] NOT NULL,
[Returns] [int] NOT NULL
);
However I get a syntax error, when I do the same on a regular table it works. Based on MSFT documentation check constraints should be ok on table types. What am I missing here ? Any better approach to validate input on a table type ?