I want to have two auto_increment column's per table, but mysql allows only one auto_increment columns. So, I tried replicating the oracle sequence using my own table.
Here is the schema.
create table logical_id_seq (
logical_id int auto_increment,
primary key(logical_id)
);
create table mytable (
physical_id int auto_increment,
logical_id int not null references parent(logical_id),
data varchar(20),
version_start_date datetime not null,
version_end_date datetime not null,
primary key(physical_id),
foreign key (logical_id) references logical_id_seq(logical_id),
unique key (logical_id,version_start_date,version_end_date)
);
So, the logical_id_seq table is used as a sequence generator.
creating new entity:
- Insert new entry into logical_id_seq.
- Read the last_insert_id() from logical_id_seq.
- Use the above value to insert a new row in the table.
Let me give you little more context on logical_id and physical_id. I want to design a time travel database, meaning I want the database state given any timestamp(now or past). So, I am having version_start_date and version_end_date.
Can you please tell me if there are side effects to my method of sequence generator.