Before insert trigger
Got fields a,b, both in primary key.
will not work --> column b can not be null.
insert into t (a) values ('foo')
Have trigger on table t, before insert, which assigns value to b
same thing will not work --> column b can not be null.
Trigger on before insert is not even triggered, tested.
I guess what I would expect is, having trigger as described, insert should work ?
EDIT: (in short)
It works like this:
2. check for various things like 'can not be null'
3. Before insert trigger is triggered
What I would expect:
2. Before insert trigger is triggered
3. check for various things like 'can not be null'
Show the actual trigger.
SHOW CREATE TRIGGER triggername;
The docs say it can work if done correctly.
I just tried it. That worked perfectly in MySQL 5.5 for me.
CREATE TRIGGER yourname BEFORE INSERT ON t
FOR EACH ROW
SET NEW.b = 'whatever';
Oops...forgot: My table was created thus:
the trigger did not work if b did not have a default value.
CREATE TABLE t ( a INT NOT NULL, b INT NOT NULL DEFAULT 0 );
But by doing it this way, the trigger effectively overrides the default value, so the default value is of no consequence.
Hmm, yes, sorry to waste your time, I'm using great client for mysql which enables me to import .csv via it. But unfortunately that part is crappy, specialy if there is error in .csv format.
And that was the cause of all troubles.