微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决尝试进行检查约束时出现 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 解释:

不允许子查询。

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。