set sql_mode=strict_all_tables; set time_zone="+02:00";
create table t1 (a int not null, b int, c int);
create trigger trgi before insert on t1 for each row set new.a=if(new.a is null,new.b,new.c);
insert t1 values (10, NULL, 1);
insert t1 values (NULL, 2, NULL);
insert t1 values (NULL, NULL, 20); ERROR23000: Column 'a' cannot be null
insert t1 values (1, 2, NULL); ERROR23000: Column 'a' cannot be null
select * from t1;
a b c 1 NULL 1 22 NULL
insert ignore t1 values (NULL, NULL, 30);
Warnings:
Warning 1048 Column 'a' cannot be null
insert ignore t1 values (1, 3, NULL);
Warnings:
Warning 1048 Column 'a' cannot be null
select * from t1;
a b c 1 NULL 1 22 NULL 0 NULL 30 03 NULL
insert t1 set a=NULL, b=4, c=a;
select * from t1;
a b c 1 NULL 1 22 NULL 0 NULL 30 03 NULL 44 NULL
delete from t1;
insert t1 (a,c) values (10, 1);
insert t1 (a,b) values (NULL, 2);
insert t1 (a,c) values (NULL, 20); ERROR23000: Column 'a' cannot be null
insert t1 (a,b) values (1, 2); ERROR23000: Column 'a' cannot be null
select * from t1;
a b c 1 NULL 1 22 NULL
delete from t1;
insert t1 select 10, NULL, 1;
insert t1 select NULL, 2, NULL;
insert t1 select NULL, NULL, 20; ERROR23000: Column 'a' cannot be null
insert t1 select 1, 2, NULL; ERROR23000: Column 'a' cannot be null
insert ignore t1 select NULL, NULL, 30;
Warnings:
Warning 1048 Column 'a' cannot be null
insert ignore t1 select 1, 3, NULL;
Warnings:
Warning 1048 Column 'a' cannot be null
select * from t1;
a b c 1 NULL 1 22 NULL 0 NULL 30 03 NULL
delete from t1;
insert delayed t1 values (10, NULL, 1);
insert delayed t1 values (NULL, 2, NULL);
insert delayed t1 values (NULL, NULL, 20); ERROR23000: Column 'a' cannot be null
insert delayed t1 values (1, 2, NULL); ERROR23000: Column 'a' cannot be null
select * from t1;
a b c 1 NULL 1 22 NULL
insert delayed ignore t1 values (NULL, NULL, 30);
Warnings:
Warning 1048 Column 'a' cannot be null
insert delayed ignore t1 values (1, 3, NULL);
Warnings:
Warning 1048 Column 'a' cannot be null
flush table t1;
select * from t1;
a b c 1 NULL 1 22 NULL 0 NULL 30 03 NULL
delete from t1;
alter table t1 add primary key (a);
create trigger trgu before update on t1 for each row set new.a=if(new.a is null,new.b,new.c);
insert t1 values (100,100,100), (200,200,200), (300,300,300);
insert t1 values (100,100,100) on duplicate key update a=10, b=NULL, c=1;
insert t1 values (200,200,200) on duplicate key update a=NULL, b=2, c=NULL;
insert t1 values (300,300,300) on duplicate key update a=NULL, b=NULL, c=20; ERROR23000: Column 'a' cannot be null
insert t1 values (300,300,300) on duplicate key update a=1, b=2, c=NULL; ERROR23000: Column 'a' cannot be null
select * from t1;
a b c 1 NULL 1 22 NULL 300300300
delete from t1;
insert t1 values (1,100,1), (2,200,2); replace t1 values (10, NULL, 1); replace t1 values (NULL, 2, NULL); replace t1 values (NULL, NULL, 30); ERROR23000: Column 'a' cannot be null replace t1 values (1, 3, NULL); ERROR23000: Column 'a' cannot be null
select * from t1;
a b c 1 NULL 1 22 NULL
delete from t1;
insert t1 values (100,100,100), (200,200,200), (300,300,300);
update t1 set a=10, b=NULL, c=1 where a=100;
update t1 set a=NULL, b=2, c=NULL where a=200;
update t1 set a=NULL, b=NULL, c=20 where a=300; ERROR23000: Column 'a' cannot be null
update t1 set a=1, b=2, c=NULL where a=300; ERROR23000: Column 'a' cannot be null
select * from t1;
a b c 1 NULL 1 22 NULL 300300300 set statement sql_mode='' for update t1 set a=1, b=2, c=NULL where a > 1; ERROR23000: Duplicate entry '0' for key 'PRIMARY'
select * from t1;
a b c 1 NULL 1 02 NULL 300300300
update t1 set a=NULL, b=4, c=a where a=300;
select * from t1;
a b c 1 NULL 1 02 NULL 44 NULL
delete from t1;
create table t2 (d int, e int);
insert t1 values (100,100,100), (200,200,200), (300,300,300);
insert t2 select a,b from t1;
update t1,t2 set a=10, b=NULL, c=1 where b=d and e=100;
update t1,t2 set a=NULL, b=2, c=NULL where b=d and e=200;
update t1,t2 set a=NULL, b=NULL, c=20 where b=d and e=300; ERROR23000: Column 'a' cannot be null
update t1,t2 set a=1, b=2, c=NULL where b=d and e=300; ERROR23000: Column 'a' cannot be null
select * from t1;
a b c 1 NULL 1 22 NULL 300300300
update t1,t2 set a=NULL, b=4, c=a where b=d and e=300;
select * from t1;
a b c 1 NULL 1 22 NULL 44300
delete from t1;
insert t2 values (2,2);
create view v1 as select * from t1, t2 where d=2;
insert v1 (a,c) values (10, 1);
insert v1 (a,b) values (NULL, 2);
insert v1 (a,c) values (NULL, 20); ERROR23000: Column 'a' cannot be null
insert v1 (a,b) values (1, 2); ERROR23000: Column 'a' cannot be null
select * from v1;
a b c d e 1 NULL 122 22 NULL 22
delete from t1;
drop view v1;
drop table t2;
load data infile 'mdev8605.txt' into table t1 fields terminated by ','; ERROR23000: Column 'a' cannot be null
select * from t1;
a b c 1 NULL 1 22 NULL
drop table t1;
create table t1 (a timestamp not null default now() on update now(), b int auto_increment primary key);
create trigger trgi before insert on t1 for each row set new.a=if(new.a is null, '2000-10-20 10:20:30', NULL); set statement timestamp=777777777 for insert t1 (a) values (NULL); set statement timestamp=888888888 for insert t1 (a) values ('1999-12-11 10:9:8');
select b, a, unix_timestamp(a) from t1;
b a unix_timestamp(a) 12000-10-2010:20:30972030030 21998-03-0303:34:48888888888 set statement timestamp=999999999 for update t1 set b=3 where b=2;
select b, a, unix_timestamp(a) from t1;
b a unix_timestamp(a) 12000-10-2010:20:30972030030 32001-09-0903:46:39999999999
create trigger trgu before update on t1 for each row set new.a='2011-11-11 11:11:11';
update t1 set b=4 where b=3;
select b, a, unix_timestamp(a) from t1;
b a unix_timestamp(a) 12000-10-2010:20:30972030030 42011-11-1111:11:111321002671
drop table t1;
create table t1 (a int auto_increment primary key);
create trigger trgi before insert on t1 for each row set new.a=if(new.a is null, 5, NULL);
insert t1 values (NULL);
insert t1 values (10);
select a from t1;
a 5 6
drop table t1;
create table t1 (a int, b int, c int);
create trigger trgi before insert on t1 for each row set new.a=if(new.a is null,new.b,new.c);
insert t1 values (10, NULL, 1);
insert t1 values (NULL, 2, NULL);
insert t1 values (NULL, NULL, 20);
insert t1 values (1, 2, NULL);
select * from t1;
a b c 1 NULL 1 22 NULL
NULL NULL 20
NULL 2 NULL
drop table t1;
create table t1 (a1 tinyint not null, a2 timestamp not null,
a3 tinyint not null auto_increment primary key,
b tinyint, c int not null);
create trigger trgi before insert on t1 for each row
begin if new.b=1 then set new.a1=if(new.c,new.c,null); end if; if new.b=2 then set new.a2=if(new.c,new.c,null); end if; if new.b=3 then set new.a3=if(new.c,new.c,null); end if;
end| set statement timestamp=777777777 for
load data infile 'sep8605.txt' into table t1 fields terminated by ','; ERROR23000: Column 'a1' cannot be null
select * from t1;
a1 a2 a3 b c 12010-11-1201:02:031000 22010-11-1201:02:031112 31994-08-2503:22:571200 42000-09-0807:06:05132908070605 51994-08-2503:22:571420 62010-11-1201:02:031500 72010-11-1201:02:0320320 82010-11-1201:02:032130
delete from t1; set statement timestamp=777777777 for
load data infile 'sep8605.txt' into table t1 fields terminated by ','
(@a,a2,a3,b,c) set a1=100-@a; ERROR23000: Column 'a1' cannot be null
select 100-a1,a2,a3,b,c from t1; 100-a1 a2 a3 b c 12010-11-1201:02:031000 982010-11-1201:02:031112 31994-08-2503:22:571200 42000-09-0807:06:05132908070605 51994-08-2503:22:571420 62010-11-1201:02:032200 72010-11-1201:02:0320320 82010-11-1201:02:032330
delete from t1; set statement timestamp=777777777 for
load data infile 'fix8605.txt' into table t1 fields terminated by ''; ERROR23000: Column 'a1' cannot be null
select * from t1;
a1 a2 a3 b c 12010-11-1201:02:031000 51994-08-2503:22:571420 82010-11-1201:02:032430
delete from t1; set statement timestamp=777777777 for
load xml infile 'xml8605.txt' into table t1 rows identified by '<row>'; ERROR23000: Column 'a1' cannot be null
select * from t1;
a1 a2 a3 b c 12010-11-1201:02:031000 22010-11-1201:02:031112 31994-08-2503:22:571200 42000-09-0807:06:05132908070605 51994-08-2503:22:571420 62010-11-1201:02:032500 72010-11-1201:02:0320320 82010-11-1201:02:032630
drop table t1;
create table t1 (a int not null default 5, b int, c int);
create trigger trgi before insert on t1 for each row set new.b=new.c;
insert t1 values (DEFAULT,2,1);
select * from t1;
a b c 511
drop table t1;
create table t1 (a int not null, b int not null default 5, c int);
create trigger trgi before insert on t1 for each row
begin if new.c=1 then set new.a=1, new.b=1; end if; if new.c=2 then set new.a=NULL, new.b=NULL; end if; if new.c=3 then set new.a=2; end if;
end|
insert t1 values (9, 9, 1);
insert t1 values (9, 9, 2); ERROR23000: Column 'a' cannot be null
insert t1 (a,c) values (9, 3);
select * from t1;
a b c 111 253
drop table t1; set session sql_mode ='no_auto_value_on_zero';
create table t1 (id int unsigned auto_increment primary key);
insert t1 values (0);
select * from t1;
id 0
delete from t1;
create trigger t1_bi before insert on t1 for each row begin end;
insert t1 values (0);
insert t1 (id) values (0); ERROR23000: Duplicate entry '0' for key 'PRIMARY'
drop table t1;
create table t1 (a int not null, b int);
create trigger trgi before update on t1 for each row do 1;
insert t1 values (1,1),(2,2),(3,3),(1,4);
create table t2 select a as c, b as d from t1;
update t1 set a=(select count(c) from t2 where c+1=a+1 group by a);
select * from t1;
a b 21 12 13 24
drop table t1, t2;
create table t1 (a int not null);
create table t2 (f1 int unsigned not null, f2 int);
insert into t2 values (1, null);
create trigger tr1 before update on t1 for each row do 1;
create trigger tr2 after update on t2 for each row update t1 set a=new.f2;
update t2 set f2=1 where f1=1;
drop table t1, t2;
create table t1 (a int not null, primary key (a));
insert into t1 (a) values (1);
show columns from t1;
Field Type Null Key Default Extra
a int(11) NO PRI NULL
create trigger t1bu before update on t1 for each row begin end;
show columns from t1;
Field Type Null Key Default Extra
a int(11) NO PRI NULL
insert into t1 (a) values (3);
show columns from t1;
Field Type Null Key Default Extra
a int(11) NO PRI NULL
drop table t1;
create table t1 (
pk int primary key,
i int,
v1 int as (i) virtual,
v2 int as (i) virtual
);
create trigger tr before update on t1 for each row set @a = 1;
insert into t1 (pk, i) values (null, null); ERROR23000: Column 'pk' cannot be null
drop table t1;
#
# MDEV-19761 Before Trigger not processed for Not Null Columns if no explicit value and no DEFAULT
#
create table t1( id int, rate int not null);
create trigger test_trigger before insert on t1 for each row set new.rate=if(new.rate is null,10,new.rate);
insert into t1 (id) values (1);
insert into t1 values (2,3);
select * from t1;
id rate 110 23
create orreplace trigger test_trigger before insert on t1 for each row if new.rate is null then set new.rate = 15; end if;
$$
insert into t1 (id) values (3);
insert into t1 values (4,5);
select * from t1;
id rate 110 23 315 45
drop table t1;
#
# MDEV-35911 Assertion `marked_for_write_or_computed()' failed in bool Field_new_decimal::store_value(const my_decimal*, int*)
# set sql_mode='';
create table t1 (c fixed,c2 binary (1),c5 fixed not null);
create trigger tr1 before update on t1 for each row set @a=0;
insert into t1 (c) values (1);
Warnings:
Warning 1364 Field 'c5' doesn't have a default value
drop table t1; set sql_mode=default;
#
# MDEV-36026 Problem with INSERT SELECT on NOT NULL columns while having BEFORE UPDATE trigger
#
create table t1 (b int(11) not null);
create trigger t1bu before update on t1 for each row begin end;
insert t1 (b) select 1 union select 2;
create trigger trgi before insert on t1 for each row set new.b=ifnull(new.b,10);
insert t1 (b) select NULL union select 11;
select * from t1;
b 1 2 10 11
drop table t1;
# End of 10.5 tests
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-10-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.