1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Databases in Python

Exercise

Updating individual records

The update statement is very similar to an insert statement. For example, you can update all wages in the employees table as follows:

stmt = update(employees).values(wage=100.00)

The update statement also typically uses a where clause to help us determine what data to update. For example, to only update the record for the employee with ID 15, you would append the previous statement as follows:

stmt = stmt.where(employees.id == 15)

You'll be using the FIPS state code here, which is appropriated by the U.S. government to identify U.S. states and certain other associated areas.

For your convenience, the names of the tables and columns of interest in this exercise are: state_fact (Table), name (Column), and fips_state (Column).

Instructions 1/3

undefined XP
    1
    2
    3
  • Build a statement to select all columns from the state_fact table where the value in the name column is 'New York'. Call it select_stmt.
  • Fetch all the results and assign them to results.
  • Print the results and the fips_state column of the first row of the results.