Another Access 2000+ answer (Jet 4.0) is to create a Jet 4.0 VIEW (in terms of Access: a SELECT query stored as a query object) with an INNER JOIN in the IDENTITY (Autonumber) column; join columns must be open in the SELECT clause and in the referenced table. Then the INSERT INTO value is VIEW for all NOT NULL columns that do not have DEFAULT .
The value of the IDENTITY column may be omitted, in which case the engine will automatically generate the value as usual or an explicit value provided and executed; if the value of the join column in another table (that is, without the IDENTITY column) is additionally provided, then it must be the same as the IDENTITY value, otherwise an error will occur; if the IDENTITY value is omitted, then any value specified for the connection column will be ignored. Please note that a FOREIGN KEY usually expected between such tables, but is not a prerequisite for this process to work.
Quick example (Query Mode ANSI-92 Jet 4.0 query mode syntax):
CREATE TABLE Table1 ( key_col INTEGER IDENTITY NOT NULL PRIMARY KEY, data_col_1 INTEGER NOT NULL ) ; CREATE TABLE Table2 ( key_col INTEGER NOT NULL, data_col_2 INTEGER NOT NULL, PRIMARY KEY (key_col, data_col_2) ) ; CREATE VIEW View1 AS SELECT T1.key_col AS key_col_1, T2.key_col AS key_col_2, T1.data_col_1, T2.data_col_2 FROM Table2 AS T2 INNER JOIN Table1 AS T1 ON T1.key_col = T2.key_col ; INSERT INTO View1 (data_col_1, data_col_2) VALUES (1, 2) ;
onedaywhen
source share