개별 레코드 업데이트하기
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]['___'])