开始使用免费开始使用

更新单条记录

update 语句与 insert 语句非常相似。例如,您可以如下更新 employees 表中的所有工资:

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

update 语句通常也会使用 where 子句来确定要更新哪些数据。比如,只更新 ID 为 15 的员工记录时,您可以在前一个语句后追加:

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

这里您将使用 FIPS 州代码。它由美国政府用于标识美国各州及某些相关区域。

为方便起见,本练习涉及的表和列名称如下:state_fact(表)、name(列)和 fips_state(列)。

本练习是课程的一部分

Python 中的数据库入门

查看课程

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Build a select statement: select_stmt
select_stmt = select([____]).where(____ == ____)

# Execute select_stmt and fetch the results
results = connection.____(____).____()

# Print the results of executing the select_stmt
print(____)

# Print the FIPS code for the first row of the result
print(results[0]['___'])
编辑并运行代码