I would like to add an autoincrementing integer field called uid to an existing table assoc, but it doesn’t look like I can do that unless it’s a primary key.
I have fields local_id and remote_id which are the existing primary key pair, and I do that so that I can INSERT OR IGNORE INTO assoc so that I don’t get duplicate primary keys, but if I have a pair of columns as a primary key, I can’t seem to use them as an update (see other SO question).
Could anyone suggest how to restructure the table (and implement that restructuring using ALTER TABLE) so that I can get the behavior I need:
- a single autoincrementing key, so I can use that for
UPDATEs - a pair of fields
local_idandremote_idso that the pair(local_id, remote_id)remains unique in the table
In this case, you could drop the primary key on your existing columns, create the new primary key integer autoincrementing column, then create a UNIQUE index on the other two columns.