SQL database system
 
Manual page for INSERT(TDH)


This manual page descibes the INSERT, UPDATE, and DELETE commands.


INSERT

INSERT writes one new row to a database table.

INSERT INTO table [ ( fieldname1 .., fieldnameN ) ]
VALUES (
value1 ..,valueN )

If fieldnames are not specified then table fields will be taken in natural order, which is probably a risky coding practice (use tabdef(1) to list the table's fields). Each value must be a constant. Any fields not mentioned will be initialized to null. Zero-length constants will be converted to null. INSERT cannot be used on temporary tables or ordinary files.

Examples:

insert into songs (id, artist, title, writer, length, album)
	values (1, "Pink Floyd", "Speak to me", 
		null, null, "Dark side of the moon")

insert into songs
	values (2, "Count Basie", "It's Oh So Nice", "", "", 
		"Basie, Straight Ahead")

insert into properties
	(id, mls, neighborhood, street, city, 
	 county, zip, school, listprice, style, 
	 bedrooms, bathrooms, lotsize, yearbuilt, 
	 heat, basement, features )

    	values ( 1, BA2804, "Rockdale", "", "Liddleford",
	"Westbrook", "01234", null, "234000", "rancher",
	3, 2, 0.34, 1984, "forced air", full, null )




UPDATE

UPDATE modifies one or more existing rows in a table, or can add a new row if ORINSERT is used.

UPDATE table [ ORINSERT ]
SET
fieldname1 = value1 ,
. .
fieldnameN = valueN
WHERE
conditional-expression
[MAXROWS
maxrows]

A WHERE clause is always required. It is not considered an error if no rows are found that meet the where clause (the row count may be checked to determine this). Each value must be a constant. Zero-length constants will be converted to null.

shsql extends standard SQL with the keywords ORINSERT and MAXROWS. If ORINSERT is specified, record(s) will be updated normally if found, but if not found a new record will be inserted (fields not SET will be null). MAXROWS may be used to raise the default row limit of 2000 rows or be set to a low number (typically 1) to ensure that an update will only affect an anticipated number of rows. If MAXROWS is exceeded the entire update is cancelled.

UPDATE cannot be used on temporary tables or ordinary files.

Example:

update people set lastname = "Sherman",
    	firstname = "Bobby", email = "bobby@bibbet.net"
  	where people_id = 245


update bugtracking orinsert set id = 2480, owner = "steve",
    status = "open" where id = 2480 




DELETE

DELETE deletes one or more existing rows.

DELETE FROM table
WHERE
conditional-expression
[MAXROWS
maxrows]

A WHERE clause is always required. It is not considered an error if no rows are found that meet the where clause (the row count may be checked to determine this). MAXROWS is a shsql extension and has similar function as with UPDATE, described above.


Example:

delete from people where people_id = 279



Copyright Steve Grubb  


Markup created by unroff 1.0,    March 18, 2004.