I have this statement in T-SQL
[dateReturned] [DATE] NULL
CONSTRAINT [Date_Returned] CHECK (dateReturned >= dateRented),
but when I execute the whole query I am getting this error.
Msg 8141, Level 16, State 0, Line 17
Column CHECK constraint for column 'dateReturned' references another column, table 'Rental'.
Msg 1750, Level 16, State 0, Line 17
Could not create constraint. See previous errors.
What is wrong with the statement?
Multi-column CHECK constraints must be defined at the table level. Constraints defined at the column level can't reference other columns
From the documentation :
You can apply multiple CHECK constraints to a single column.
You can also apply a single CHECK constraint to multiple columns by creating it at the table level.
Taken from another MSDN page:
ALTER TABLE dbo.Vendors ADD CONSTRAINT CK_Vendor_CreditRating
CHECK (CreditRating >= 1 AND CreditRating <= 5)