title: Remove quantity from old and add to new
body: <h2>The goal</h2>
  
  <p>When change the category of a product, I want to decrease the quantity of the products in the old category of this product and increase quantity into the new category.</p>
  
  <h2>The problem</h2>
  
  <p>I know I will do it with a trigger, but I do not know the syntax.</p>
  
  <h2>What I already have tried</h2>
  
  <p>I made a sketch, hehe:</p>
  
  <p><img src="https://i.stack.imgur.com/HN48K.jpg" alt="Sketch"></p>
  
  <h2>Details</h2>
  
  <p>I'm using <strong>MySQL</strong>.</p>
  
  <p><strong><em>Categories table structure</em></strong>:</p>
  
  <p><img src="https://i.stack.imgur.com/4yID8.jpg" alt="Category table"></p>
  
  <p><strong><em>Categories and Products relationship table structure</em></strong>:</p>
  
  <p><img src="https://i.stack.imgur.com/l08vD.jpg" alt="Relationship"></p>
  
  <h2>What I already have thought:</h2>
  
  <p>I know, it is not right, but just to illustrate my philosophy:</p>
  
  <pre><code>CREATE DEFINER=`root`@`localhost` TRIGGER `updateQuantitiesOfProductsInCategories` AFTER UPDATE ON `products_category_relationship` FOR EACH ROW BEGIN
      UPDATE categories
      SET categories.ProductsQuantity = OLD.categories.ProductsQuantity -1
      AND NEW.categories.ProductsQuantity +1
      WHERE bm_categories.Id = OLD.ProductId;
  END
  </code></pre>