4.Summary - 4.데이터베이스 활용

CODEDRAGON Development/Python

반응형



 

 

 

1

데이터 베이스에 UPDATE, DELETE 쿼리문을 수행하고 Commit하는 프로그램입니다. 해당 코드를 완성하시오.

 

 

import pymysql

 

conn = _________________________.connect(host='localhost', user='dsuser', password='mysqlpw',

                       db='dsdb', charset='utf8')

 

curs = conn._________________________()

 

# Region "seoul"인 데이타를 모두 "서울"로 변경

sql = """_________________________ customer

         set region = '서울'

         where region = 'seoul'"""

curs.execute(sql)

 

 

 

# id 6 customer 데이타를 삭제

sql = "delete from customer where id=_________________________"

curs.execute(sql, 7)

 

conn.commit()

 

 

 

 

# 데이터 확인하기

sql = "select * from customer"

curs._________________________(sql)

 

# 데이타 Fetch

rows = curs._________________________()

 

# 전체 rows

# 전체 row들을 Tuple Tuple로서 출력

print(rows)

 

 

_________________________.close()

 

 

 

import pymysql

 

conn = pymysql.connect(host='localhost', user='dsuser', password='mysqlpw',

                       db='dsdb', charset='utf8')

 

curs = conn.cursor()

 

# Region "seoul"인 데이타를 모두 "서울"로 변경

sql = """update customer

         set region = '서울'

         where region = 'seoul'"""

curs.execute(sql)

 

 

 

# id 6 customer 데이타를 삭제

sql = "delete from customer where id=%s"

curs.execute(sql, 7)

 

conn.commit()

 

 

 

 

# 데이터 확인하기

sql = "select * from customer"

curs.execute(sql)

 

# 데이타 Fetch

rows = curs.fetchall()

 

# 전체 rows

# 전체 row들을 Tuple Tuple로서 출력

print(rows)

 

 

conn.close()

 

 


반응형