Agregar un registro

Ahora estamos listos para agregar el primer registro o fila con datos a la tabla:


# first we setup the query and the dataset
query = ("INSERT INTO customers (firstName, lastName) "
         "VALUES (%s, %s)")
val = [
  ('Richard', 'Williams'),
  ('Anne', 'Robinson'),
  ('Christine', 'Frederic')
]

# then execute with the row in the dataset
cursor.executemany(query, val)
cnxn.commit()  # and commit changes


El uso de executemany() método (en lugar de execute()) nos permite insertar varias filas en la tabla.

Agregar registros (filas) aumenta el recuento total de registros en la tabla.