> For the complete documentation index, see [llms.txt](https://docs.objectiphy.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.objectiphy.net/query-builder/insert-queries.md).

# Insert Queries

Perform single or bulk inserts without creating any entities

If you create a new entity, you can save it by calling `saveEntity` as described on the [Basic Saving](/basic-saving.md) page. There might be times however, when you want to quickly save one or more new records without necessarily creating new entities for each record. You can achieve this using insert queries.

```php
$query = QB::create()
    ->insert(Contact::class)
    ->set([
        'firstName' => 'Anna', 
        'lastName' => 'Skywalker'
    ])
    ->buildInsertQuery();
$repository->executeQuery($query);
$lastInsertId = $this->objectRepository->getLastInsertId();
```

You can also insert multiple records in a single query, which will send a single SQL statement to the database (unlike the `saveEntities` method, which has to loop through the entities and send a query to the database for each one):

```php
$query = QB::create()
    ->insert(TestContact::class)
    ->set(['firstName' => 'Englebert', 'lastName' => 'Skywalker'])
    ->set(['firstName' => 'Jemima', 'lastName' => 'Skywalker'])
    ->set(['firstName' => 'Jedediah', 'lastName' => 'Skywalker'])
    ->set(['firstName' => 'Trixie', 'lastName' => 'Skywalker'])
    ->buildInsertQuery();
$insertCount = $repository->executeQuery($query);
```
