December 2017
Beginner
412 pages
10h 8m
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 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