INSERT – SQL Command Examples

The following example opens the employee table and adds one record.

USE employee
INSERT INTO employee (emp_no, fname, lname, officeno) ;
   VALUES (3022, "John", "Smith", 2101)

The following example opens the customer table in the testdata database. The contents of the current record are scattered to variables, and the table's structure is copied to a new table named cust2. INSERT - SQL is used to insert a new record in the cust2 table, and BROWSE is issued to display the new record.

CLOSE DATABASES
CLEAR

OPEN DATABASE (HOME(2) + 'Data\testdata')
USE Customer     && Open customer table
* Scatter current record to memory variables
SCATTER MEMVAR

* Copy structure of current table to example table
COPY STRUCTURE TO cust2

* Insert record from memory variable
INSERT INTO cust2 FROM MEMVAR

SELECT CUST2
BROWSE

* Close and delete example table
USE
DELETE FILE cust2.dbf