First page Back Continue Last page Overview Graphics

Create Table / Insert (III)

staff_data = [ ("William", "Shakespeare", "m", "1961-10-25"),

("Frank", "Schiller", "m", "1955-08-17"),

("Jane", "Wall", "f", "1989-03-14"),

]

for staff, p in enumerate(staff_data):

format_str = """INSERT INTO employee (staff_number, fname, lname, gender, birth_date) VALUES ({staff_no}, '{first}', '{last}', '{gender}', '{birthdate}');"""

sql_command = format_str.format(staff_no=staff, first=p[0], last=p[1], gender=p[2], birthdate = p[3])

print(sql_command)

cursor.execute(sql_command)

connection.commit()

cursor.close()

connection.close()