I want to insert a row in a table, and when I do the insertion I want to insert another row in another table at the same time.
What is the more efficient way to do this in an Android app?
Is it more efficient to do a trigger when I insert one row and SQL takes care of the insertion, or do two inserts with database.insert() in Java?
The information needed to insert the second row is already in the first insertion.
Thanks!
For sure use for this
TRIGGER, because it working on database layer so you only need to create it and then it will be called itself when you do something(depends on how you implement trigger).Also it’s more faster and you do not call it explicit, just let database work. All what is database able to do, let do it on database.
Update:
So after a little discussion with @Graham Borland you can use also inserts in
TRANSACTION.Have look at Android Database Transaction.
And conclusion what is faster?
I exactly don’t know it because i don’t have performance tests but for sure
TRANSACTIONSare the safest i think but whether faster thanTRIGGERSthis i don’t know exactly but usage of transactions is very good and mainly safe approach to prevent database get to incorrect state that is very undesirable.