I have a table with a 'start_date' attribute and an 'end_date' attribute. I want to create a check constraint in Oracle that prevents the end_date from preceding the start_date and the start_date from exceeding the end_date. Anybody help me out?
Add a CHECK
constraint :
ALTER TABLE tableX
ADD CONSTRAINT end_date_later_than_start_date_CK -- a sensible name
-- for the constraint
CHECK (start_date <= end_date)
<optional constraint state>
;
The optional constraint states are described in the link. For example, you can specify ENABLE NOVALIDATE
, if you want to enable the constraint for future insertions (and updates) but not check existing rows.
I'm not an Oracle person but I found this on the web and it may helps. Take the timespan for these two dates. Here is a link for documentation :
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.