Search code examples
sqlheidisql

Multiplying 2 value in database


I have a database. I created it with HeidiSQL. Its look like this.

I enter the value-1 and value-2.

Is there a way to enter a formula to Result column like " =Value-1 * Value-2 " ? I want my database to calculate the Result when I enter my values to other cells.


Solution

  • A trigger is one way to achieve automated column content.

    A second one is a view, which you can create additionally to the table. That view could contain SQL which generates the result:

    SELECT value1, value2, value1*value2 AS result
    

    A third (more modern) alternative is adding a virtual column in your existing table. You can do that with HeidiSQL's table editor, like shown in the screenshot. Just add a new column with INT data type, and set its Virtuality to "VIRTUAL", and Expression to "value-1 * value-2". That's it.

    creating a virtual column in HeidiSQL