---
title: "How to Create Update query Without Using Model File in Magento 2"
url: "https://magecomp.com/blog/magento-2-how-to-create-update-query-without-using-model-file/"
date: "2019-09-23T16:47:48+00:00"
modified: "2025-05-28T12:55:23+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 425
reading_time: "3 min read"
summary: "For Any Website, One crucial necessity is the utilization of Database. Especially for any CMS, it is quite essential to interact with MYSQL with fetching and retrieving of data from the database. T..."
description: "Learn How You can execute multiple SQL update operations without creating a model file. Without creating a standard Magento 2 Model file."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to get Module Version Programmatically in Magento 2"
    url: "https://magecomp.com/blog/get-module-version-programmatically-magento-2/"
  - title: "How to Enable/Disable Ship Button Based on Order Status in Magento 2?"
    url: "https://magecomp.com/blog/enable-disable-ship-button-based-on-order-status-magento-2/"
  - title: "How to set Address Limitation for Logged In Customer on Checkout page of Magento 2"
    url: "https://magecomp.com/blog/set-address-limitation-on-the-checkout-page-of-magento-2/"
---

# How to Create Update query Without Using Model File in Magento 2

_Published: September 23, 2019_  
_Author: Dhiren Vasoya_  

![How to create Update query Without Using Model File Magento 2](https://magecomp.com/blog/wp-content/uploads/2019/09/How-to-create-Update-query-Without-Using-Model-File-Magento-2-1024x332.webp)

For Any Website, One crucial necessity is the utilization of Database. Especially for any CMS, it is quite essential to interact with MYSQL with fetching and retrieving of data from the database. Taking about Ecommerce sites Database plays the most important role in managing that store. One of the most used Ecommerce platforms i.e. Magneto 2 is a CMS. In order to store different information like product data, customer data, etc. it utilizes MYSQL.

[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-2-2.webp)](https://magecomp.com/services/magento-upgrade-services/)

There are times when a developer wants to perform database operations like storing some data, modifying data or deleting it during coding. But there are certain coding standards in Magento. And according to those standards, a developer has to create a model file in order to perform any SQL query. It is one hectic dilemma in this near-perfect platform for an Ecommerce store.

But what if it was possible to perform those SQL queries without the use of model files. Believe me, it’s possible. And today’s blog is regarding the same. Here I’ll show you how to perform an update query. In the below code update is shown which shows you how to perform an update for any number of times without the use of a modal file. So, let’s start…??

Initially, in order to perform it, you need to create an “**Index.php**” file inside my extension folder at the path which is defined below.

**app\code\Vendor\Extension\Controller\Updatequery**

[![Magento Malware Removal](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-Malware-Removal-CTA-6.webp)](https://magecomp.com/magento-malware-removal.html)

After creating the folder, you need to apply the below code in order to perform the update operation.

```
<?php
namespace VendorExtensionControllerUpdatequery;

use MagentoFrameworkAppResourceConnection;
use MagentoFrameworkAppActionContext;

class Index extends MagentoFrameworkAppActionAction
{
    const QUOTE_TABLE = '[TABLE_NAME]';
    private $resourceConnection;
    public function __construct( Context $context, ResourceConnection     $resourceConnection){
        $this->resourceConnection = $resourceConnection;
        return parent::__construct($context);
    }

    public function execute()
    {
        $connection = $this->resourceConnection->getConnection();
        $data = ["field1"=> 3, "field2"=>15]; // you can use as per your    requirement
        $id = 1;
        $where = ['entity_id = ?' => (int)$id];
        $tableName = $connection->getTableName(self::QUOTE_TABLE);
        $updatedRows=$connection->update($tableName, $data, $where);
        echo "Updated Rows : ".$updatedRows;
    }
}
```

That’s it. With the help of this code, you can execute multiple SQL update operations without creating a model file. Without creating a standard Magento 2 Model file can be very helpful in your development phase.

[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-2.webp)](https://magecomp.com/magento-performance-optimization.html)

lastly,?If This blog was helpful, then don’t forget to share it with your Magneto friends. Along with that if you are facing any difficulty or error during the implementation of this code, just let us know.

Happy Coding! ?‍??‍?


---

_View the original post at: [https://magecomp.com/blog/magento-2-how-to-create-update-query-without-using-model-file/](https://magecomp.com/blog/magento-2-how-to-create-update-query-without-using-model-file/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-09-09 04:05:54 UTC_  
