Delete in sql - Inner Join

0

How is the syntax of a query using Inner Join delete in sql, to compare two-table code and exclude to be equal?

Sales item table. in the item sale table, a sale has been registered whose code is 4. To execute the reversal, if applicable, the user can remove.

ControltableBox.Whenreversed,therecordoftheitemsaletablewillberemovedandatthesametimewillberemoved,therecordwhosecodDoc=4.Thisdocumentcodeisgeneratedwhenthesaleisfinalized.

    
asked by anonymous 27.05.2017 / 20:56

1 answer

0

In your situation, the recommended one would be an FK with Cascade on delete, the bank will do that.

But still if you do not use the bank's resources, in the command, I imagine either you will execute something like:

"Delete from Vendas where Codigo = 4;"

So you should run the following commands:

Delete from controleCaixa where codDoc = 4;
Delete from itemVenda where venda =4;
Delete from venda where codigo = 4;

All in the same transaction.

    
27.05.2017 / 21:35