Mysql 8.0是否支持使用子查询检查约束?
我的表有date_from和date_to,我需要约束来确保行上没有时间间隔的交叉点。
CREATE TABLE `interval` (
`id` int NOT NULL,
`start` datetime NOT NULL,
`end` datetime NOT NULL,
CONSTRAINT C1 CHECK (id not in (select id from interval as t2 where start between t2.start and t2.end or end between t2.start and t2.end))
) ENGINE=InnoDB DEFAULT CHARSET=utf8;