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 am trying
INSERT INTO Data ( Col1 ) VALUES ('Hello', 'World')
That code was taken from this question, but it, like many other examples I have found on the web uses 2 columns, I just want to use 1. What am I doing wrong?
Thanks
Tip: To insert more than one row (or column) at the same time, select as many rows or columns as you want to add before you click the insert control. For example, to insert two rows above a row, first select two rows in your table and then click Insert Above.
INSERT INTO Syntax It is possible to write the INSERT INTO statement in two ways: 1. Specify both the column names and the values to be inserted: INSERT INTO table_name (column1, column2, column3, ...)
You can concatenate rows into single string using COALESCE method. This COALESCE method can be used in SQL Server version 2008 and higher. All you have to do is, declare a varchar variable and inside the coalesce, concat the variable with comma and the column, then assign the COALESCE to the variable.
to insert values for a particular column with other columns remain same:-
INSERT INTO `table_name`(col1,col2,col3) VALUES (1,'val1',0),(1,'val2',0),(1,'val3',0)
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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With