September 2013
Intermediate to advanced
350 pages
9h 38m
English
Data often changes over time, so we need to be able to change the information stored in databases. To do that, we can use the UPDATE command, as shown in the following code:
| | >>> cur.execute('SELECT * FROM PopByRegion WHERE Region = "Japan"') |
| | <sqlite3.Cursor object at 0x102e3e490> |
| | >>> cur.fetchone() |
| | ('Japan', 100562) |
| | >>> cur.execute('''UPDATE PopByRegion SET Population = 100600 |
| | WHERE Region = "Japan"''') |
| | <sqlite3.Cursor object at 0x102e3e490> |
| | >>> cur.execute('SELECT * FROM PopByRegion WHERE Region = "Japan"') |
| | <sqlite3.Cursor object at 0x102e3e490> |
| | >>> cur.fetchone() |
| | ('Japan', 100600) |
We can also delete records from the database:
| | >>> cur.execute( ... |
Read now
Unlock full access