Is it possible to have a CHECK constraint on a column that only accept a list of values from, say another table?
I created a function that retrieves all available international dialling codes that the user can insert into the telephones table and I want to restrict them to only being able to insert these international codes.
I then call the function within the CHECK statement.
It doesnt work though. Any Ideas?
CREATE TABLE tbl_telephones
tel_id INT NOT NULL,
tel_int_code INT SPARSE NULL,
tel_number VARCHAR(25) NOT NULL,
CONSTRAINT pk__tbl__telephones__tel_id PRIMARY KEY CLUSTERED(tel_id),
CONSTRAINT chk__tbl_telephones__tel_id CHECK(tel_int_code IN(SELECT * FROM dbo.fn_available_int_codes()))
Msg 1046, Level 15, State 1, Line 8
Subqueries are not allowed in this context. Only scalar expressions are allowed.