Createtableemployee_data(IDINTAUTO_INCREMENTPRIMARYKEY, First_nameVARCHAR(50)NOTNULL,Last_nameVARCHAR(50)NOTNULL,"/> Createtableemployee_data(IDINTAUTO_INCREMENTPRIMARYKEY, First_nameVARCHAR(50)NOTNULL,Last_nameVARCHAR(50)NOTNULL,">
Rumah > Artikel > pangkalan data > Bagaimanakah lajur terhasil maya MySQL berfungsi dengan fungsi terbina dalam?
boleh dijelaskan dengan contoh di mana kita mencipta lajur yang dijana dummy dalam jadual yang dipanggil "data_pekerja". Kami tahu bahawa lajur terjana maya boleh dijana dengan atau tanpa kata kunci "maya".
mysql> Create table employee_data(ID INT AUTO_INCREMENT PRIMARY KEY, First_name VARCHAR(50) NOT NULL, Last_name VARCHAR(50) NOT NULL, FULL_NAME VARCHAR(90) GENERATED ALWAYS AS(CONCAT(First_name,'',Last_name))); Query OK, 0 rows affected (0.55 sec) mysql> DESCRIBE employee_data; +------------+-------------+------+-----+---------+-------------------+ | Field | Type | Null | Key | Default | Extra | +------------+-------------+------+-----+---------+-------------------+ | ID | int(11) | NO | PRI | NULL | auto_increment | | First_name | varchar(50) | NO | | NULL | | | Last_name | varchar(50) | NO | | NULL | | | FULL_NAME | varchar(90) | YES | | NULL | VIRTUAL GENERATED | +------------+-------------+------+-----+---------+-------------------+ 4 rows in set (0.00 sec) mysql> INSERT INTO employee_data(first_name, Last_name) values('Yashpal','Sharma'); Query OK, 1 row affected (0.09 sec) mysql> INSERT INTO employee_data(first_name, Last_name) values('Krishan','Kumar'); Query OK, 1 row affected (0.09 sec) mysql> INSERT INTO employee_data(first_name, Last_name) values('Rakesh','Arora'); Query OK, 1 row affected (0.08 sec) mysql> Select * from employee_data; +----+------------+-----------+----------------+ | ID | First_name | Last_name | FULL_NAME | +----+------------+-----------+----------------+ | 1 | Yashpal | Sharma | Yashpal Sharma | | 2 | Krishan | Kumar | Krishan Kumar | | 3 | Rakesh | Arora | Rakesh Arora | +----+------------+-----------+----------------+ 3 rows in set (0.00 sec)
Atas ialah kandungan terperinci Bagaimanakah lajur terhasil maya MySQL berfungsi dengan fungsi terbina dalam?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!