Вы можете заполнить [InsertDate]
значением по умолчанию GETDATE()
и заполнить [UpdateDate]
текущей датой при обновлении столбца (поскольку вы используете процедуры ( wink ), этодействительно легко контролировать).Если вы не используете процедуры и хотите контролировать.В столбце [UpdateDate]
вы можете использовать триггер для заполнения этого столбца.
Пусть столбец Activity
будет вычисляемым полем:
DATEDIFF(day, [InsertDate], [UpdateDate])
DATEDIFF
Расчетные столбцы
Из MSDN о вычисляемых столбцах:
Unless otherwise specified, computed columns are virtual columns that are
not physically stored in the table. Their values are recalculated every
time they are referenced in a query. The Database Engine uses the PERSISTED
keyword in the CREATE TABLE and ALTER TABLE statements to physically store
computed columns in the table. Their values are updated when any columns
that are part of their calculation change. By marking a computed column as
PERSISTED, you can create an index on a computed column that is
deterministic but not precise.