尝试进行检查约束时出现 MySQL 错误代码 3815

问题描述

这是我试图对其进行约束的表格:

create table All_Events(
event_id int not null auto_increment,event_name varchar(50),event_type int,event_catagory int,other_text varchar(20),event_description varchar(200),start_time time,end_time time,event_date date,address varchar(100),lat decimal(10,6),lng decimal(10,contact_phone varchar(10),contact_email varchar(50),creator_id varchar(10),uni_name varchar(50),rso_name varchar(50),primary key(event_id),foreign key (creator_id) references Users(uid),foreign key (uni_name) references Universities(uni_name)
);

约束的目标是确保同一天同一地点的事件没有时间重叠。这是我目前所拥有的:

alter table All_Events add constraint timeChecker
    check ((
        select count(*) from All_Events A,All_Events B where A.event_date = B.event_date and A.address = B.address and (A.start_time > B.start_time and A.start_time < B.end_time) or (A.end_time > B.start_time and A.end_time < B.end_time)
    )=0);

问题是在尝试添加约束时,我收到“错误代码 3815:检查约束‘timeChecker’的表达式包含不允许的函数”,但没有关于不允许的内容的上下文。任何使此约束起作用的见解或帮助将不胜感激

解决方法

https://dev.mysql.com/doc/refman/8.0/en/create-table-check-constraints.html 解释:

不允许子查询。

我建议您完整阅读我链接到的页面。