Whats the difference between execute() and executemany()

Home Forums Python Course Forum Python DB (MySQL) Whats the difference between execute() and executemany()

Viewing 0 reply threads
  • Author
    Posts
    • training@h2kinfosys.com
      Keymaster
      (124.123.164.108)

        “You write the INSERT INTO query in a string and pass it to cursor.execute(). You can use this method to insert data into the any table.
        cursor.execute() approach is more suitable when the number of records is fairly small and you can write these records directly into the code.
        You’ll often have this data stored in some other file, or the data will be generated by a different script and will need to be added to the MySQL database.

        This is where .executemany() comes in handy. It accepts two parameters:

        A query that contains placeholders for the records that need to be inserted
        A list that contains all records that you wish to insert”

        #18502

    Viewing 0 reply threads
    • You must be logged in to reply to this topic.