How can we insert new records in magento2 db using sql queries

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
1
down vote

favorite












Let us know the exact way to import bulk data to DB using queries.










share|improve this question



























    up vote
    1
    down vote

    favorite












    Let us know the exact way to import bulk data to DB using queries.










    share|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      Let us know the exact way to import bulk data to DB using queries.










      share|improve this question













      Let us know the exact way to import bulk data to DB using queries.







      magento2 database data-migration bulk-products-update






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 1 hour ago









      sahana

      1067




      1067




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote













          Write custom MYSQL query without using Model



          Here is example how to write custom mysql query in Magento2.



          Suppose we have table employee with fields emp_id, emp_name, emp_code and emp_salary.



          Now use following code to run custom queries in magento2 without using model.



          $objectManager = MagentoFrameworkAppObjectManager::getInstance(); // Instance of object manager
          $resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
          $connection = $resource->getConnection();
          $tableName = $resource->getTableName('employee'); //gives table name with prefix

          //Select Data from table
          $sql = "Select * FROM " . $tableName;
          $result = $connection->fetchAll($sql); // gives associated array, table fields as key in array.

          //Delete Data from table
          $sql = "Delete FROM " . $tableName." Where emp_id = 10";
          $connection->query($sql);

          //Insert Data into table
          $sql = "Insert Into " . $tableName . " (emp_id, emp_name, emp_code, emp_salary) Values ('','XYZ','ABD20','50000')";
          $connection->query($sql);

          //Update Data into table
          $sql = "Update " . $tableName . "Set emp_salary = 20000 where emp_id = 12";
          $connection->query($sql);


          For more reference Click here






          share|improve this answer




















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "479"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f243783%2fhow-can-we-insert-new-records-in-magento2-db-using-sql-queries%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote













            Write custom MYSQL query without using Model



            Here is example how to write custom mysql query in Magento2.



            Suppose we have table employee with fields emp_id, emp_name, emp_code and emp_salary.



            Now use following code to run custom queries in magento2 without using model.



            $objectManager = MagentoFrameworkAppObjectManager::getInstance(); // Instance of object manager
            $resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
            $connection = $resource->getConnection();
            $tableName = $resource->getTableName('employee'); //gives table name with prefix

            //Select Data from table
            $sql = "Select * FROM " . $tableName;
            $result = $connection->fetchAll($sql); // gives associated array, table fields as key in array.

            //Delete Data from table
            $sql = "Delete FROM " . $tableName." Where emp_id = 10";
            $connection->query($sql);

            //Insert Data into table
            $sql = "Insert Into " . $tableName . " (emp_id, emp_name, emp_code, emp_salary) Values ('','XYZ','ABD20','50000')";
            $connection->query($sql);

            //Update Data into table
            $sql = "Update " . $tableName . "Set emp_salary = 20000 where emp_id = 12";
            $connection->query($sql);


            For more reference Click here






            share|improve this answer
























              up vote
              2
              down vote













              Write custom MYSQL query without using Model



              Here is example how to write custom mysql query in Magento2.



              Suppose we have table employee with fields emp_id, emp_name, emp_code and emp_salary.



              Now use following code to run custom queries in magento2 without using model.



              $objectManager = MagentoFrameworkAppObjectManager::getInstance(); // Instance of object manager
              $resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
              $connection = $resource->getConnection();
              $tableName = $resource->getTableName('employee'); //gives table name with prefix

              //Select Data from table
              $sql = "Select * FROM " . $tableName;
              $result = $connection->fetchAll($sql); // gives associated array, table fields as key in array.

              //Delete Data from table
              $sql = "Delete FROM " . $tableName." Where emp_id = 10";
              $connection->query($sql);

              //Insert Data into table
              $sql = "Insert Into " . $tableName . " (emp_id, emp_name, emp_code, emp_salary) Values ('','XYZ','ABD20','50000')";
              $connection->query($sql);

              //Update Data into table
              $sql = "Update " . $tableName . "Set emp_salary = 20000 where emp_id = 12";
              $connection->query($sql);


              For more reference Click here






              share|improve this answer






















                up vote
                2
                down vote










                up vote
                2
                down vote









                Write custom MYSQL query without using Model



                Here is example how to write custom mysql query in Magento2.



                Suppose we have table employee with fields emp_id, emp_name, emp_code and emp_salary.



                Now use following code to run custom queries in magento2 without using model.



                $objectManager = MagentoFrameworkAppObjectManager::getInstance(); // Instance of object manager
                $resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
                $connection = $resource->getConnection();
                $tableName = $resource->getTableName('employee'); //gives table name with prefix

                //Select Data from table
                $sql = "Select * FROM " . $tableName;
                $result = $connection->fetchAll($sql); // gives associated array, table fields as key in array.

                //Delete Data from table
                $sql = "Delete FROM " . $tableName." Where emp_id = 10";
                $connection->query($sql);

                //Insert Data into table
                $sql = "Insert Into " . $tableName . " (emp_id, emp_name, emp_code, emp_salary) Values ('','XYZ','ABD20','50000')";
                $connection->query($sql);

                //Update Data into table
                $sql = "Update " . $tableName . "Set emp_salary = 20000 where emp_id = 12";
                $connection->query($sql);


                For more reference Click here






                share|improve this answer












                Write custom MYSQL query without using Model



                Here is example how to write custom mysql query in Magento2.



                Suppose we have table employee with fields emp_id, emp_name, emp_code and emp_salary.



                Now use following code to run custom queries in magento2 without using model.



                $objectManager = MagentoFrameworkAppObjectManager::getInstance(); // Instance of object manager
                $resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
                $connection = $resource->getConnection();
                $tableName = $resource->getTableName('employee'); //gives table name with prefix

                //Select Data from table
                $sql = "Select * FROM " . $tableName;
                $result = $connection->fetchAll($sql); // gives associated array, table fields as key in array.

                //Delete Data from table
                $sql = "Delete FROM " . $tableName." Where emp_id = 10";
                $connection->query($sql);

                //Insert Data into table
                $sql = "Insert Into " . $tableName . " (emp_id, emp_name, emp_code, emp_salary) Values ('','XYZ','ABD20','50000')";
                $connection->query($sql);

                //Update Data into table
                $sql = "Update " . $tableName . "Set emp_salary = 20000 where emp_id = 12";
                $connection->query($sql);


                For more reference Click here







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 59 mins ago









                Chirag Patel

                1,279118




                1,279118



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f243783%2fhow-can-we-insert-new-records-in-magento2-db-using-sql-queries%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    Long meetings (6-7 hours a day): Being “babysat” by supervisor

                    Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                    Confectionery