

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How MySQL virtual GENERATED COLUMNS can work with mathematical expressions?
It can be illustrated with the help of an example in which we are creating a virtual generated column in the table named ‘triangle’. As we know that virtual generated column can be generated with or without using the keyword ‘virtual’.
Example
mysql> Create table triangle(SideA DOUBLE, SideB DOUBLE, SideC DOUBLE AS (SQRT(SideA * SideB + SideB * SideB))); Query OK, 0 rows affected (0.44 sec) mysql> Describe Triangle; +-------+--------+------+-----+---------+-------------------+ | Field | Type | Null | Key | Default | Extra | +-------+--------+------+-----+---------+-------------------+ | SideA | double | YES | | NULL | | | SideB | double | YES | | NULL | | | SideC | double | YES | | NULL | VIRTUAL GENERATED | +-------+--------+------+-----+---------+-------------------+ 3 rows in set (0.00 sec)
The above description shows that the column SideC is a virtually generated column.
mysql> INSERT INTO triangle(SideA, SideB) Values(1,1),(3,4),(6,8); Query OK, 3 rows affected (0.15 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> Select * from triangle; +-------+-------+--------------------+ | SideA | SideB | SideC | +-------+-------+--------------------+ | 1 | 1 | 1.4142135623730951 | | 3 | 4 | 5.291502622129181 | | 6 | 8 | 10.583005244258363 | +-------+-------+--------------------+ 3 rows in set (0.03 sec)
- Related Questions & Answers
- How MySQL stored GENERATED COLUMNS can work with mathematical expressions?
- How Can MySQL virtual GENERATED COLUMNS work with built-in functions?
- How MySQL stored GENERATED COLUMNS are different from MySQL virtual GENERATED COLUMNS?
- How MySQL stored GENERATED COLUMNS can work with built-in functions?
- How can we alter table to add MySQL virtual GENERATED COLUMNS?
- How can we alter table to add MySQL stored GENERATED COLUMNS?
- How can we have multiple virtuals GENERATED COLUMNS in MySQL table with CREATE TABLE statement?
- Can we order a MySQL result with mathematical operations?
- How can MySQL work with PHP programming language?
- How we have multiple stored GENERATED COLUMNS in MySQL table with CREATE TABLE statement?
- Removing parentheses from mathematical expressions in JavaScript
- What are the different types of MySQL GENERATED COLUMNS?
- Java Program to evaluate mathematical expressions in String
- How can we use two columns with MySQL WHERE clause?
- How can we emulate CHECK CONSTRAINT by using MySQL GENERATED COLUMN?
Advertisements