Purpose
Modifies one or more rows in a table. You can issue this statement from the MapBasic window in MapInfo Pro.
Syntax
Update table Set column = expr [ , column = expr, ...]
[ Where [ RowID = id ] | expr ]
[ DropIndex ( Auto | On | Off ) ]
table is the name of an open table.
column is the name of a column.
expr is one or more expressions, separated by the keywords AND or OR.
id is the number of a row in the table.
Description
The Update statement modifies one or more columns in a table. By default, the Update statement will affect all rows in the specified table. However, if the statement includes a Where RowID clause, only one particular row will be updated. The Set clause specifies what sort of changes should be made to the affected row or rows.
To update the map object that is attached to a row, specify the column name Obj in the Set clause; see example below.
Specifying that the DropIndex clause is On suspends updating transaction indexes while executing the operation and recreates them when the operation is complete. In some cases this significantly improves performance, but not always. For the best performance, we recommend setting this clause to Auto, so that MapInfo Pro decides whether or not to suspend and recreate indexes. MapInfo Pro will suspend and recreate indexes later if the operation is deleting or updating the rows and the table contains more than 1000 rows and more than 0.1% of the total rows are getting updated. When the DropIndex clause is Off the operation executes without suspending and recreating the transaction indexes.
Update PopAreas Set Area_sqm = Area(obj, "sq_m") Where Area_sqm = 0
"4 > RowId OR 2 < RowId" instead of "RowId > 4 OR RowId < 2"
Examples
In the following example, we have a table of employee data; each record states the employee's department and salary. Let us say we wish to give a seven percent raise to all employees of the marketing department currently earning less than $20,000. The example below uses a Select statement to select the appropriate employee records, and then uses an Update statement to modify the salary column accordingly.
Select * From employees
Where department ="marketing" And salary < 20000
Update Selection
Set salary = salary * 1.07
By using a Where RowID clause, you can tell MapBasic to only apply the Set operation to one particular row of the table. The following example updates the salary column of the tenth record in the employees table:
Update employees
Set salary = salary * 1.07
Where Rowid = 10
By using a Where expression clause, you can tell MapBasic to only apply the Set operation to selected rows of the table. The following example updates the salary column of employees having more than five years of experience in the employees table:
Update employees
Set salary = salary * 1.07
Where EmpExp > 5
The next example stores a point object in the first row of a table:
Update sites
Set Obj = CreatePoint(x, y)
Where Rowid = 1
See Also: