Sql-server – Check for changes in a text column

sql serversql-server-2012t-sqltrigger

Using SQL Server 2012, how can I check for changes in a text column?

I know the text datatype has been deprecated, and get the ever helpful message

Cannot use text, ntext, or image columns in the 'inserted' and 'deleted' tables.

when trying to reference the existing text column in a trigger, so things like joining inserted & deleted tables on the column does not work. UPDATE() would work, except it is always true (I am guessing the front end just pushes whatever data is in the form field regardless if it changed or not).

Any suggestions on how I can check for changes on the column?

Best Answer

Can you implement an INSTEAD OF UPDATE trigger? - a quick test on my local instances indicates you can reference the inserted and deleted tables. Naturally, you still have to apply the real update.

here was my quick test

create table TextDataTypeTest (Col1 text)
insert into dbo.textdatatypetest (col1) values('test')
----------------
create TRIGGER dbo.TextDataTypeTest_Trigger
   ON  dbo.TextDataTypeTest 
   instead of UPDATE
AS 
BEGIN

select col1 into #Before from deleted
select col1 into #After from inserted

select * from #Before

select * from #After
update a 
set a.col1=b.col1 
from dbo.textdatatypetest a join
inserted b on 1=1

END
GO


update dbo.textdatatypetest set col1='oneforalx'