OK, there are two issues here.
One is that you are denormalising your data by adding a surrogate ID. However it is probably too late for you to change this.
One solution would be to use a sequence rather than an auto-increment column. There is a cargo cult that like functions that return the last insert ID - and indeed it may be possible to do this with access - but sequences are your friend. In that approach, you first query the database for the next number from the sequence generator (a very fast query) and then you can insert it. You can forgoe that step by putting the sequence expression directly in the insert query, but then you have the same problem - how do you return it?
It turns out that you are using the table expecting the host column to be the real primary key.
You can guard the table from having duplicate host records by adding a unique index;
CREATE UNIQUE INDEX HOST_IDX ON Apps (Host_ID);
It is possible to further constrain the table by saying that the ID must exist in the other table, this is called a "foreign key".
You sound like you are ready to move onto the next stage with your database exploration. I can highly recommend SQLite if you don't need to continue to use the MS-Access front-end, or PostgreSQL if you still need something you can access via ODBC (I assuming MS-Access can access a real database - however I never tried that).
$h=$ENV{HOME};my@q=split/\n\n/,`cat $h/.quotes`;$s="$h/." ."signature";$t=`cat $s`;print$t,"\n",$q[rand($#q)],"\n";
In reply to Use indexes, sequences
by mugwumpjism
in thread SQL statment to insert if none exits and to obtain the primary key of a record with one visit!
by blackadder
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |