If I have a trigger defined to fire "BEFORE INSERT,UPDATE", is there a way to determine whether the event is question is an INSERT or UPDATE? The table involved has at least one field defined as "not null", so at first blush I'm tempted to use something like this:
I've looked to see if there is a built-in variable I can reference to make the determination, but my searching powers are apparently too weak. We are using SQL/Anywhere 16.
Yes, you can use the "Trigger operation conditions" to tell an INSERT from an UPDATE.
More on this is also discussed in that other FAQ.
Note that your proposed code won't work: There's no OLD row to check in an INSERT statement - IMHO, the operation will fail, and so will the INSERT, either.
If you simply want to fill a NOT NULL column with a value, you simply can do so in a BEFORE INSERT trigger, as the NOT NULL check will be done later, so you simply might use:
FWIW, here's an old posting by Glenn Paulley with detailed insights (as expected...) on the internal steps a trigger has to consider - cf. that old NNTP article "Before update trigger and computed column " - I'm not sure whether it is fully true for current versions, however, a BEFORE TRIGGER surely is run before NULLs in NOT NULL columns are checked.