Doubt with data recording time in master-detail tables?

1

After inserting a record, I use select max(IDControle) to retrieve the table id to record the items.

When the time is only 1 second, I noticed that the items were all recorded in the 1st record. Does anyone have any idea how this could be avoided?

insert into TB_C_ORCAMENTO (descricaosituacao) values ('exemplo');
select max(controle) from TB_C_ORCAMENTO;
insert into TB_D_ORCAMENTO (controle, descricaoproduto) values (10, 'teste');
    
asked by anonymous 13.07.2015 / 16:08

1 answer

0

This is not a good way to get the last Id entered. By competitive conditions, this Id may have been changed between one command and another.

#. The context is within Stored Procedure , but can be used in your application code if DbConnection is not closed.

    
13.07.2015 / 17:03