我有下表。
create table test (
id smallint unsigned AUTO_INCREMENT,
age tinyint not null,
primary key(id),
check (age<20)
);
Run Code Online (Sandbox Code Playgroud)
问题是CHECK
约束不适用于年龄列。例如,当我为年龄字段插入 222 时,MySQL 接受它。
我想创建一个触发器,以防止在numflights
不存在的航班 ( )的预订表中插入。
Tables
----------------------------------------------
flights(numflight, origine, destination, dep, arr)
airports(code, city, country)
reservation(people, numflight, date_travel)
Run Code Online (Sandbox Code Playgroud)
列origine
和destination
包含机场代码。