简体   繁体   中英

SQL Server datecolumn NOT greater than another date column

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM