December 5, 2016 at 5:18 am
I would like to detect any changes done on update to a text column 'comments' through a trigger.
The column should be no longer than 200 characters.
Do I define the column as varchar or text ?
In my trigger: Would old.comments <> new.comments be okay. Is there a better more efficient way to do the comparison ?
Thanks
December 5, 2016 at 5:44 am
Field type text is deprecated, I would definitely use VARCHAR or NVARCHAR. ntext, text, and image (Transact-SQL)
Are you going to be comparing any other fields as well? As you're on 2016, have you considered Temporal (History) Tables instead of a trigger?
In a simple answer, yes, where new != old is fine, but thought best to bring up other solutions.
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
December 5, 2016 at 5:56 am
so I'm assuming you want a soft fix to the issue, where you are detecting and maybe truncating in the trigger to make it no more than 200 characters, even though the column supports more?
adding a hard fix, like setting the column size to 200 is not an option, right?
Lowell
December 5, 2016 at 6:14 pm
I haven't decided. What's your suggestion ?
December 6, 2016 at 6:58 pm
See if this is helpful to you .
https://msdn.microsoft.com/en-us/library/ms186329.aspx
The article has an example that makes use of a audit table. I have to wonder if you are not concerned about trimming important data from a field. Why does the field have to be less than 200 characters in the table of the database?
----------------------------------------------------
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply