Is Microsoft full of #*$#*% (again) or am I badly misunderstandin g
something?
Quote from Microsoft's T-SQL doc:[color=blue]
> INSTEAD OF triggers are executed instead of the triggering action.
> These triggers are executed after the inserted and deleted tables
> reflecting the changes to the base table are created, but before any
> other actions are taken. They are executed before any constraints,[/color]
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^[color=blue]
> so can perform preprocessing that supplements the constraint actions.[/color]
(SQL Server 2000 sp3a)
CREATE TABLE t (
a INT PRIMARY KEY,
b CHAR(1) NOT NULL)
I want to override the value of [b] with the value of 'X' when
inserting into t...
CREATE TRIGGER t_tbi ON t INSTEAD OF INSERT AS BEGIN
SET NOCOUNT ON
INSERT INTO t (a,b) (SELECT a,'X' FROM inserted)
END
Let's try it...
INSERT INTO t (a,b) VALUES(1,'z')
SELECT * FROM t
a | b
---|---
1 | X
Good, the trigger did what it was supposed to. Lets try a
slight variation...
INSERT INTO t (a) VALUES(2)
Server: Msg 233, Level 16, State 2, Line 1
The column 'b' in table 't' cannot be null.
WTF? What was that I just read about "[instead-of triggers]
are executed before any constraints"?!? !
What's going on here???
something?
Quote from Microsoft's T-SQL doc:[color=blue]
> INSTEAD OF triggers are executed instead of the triggering action.
> These triggers are executed after the inserted and deleted tables
> reflecting the changes to the base table are created, but before any
> other actions are taken. They are executed before any constraints,[/color]
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^[color=blue]
> so can perform preprocessing that supplements the constraint actions.[/color]
(SQL Server 2000 sp3a)
CREATE TABLE t (
a INT PRIMARY KEY,
b CHAR(1) NOT NULL)
I want to override the value of [b] with the value of 'X' when
inserting into t...
CREATE TRIGGER t_tbi ON t INSTEAD OF INSERT AS BEGIN
SET NOCOUNT ON
INSERT INTO t (a,b) (SELECT a,'X' FROM inserted)
END
Let's try it...
INSERT INTO t (a,b) VALUES(1,'z')
SELECT * FROM t
a | b
---|---
1 | X
Good, the trigger did what it was supposed to. Lets try a
slight variation...
INSERT INTO t (a) VALUES(2)
Server: Msg 233, Level 16, State 2, Line 1
The column 'b' in table 't' cannot be null.
WTF? What was that I just read about "[instead-of triggers]
are executed before any constraints"?!? !
What's going on here???
Comment