Updating multiple records
As Jason discussed in the video, by using a where clause that selects more records, you can update multiple
records at once. Unlike inserting, updating multiple records works exactly the same way as updating a single record (as long as you are updating them with the same value). It's time now to practice this!
For your convenience, the names of the tables and columns of interest in this exercise are: state_fact (Table), notes (Column), and census_region_name (Column).
Este ejercicio forma parte del curso
Introduction to Databases in Python
Instrucciones del ejercicio
- Build an
updatestatement to update thenotescolumn in thestate_facttable to'The Wild West'. Save it asstmt. - Use a
whereclause to filter for records that have'West'in thecensus_region_namecolumn of thestate_facttable. - Execute
stmt_westvia theconnectionand save the output asresults. - Run the solution to print
rowcountof theresults.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Build a statement to update the notes to 'The Wild West': stmt
stmt = update(____).values(____=____)
# Append a where clause to match the West census region records: stmt_west
stmt_west = stmt.____(____ == ____)
# Execute the statement: results
results = connection.execute(____)
# Print rowcount
print(results.rowcount)