Insert 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

Appends new rows to an open table. You can issue this statement from the MapBasic window in MapInfo Pro.

Syntax

Insert Into table 
	[ ( columnlist ) ] 
	{ Values ( exprlist ) | Select columnlist From table }
	[ DropIndex ( Auto | On | Off ) ]

table is the name of an open table.

columnlist is a list of column expressions, comma-separated.

exprlist is a list of one or more expressions, comma-separated.

Description

The Insert statement inserts new rows into an open table. There are two main forms of this statement, allowing you to either add one row at a time, or insert groups of rows from another table (via the Select clause). In either case, the number of column values inserted must match the number of columns in the column list. If no column list is specified, all fields are assumed. Note that you must use a Commit Table statement if you want to permanently save newly-inserted records to disk.

If you know exactly how many columns are in the table you are modifying, and if you have values to store in each of those columns, then you do not need to specify the optional columnlist clause.

In the following example, we know that the table has four columns (Name, Address, City, and State), and we provide MapBasic with a value for each of those columns.

Insert Into customers
	Values ("Mary Ryan", "23 Main St", "Dallas", "TX")

The preceding statement would generate an error at run-time if it turned out that the table had fewer than (or more than) four columns. In cases where you do not know exactly how many columns are in a table or the exact order in which the columns appear, you should use the optional columnlist clause.

Specifying that the DropIndex clause is On suspends updating transaction indexes while executing the operation and recreates them when the operation is complete. When the DropIndex clause is Off or Auto the operation executes without suspending and recreating the transaction indexes.

Examples

The following example inserts a new row into the customer table, while providing only one column value for the new row; thus, all other columns in the new row will initially be blank. Here, the one value specified by the Values clause will be stored in the "Name" column, regardless of how many columns are in the table, and regardless of the position of the "Name" column in the table structure.

Insert Into customers (Name)
	Values ("Steve Harris")

The following statement creates a point object and inserts the object into a new row of the Sites table. Note that Obj is a special column name representing the table's graphical objects.

Insert Into sites (Obj) 
	Values ( CreatePoint(-73.5, 42.8) )

The following example illustrates how the Insert statement can append records from one table to another. In this example, we assume that the table NY_ZIPS contains ZIP Code boundaries for New York state, and NJ_ZIPS contains ZIP Code boundaries for New Jersey. We want to put all ZIP Code boundaries into a single table, for convenience's sake (since operations such as Find can only work with one table at a time).

Accordingly, the Insert statement below appends all of the records from the New Jersey table into the New York table.

Insert Into NY_ZIPS
	Select * From NJ_ZIPS 

In the following example, we select the graphical objects from the table World, then insert each object as a new record in the table Outline.

Open Table "world"
Open Table "outline"
	Insert Into outline (Obj)
	Select Obj From World 

See Also:

Commit Table statement, Delete statement, Rollback statement