Use of insertMultiple mysql query in Magento 2.

Write a Mysql insertMultiple() query using Magento standard way to insert a multiple row/records at a single time.

You can write direct SQL query insertMultiple() without worrying about the Model operation for insert multiple records in a specific table using below code snippet.

Return Type: insertMultiple() always return an integer number for affected rows in a table.

Base Definition of function:

 * Inserts a table multiply rows with specified data.
 * @param mixed $table The table to insert data into.
 * @param array $data Column-value pairs or array of Column-value pairs.
 * @return int The number of affected rows.
public function insertMultiple($table, array $data);

Let’s we are writing a query from sales_order_status table to accomplish insertMultiple() query operation.

sales_order_status contains two fields only, status and label.

namespace Path\To\Class;

use Magento\Framework\App\ResourceConnection;

class insertMultiple {

    const ORDER_TABLE = 'sales_order_status';

     * @var ResourceConnection
    private $resourceConnection;

    public function __construct(
       ResourceConnection $resourceConnection
    ) {
       $this->resourceConnection = $resourceConnection;

    * insert multiple records Sql Query
    * @return int
    public function insertMultipleQuery()
      $connection  = $this->resourceConnection->getConnection();
      $tableName = $connection->getTableName(self::ORDER_TABLE);

      $data = [

      $countData = $connection->insertMultiple($tableName, $data);

      return $countData;


You can see new records are added to the sales_order_status table.

Check for Other Direct SQL Query in Magento 2