Product: MapBasic
Version: 6.x
Platform: Not Platform Related
Category: Documentation
Summary:
Update Statement - Description.
Question:
How is the update statement used in MapBasic?
Answer:
Update statement
Purpose
Modifies one or more rows in a table.
Syntax
Update table Set column = expr [, column = expr, ...]
[ Where RowID = idnum ]
table is the name of an open table
column is the name of a column
expr is an expression to assign to a column
idnum 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.
Examples
In the following example, there is a table of employee data; each record states the employee's department and salary. Let's say it is desired 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, MapBasic will 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
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
Creating and modifying tables.
Last Modified: 06/04/2001 01:13:28 PM
|