我有一张桌子,上面有会员加入俱乐部时输入的日期。该列是沼泽标准,DATE为类型。没必要时间。
基本上我试图找到一种不可能在将来出现的方式?
答案 0 :(得分:0)
您可以使用触发器。以下是一个功能齐全的测试示例:
create table t(signup_date date not null);
delimiter //
create trigger ins_check_date before insert on t
for each row
begin
if (new.signup_date > current_date()) then
signal sqlstate '45000' set message_text = 'Date cannot be in the future';
end if;
end//
create trigger up_check_date before update on t
for each row
begin
if (new.signup_date > current_date()) then
signal sqlstate '45000' set message_text = 'Date cannot be in the future';
end if;
end//
delimiter ;
insert into t values (current_date());
insert into t values (current_date() - interval 1 day);
insert into t values (current_date() - interval 2 day);
insert into t values (current_date() + interval 1 day);
select * from t;
update t set signup_date = signup_date - interval 1 month
where signup_date = current_date() - interval 1 day;
update t set signup_date = signup_date + interval 1 month
where signup_date = current_date();
select * from t;