-1

How would I make a query to INSERT repeating data into several rows in a database? I have an auto incremented field id so I feel a simple

INSERT INTO table_name (column, column) 
VALUES ('data', 'data') 

should be fine but not sure how to make it do it multiple times.

ragerory
  • 1,360
  • 1
  • 8
  • 27
Casey Stack
  • 103
  • 7
  • I am using MySql. I've been using exactly the above query and, yes, expecting the addition of a rows with that information and the rest becomes NULL..which is what I want, but I want it to do that but more maybe the next 20 rows..I have looked at using INSERT ALL beforehand, but that gave me an syntax error. – Casey Stack Jun 15 '15 at 19:07

2 Answers2

0

Notice how MYSQLDUMP does it. The VALUES clause allows a list of one-or-more value sets to be provided. A new row will be inserted for each.

Mike Robinson
  • 8,490
  • 5
  • 28
  • 41
0

This is a fairly common question, so I imagine more searching would've been beneficial. That said, a common syntax would be like the below, depending on which RDBMS you are using.

INSERT INTO table_name (column1, column2) 
VALUES ('data', 'data'), ('data', 'data'), ('data', 'data')

See other examples here:

Inserting multiple records

3 methods to insert multiple records

There is also the notion of bulk inserting, but again, not much information about your environment.

Community
  • 1
  • 1
ragerory
  • 1,360
  • 1
  • 8
  • 27