You cannot access TEXT, NTEXT or IMAGE fields from INSERTED or DELETED. However you can access them from the base table by joining with INSERTED. This only works for INSERT and UPDATE because in a DELETE the base row no longer exists.
To achieve what you need, in another trigger, copy the primary key and TEXT, NTEXT and IMAGE columns to a side table.
For example
create table C1(
accountNo int identity primary key,
someColumn nvarchar(10),
someNtext ntext
)
create table C1_side(
accountNo int primary key,
someNtext ntext
)
create trigger trgC1_IU on C1 AFTER INSERT, UPDATE
as
BEGIN
-- Ensure side row exists
insert C1_side(accountNo, someNtext)
select accountNo from INSERTEd
where not exists (select 1 from C1_side where C1_side.accountNo = inserted.accountNo)
-- Copy NTEXT value to side row
update C1_side
set someNtext = c1.someNtext
from C1_side inner join C1 on C1_side.accountNo = C1.accountNo
inner join INSERTED on INSERTED.accountNo = C1.accountNo
-- Could improve by checking if the column was updated for efficiency
END
Now, in your DELETE trigger, you can join DELETED to C1_side to read the previous value of the ntext column. Note that you will have to populate initial values for your side table, for rows which already exist in C1.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…