Multiple INSERT queries turned into one single query

This question already has an answer here:

  • Inserting multiple rows in a single SQL query? [duplicate] 4 answers

  • 如果您使用的是Sql Server,请尝试以下操作

    Insert into table (columns..)
    Values(values1,value2,...), 
        (values1,value2,...),
        (values1,value2,...),
        (values1,value2,...)
    

    最接近的是仅需要一次字段列表的简写版本:

      INSERT INTO `creature` ( <field list> ) VALUES
        ( <value list> ),
        ( <value list> ),
        ( <value list> )
    

    In Mysql, do this (most popular databases have a similar syntax):

    INSERT INTO mytable (col1, col2, col3, ...) VALUES
    (1, 2843, 0, ...),
    (2, 7853, 0, ...);
    

    In most databases, you can do this:

    INSERT INTO mytable (col1, col2, col3, ...)
    SELECT 1, 2843, 0, ...
    UNION ALL
    SELECT 2, 7853, 0, ...;
    

    In backward, behind-the-times databases, like Oracle, you must code this second option using the artificial single-rowed table DUAL:

    INSERT INTO mytable (col1, col2, col3, ...)
    SELECT 1, 2843, 0, ...
    FRIM DUAL
    UNION ALL
    SELECT 2, 7853, 0, ...
    FROM DUAL;
    
    链接地址: http://www.djcxy.com/p/94492.html

    上一篇: 是否可以一次插入相同的值(Mysql)?

    下一篇: 多个INSERT查询转换为一个查询