Main Content

INSERT, DELETE, REPLACE and UPDATE - changing the content of SQL tables

Archive - Originally posted on "The Horse's Mouth" - 2010-11-19 09:07:28 - Graham Ellis

Most enquires of an SQL database are SELECTs - most database are "Read Mostly" and writes are limited to a small proportion of accesses (though there are exceptions). And SELECTs are much more complex that things that insert or change data too.

However, I found myself writing en example on yesterday's MySQL course that shows most of the commands for amending data ...

INSERT to add new rows to a table

DELETE to remove rows from a table

REPLACE to replace complete rows, based on the primary key

UPDATE to alter data within existing rows

See examples of each of them [here].

also:

LOAD to insert a whole series of rows from data in a file

The commands above handle the data itself. If you want to handle the metadata (i.e. the information about the tables, such as their structure), you'll use CREATE TABLE to set up new tables and ALTER to amend the table structre.