Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
Tags
- 주피터노트북
- 주피터노트북판다스
- 파이썬크롤링
- sql연습하기
- 데이터분석시각화
- python알고리즘
- 맷플롯립
- 주피터노트북맷플롯립
- sql연습
- Python
- 파이썬차트
- 팀플기록
- 파이썬데이터분석
- matplotlib
- 파이썬
- sql따라하기
- python수업
- SQL
- 판다스그래프
- 수업기록
- 파이썬시각화
- 파이썬알고리즘
- python데이터분석
- SQLSCOTT
- 판다스데이터분석
- SQL수업
- 주피터노트북그래프
- 파이썬수업
- 주피터노트북데이터분석
- 파이썬데이터분석주피터노트북
Archives
- Today
- Total
IT_developers
Python 개념 및 실습 - 데이터베이스(2) 본문
import sqlite3
conn = sqlite3.connect("data/database.db")
cursor = conn.cursor()
# 수정
# id가 2번인 user 이름을 cho로 변경
sql = """ update users
set username = ? where id = ?
"""
cursor.execute(sql, ("cho", 2))
conn.commit()
# id가 2번인 user 이름을 cho에서 hong로 변경
# 딕셔너리 구조
sql = """ update users
set username = :username where id = :id
"""
cursor.execute(sql, {"username": "hong", "id": 2})
conn.commit()
![](https://blog.kakaocdn.net/dn/DssVn/btrDJw00YpT/Zj63MGJKg2UKf3Vmx5PcCK/img.png)
![](https://blog.kakaocdn.net/dn/bNkFfi/btrDLVzcqtK/XIlvYe61GM7iYPSErAZs60/img.png)
# id가 2번인 user 이름을 cho로 변경
# 포맷
set username = %s where id = %s ==> OperationalError: no such column: cho
# 홑 따옴표 사용
sql = """ update users
set username = '%s' where id = '%s'
"""
cursor.execute(sql % ("cho", 2))
conn.commit()
![](https://blog.kakaocdn.net/dn/uDauB/btrDLVMKF6l/3IducPKN8euSoVVhs0XjiK/img.png)
![](https://blog.kakaocdn.net/dn/vqzpZ/btrDHezMv7m/qUJDlsZucpfoOphVgCi7ik/img.png)
#삭제
# 튜플
cursor.execute("delete from users where id=?", (2,))
#딕셔너리
cursor.execute("delete from users where id=:id", {"id": 3})
# 포맷
cursor.execute("delete from users where id= %d" % 4)
conn.commit()
'Python' 카테고리의 다른 글
Python algorithm 개념 및 실습 - 절댓값 구하기 (0) | 2022.09.15 |
---|---|
Python 개념 및 실습 - 게임 (0) | 2022.09.14 |
Python 개념 및 실습 - 데이터베이스(1) (0) | 2022.09.13 |
Python 개념 및 실습 - 예외 (0) | 2022.09.13 |
Python 개념 및 실습 - 모듈(2) (0) | 2022.09.12 |
Comments