Additionally, add a column Validation Rule (or CHECK
constraint) to ensure the 'timestamp' column is updated when the table is being updated other than via your form. The SQL DLL (ANSI-92 Query Mode syntax) would look something like this:
CREATE TABLE MyTable
(
key_col INTEGER NOT NULL UNIQUE,
data_col INTEGER NOT NULL
)
;
ALTER TABLE MyTable ADD
my_timestamp_col DATETIME
DEFAULT NOW()
NOT NULL
;
ALTER TABLE MyTable ADD
CONSTRAINT my_timestamp_col__must_be_current_timestamp
CHECK (my_timestamp_col = NOW())
;
Another approach when using Jet 4.0 (pre-Access 2007 i.e. before user level security was removed from the engine) is to create a 'helper' Jet SQL PROCEDURE
(Access term: stored Query object defined using an SQL 'Action' statement, as distinct from a SQL SELECT
query) that automatically updates the 'timestamp' column then remove 'update' privileges from the table and grant them instead on the PROC
e.g. SQL DDL/DCL something like:
CREATE PROCEDURE MyProc
(
arg_key INTEGER,
arg_new_data INTEGER
)
AS
UPDATE MyTable
SET data_col = arg_new_data,
my_timestamp_col = NOW()
WHERE key_col = arg_key
;
REVOKE UPDATE ON MyTable FROM PUBLIC
;
GRANT UPDATE ON MyProc TO PUBLIC
;
The advantage here is all updates must go via the PROC
and therefore is under the developer's control; the disadvantage is Access/Jet SQL is that your form will also have to use the PROC
, which means a paradigm shift away from the standard 'data bound forms' approach for which Access is famous.