Should I be creating a TSQLTransaction for each TSQLQuery? Can you "share" a TSQLTransaction across multiple TSQLQuerys? I will indeed read up on this.
Yes, you can share a TSQLTransaction between TSQLQuerys, but it depends on the situation if you want/need to do this. In your example (with a simple
ShowModal-form to edit data) using the same TSQLTransaction that's connected to the TSQLConnection is not wrong. It's simple, clear to understand and does the job. You could even do with one TSQLQuery on your datamodule but could also have TSQLQuerys on the forms connected to the same TSQLTransaction.
But picture this... Your same customer database is growing to include offers, orders and invoices. You have the possibility to open 2, 3 or even more customer-detail-screens at the same time, while having multiple orders and invoices open too. Imagine how many TSQLQuerys you need on your datamodule. Especially if you're going to allow multiple customers, orders and invoices open at the same time it's best to create the TSQLQuery/TDatasource in the form where it is used.
As for the TSQLTransaction... if all TSQLQuery's where connected to the same TSQLTransaction (the one on a datamodule), if one TSQLQuery committed the transaction all the others would be committed too (if a Post was already issued). Granted... the time between a .Post and .Transaction.Commit on the other forms is small but it could happen. Having transaction control on the form itself gives you the ability to control it better (i.e. Rollback, Commit etc).
There are situations where you want to use the same TSQLTransaction between TSQLQuerys, for example when you want to access already posted data but not yet committed from that other query.
But as said... above is for multiple editing at the same time. For single editing (i.e. in ShowModal) one TSQLTransaction is fine. It's just that in the future you'll probably encounter situations where you need to understand transactions and use them. If you read-up on transactions it will become apparent when you should use them and where you can share them.
Have fun learning about transactions
