To delete a row from a database table, you use the following technique:
The SELECT statement you issue to return the row to be deleted cannot contain a join operation. You can use this technique only to delete rows returned from a single table.
The following sample code contains two blocks of code to be evaluated separately.
The first block deletes the row created in the example for inserting a new row into a table:
The second block retrieves the STAFF table and converts it to an ordered collection that you can inspect.
Before you can evaluate this sample code, you need to connect to the database and create the row to be deleted.
To use these blocks of code, follow these steps:
"Delete a row from a table" | connection querySpec row | connection := AbtDbmSystem activeDatabaseConnectionWithAlias: 'SAMPLE'. querySpec := (AbtQuerySpec new) statement: 'SELECT * from STAFF where ID = 999 '. row := (connection resultTableFromQuerySpec: querySpec) first. (connection openTableNamed: 'STAFF') deleteRow: row. "Select table to show row has been deleted" | connection querySpec result resultCollection | resultCollection := OrderedCollection new. connection := AbtDbmSystem activeDatabaseConnectionWithAlias: 'SAMPLE'. querySpec := (AbtQuerySpec new) statement: 'SELECT * from STAFF'. result := connection resultTableFromQuerySpec: querySpec. result do: [:eachRow | resultCollection add: (eachRow asString)]. ^resultCollection.