MySQL常见的用法
插入单条记录
INSERT INTO table_name ( field1, field2,...fieldN ) VALUES ( value1, value2,...valueN );
插入多条记录
INSERT INTO tbl_name (a,b,c) VALUES (1,2,3), (4,5,6), (7,8,9);
从一个或多个表中进行选择插入到表中INSERT ... SELECT
INSERT INTO tbl_temp2 (fld_id)
SELECT tbl_temp1.fld_order_id
FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100;
从MySQL 8.0.19开始,您可以使用 TABLE
语句代替 SELECT
,如下所示:
INSERT INTO ta TABLE tb;
TABLE tb
等同于SELECT * FROM tb
MySQL的value和values的区别
网上看了各种版本,乱七八糟的。mysql8.0官网INSERT语句解释如下:
VALUE
is a synonym for VALUES
in this context. Neither implies anything about the number of values lists, nor about the number of values per list. Either may be used whether there is a single values list or multiple lists, and regardless of the number of values per list.
我翻译如下:
在文中,VALUE是VALUES的同义词。既不表示值列表的数量,也不表示每个列表的值的数量。无论是单个值列表还是多个列表,也无论每个列表的值数如何,都可以使用这两种方法。