sql - Add "DateModified" Column with an Update Trigger To All Tables that contain a "DateCreated" Column -
I have several tables that have a [DateCreated]
column whose date Coded]
column. Columns [DateModified]
column will require an update
trigger that contains the current date ( getdate ()
) this new In the
Each table uses custom schema, [dbo]
not.
Is that the easiest / best way to do this?
This will give you the table table description, to execute you in a new query window / Can paste. To generate trigger statement I will leave it as a practice to use the same technique for the reader.
Select 'change table' + name (+ .name) + '.' + Add 'DateModified] datetime' from Cotnam (TNN) + 'sys.column c. C includes c.object_id = t.object_id internal entry on sys.schemas s t.schema_id = s Left at left .schema_id, t.object_id = c2.object_id and c2.name = 'DateModified' on Sys.columns c2 where c.name = 'DateCreated' and t.type = 'U' and c2.column_id are empty / date Dated column is not already present * /
Comments
Post a Comment