You should understand the relationship between database (a physical server database like SQLite, Firebird, MySQL, etc.) and TDataset (TSQLQuery, TIBDataSet, etc. TMemDataSet or TBufDataSet are also TDataSet descendants).
When you open an SQL within TSQLQuery or whatever, like
Select * from counterparts;then what you actually have is a subset copy of the whole table (in this case whole table of counterparts. If there are any "where" clauses then you will copy only a subset of the whole table).
And TDataSet methods like edit, append, appendrecord, etc. operate only on the dataset, not the database file itself. In order to update your changes in the TDataSet to the permanent database file, you have to call
COUNTERPARTS.ApplyUpdates;And the transaction is on the permanent database file, not your TDataSet. So the exact order in your example would be:
// you can assign this anytime
COUNTERPARTS.SQL.Text := 'SELECT * FROM COUNTERPARTS';
// following section is downloading records from server database to TDataSet (COUNTERPARTS, in this case)
SQLTransaction1.Active := True;
COUNTERPARTS.open;
SQLTransaction1.CommitRetaining; // Simply opening a dataset, RollbackRetaining may be used as well
// As Transaction has been committed or rolled back, operations from now on has nothing to do with server database.
COUNTERPARTS.appendRecord(['1111',3,'name-1']);
COUNTERPARTS.appendRecord(['2222',3,'name-2']);
COUNTERPARTS.appendRecord(['3333',3,'name-3']);
COUNTERPARTS.appendRecord(['4444',3,'name-4']);
// As you have finished editing TDataSet, now you want to upload the TDataSet content to your permanent database file.
SQLTransaction1.Active := True;
CounterParts.ApplyUpdates;
SQLTransaction1.CommitRetaining;
In order for ApplyUpdates to work correctly, the property "use primary key as key" of counterparts should be set true (which is default), or you have to define InsertSQL, UpdateSQL, and DeleteSQL yourself.