Delete statement - MapBasic - 2023

MapInfo MapBasic Reference

Product type
Software
Portfolio
Locate
Product family
MapInfo
Product
MapInfo > MapBasic
Version
2023
Language
English
Product name
MapBasic
Title
MapInfo MapBasic Reference
First publish date
1985
Last updated
2023-09-12
Published on
2023-09-12T16:32:32.686312

Purpose

Deletes one or more graphic objects, or one or more entire rows, from a table. You can issue this statement from the MapBasic window in MapInfo Pro.

Syntax

Delete [ Object ] From table 
	[ Where [ Rowid = id_number ] | expr ]
	[ DropIndex ( Auto | On | Off ) ]

table is the name of an open table.

id_number is the number of a single row (an integer value of one or more).

expr is an expression to assign to a column or row.

Description

The Delete statement deletes graphical objects or entire records from an open table. By default the Delete statement:

  • Deletes all records from a table. However, if the statement includes the optional Object keyword, MapBasic only deletes the graphical objects that are attached to the table, rather than deleting the records themselves.
  • Affects all records in the table. However, if the statement includes the optional Where Rowid =...clause, then only the specified row is affected by the Delete statement.
  • Affects all records in the table. However, if the statement includes the optional Where expr...clause, then only the selected row is affected by the Delete statement.

There is an important difference between a Delete Object From statement and a Drop Map statement. A Delete Object From statement only affects objects or records in a table, it does not affect the table structure itself. A Drop Map statement actually modifies the table structure, so that graphical objects may not be attached to the table.

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.

The Delete statement also supports providing an expression in the WHERE clause. In case the statement include a WHERE expression clause, only the rows matching the expression are affected.
Delete Object From clients Where Status = 0
If you want to use RowId as an expression in the WHERE clause, use like:
"4 > RowId OR 2 < RowId" instead of "RowId > 4 OR RowId < 2"

Examples

The following Delete statement deletes all of the records from a table. At the conclusion of this operation, the table still exists, but it is completely empty as if the user had just created it.

Open Table "clients"
Delete From clients
 Table clients

The following Delete statement deletes only the object from the tenth row of the table:

Open Table "clients"
Delete Object From clients Where Rowid = 10
 Table clients

The following Delete statement deletes only the object from with status = 0 (inactive):

Open Table "clients"
Delete Object From clients Where Status = 0
 Table clients

See Also:

Drop Map statement, Insert statement