如果我必须在一个表中插入几百行,但是我插入的数据只在单个列中变化,那么在不进行几百次单独插入的情况下,最好的方法是什么呢?
。
name, lastname, lastlogin
bill smith 2015-08-01
bill smith 2015-08-02
bill smith 2015-08-03
bill smith 2015-08-04
几百行?这是什么。只需展开它并创建一个具有多个值的INSERT
语句:
INSERT INTO the_table (name, lastname, lastlogin)
VALUES ('bill','smith', '2015-08-01'),
('bill','smith', '2015-08-02'),
...
您可以使用变量和函数来编写大约100倍的查询:
<>之前现在设置@variable_field = ();INSERT INTO login VALUES("bill", "smith", @variable_field);