As with record retrieval in the previous chapter, inserting data into MySQL through Python relies on understanding data insertion in MySQL itself. You will recall that the requirements of a computing language necessitate the use of as few words as possible to do anything. Ideally, there should be only one word as the Zen of Python reads:
There should be one—and preferably only one—obvious way to do it.
For retrieval, we used the SELECT
command. For putting data into the database, we use INSERT
. So instead of saying "Put everything on the far table!" or "Stick everything over there!", MySQL needs specification such as:
INSERT INTO far VALUES("everything");
This is perhaps the most basic insertion statement that one can make for MySQL. You can tell from it that the basic syntax of MySQL's INSERT
statement is as follows:
INSERT INTO <some table> (<some column names>) VALUES("<some values>");
Now let's take this skeleton of a statement apart and...