การเพิ่มข้อมูลลงในฐานข้อมูล

Python เบื้องต้นสำหรับฐานข้อมูล

Jason Myers

Co-Author of Essential SQLAlchemy and Software Engineer

ส่วนที่ 2: การเพิ่มข้อมูลลงในฐานข้อมูล

  • โหลดไฟล์ CSV ลงใน values list
values_list = []
for row in csv_reader:
    data = {'state': row[0], 'sex': row[1], 'age': row[2],
            'pop2000': row[3], 'pop2008': row[4]}
    values_list.append(data)
Python เบื้องต้นสำหรับฐานข้อมูล

ส่วนที่ 2: การเพิ่มข้อมูลลงในฐานข้อมูล

  • แทรก values list ลงในตาราง census
from sqlalchemy import insert

stmt = insert(employees)
result_proxy = connection.execute(stmt, values_list) print(result_proxy.rowcount)
2
Python เบื้องต้นสำหรับฐานข้อมูล

มาฝึกกันเถอะ!

Python เบื้องต้นสำหรับฐานข้อมูล

Preparing Video For Download...