GSAK (Geocaching Swiss Army Knife)
 

Contents - Index


SQL - Insert Into


Allows you to insert a data record into a table. This command can also insert many records at once by selecting them from another table using a sub-select.

Syntax:

   INSERT INTO tablename [(field1[,fieldN])] VALUES (field1value[,fieldNvalue])

Or

  INSERT INTO tablename selectstatement
 
Where field values are ordered in the same order as the field names and must match the type (numbers as plain numbers and string as single-quoted text).
 

Example:
 

$Status = sql("CREATE TABLE userdata (code,comment,Rating)","")
$status = sql("INSERT INTO userdata VALUES ('GC1EAC','Great views over the vally',8);","") 
$Status = sql("Commit","")

 
or 
 

$Status = sql("CREATE TABLE userdata (code,comment,Rating)","")
$status = sql("INSERT INTO userdata (code,comment,rating) VALUES ('GC1EAC','Great views over the vally',8);","") 
$Status = sql("Commit","")

 
or
 

$status = sql("CREATE TABLE userdata (code,comment,rating)","")
$status = sql("INSERT INTO userdata SELECT * FROM userdata2 WHERE rating > 5","")
$Status = sql("Commit","")

 
Notes
When you insert records using select statement, the output fields of the select statment must match the field names of tablename. Only values of matching field names will be inserted.

Note that the opposite of "INSERT INTO" is the "DELETE FROM" SQL command.
Copyright 2004-2008 CWE Computer Services  
Privacy Policy Contact