importsqlite3# Connect to the databaseconn=sqlite3.connect('customer.db')# Create a Cursorc=conn.cursor# These correspond to the fields we added to our table, first_name,# last_name, emailc.execute("INSERT INTO customers VALUES ('John', 'Elder', 'john@codemy.com')")c.execute("INSERT INTO customers VALUES ('Tim', 'Smith', 'tim@codemy.com')")c.execute("INSERT INTO customers VALUES ('Mary', 'Brown', 'mary@codemy.com')")# Commit our commandconn.commit()# Close our connectionconn.close()
Insert many records into the database - Video 7
importsqlite3# Connect to the databaseconn=sqlite3.connect('customer.db')# Create a Cursorc=conn.cursor# These correspond to the fields we added to our table, first_name,# last_name, emailmany_customers=[('Wes','Brown','wes@brown.com'),('Steph','Kuewa','steph@kuewa.com'),('Dan','Pas','dan@pas.com'),]c.executemany("INSERT INTO customers VALUES (?,?,?)",many_customers)# Commit our commandconn.commit()# Close our connectionconn.close()