Insert multiple rows into single column

前端 未结 9 1649
抹茶落季
抹茶落季 2020-12-24 07:29

I\'m new to SQL, (using SQL 2008 R2) and I am having trouble inserting multiple rows into a single column.

I have a table named Data and this is what I

相关标签:
9条回答
  • 2020-12-24 07:46
      INSERT INTO Data ( Col1 ) VALUES ('Hello'), ('World')
    
    0 讨论(0)
  • 2020-12-24 07:54

    Another way to do this is with union:

    INSERT INTO Data ( Col1 ) 
    select 'hello'
    union 
    select 'world'
    
    0 讨论(0)
  • 2020-12-24 07:55

    To insert into only one column, use only one piece of data:

    INSERT INTO Data ( Col1 ) VALUES
    ('Hello World');
    

    Alternatively, to insert multiple records, separate the inserts:

    INSERT INTO Data ( Col1 ) VALUES
    ('Hello'),
    ('World');
    
    0 讨论(0)
  • 2020-12-24 07:56

    If your DBMS supports the notation, you need a separate set of parentheses for each row:

    INSERT INTO Data(Col1) VALUES ('Hello'), ('World');
    

    The cross-referenced question shows examples for inserting into two columns.

    Alternatively, every SQL DBMS supports the notation using separate statements, one for each row to be inserted:

    INSERT INTO Data (Col1) VALUES ('Hello');
    INSERT INTO Data (Col1) VALUES ('World');
    
    0 讨论(0)
  • 2020-12-24 07:56
    INSERT INTO hr.employees (location_id) VALUE (1000) WHERE first_name LIKE '%D%';
    

    let me know if there is any problem in this statement.

    0 讨论(0)
  • 2020-12-24 08:02

    In that code you are inserting two column value. You can try this

       INSERT INTO Data ( Col1 ) VALUES ('Hello'),
       INSERT INTO Data ( Col1 ) VALUES ('World')
    
    0 讨论(0)
提交回复
热议问题