0

I want to insert thousand of Record in table, right now i am using

INSERT INTO myTable ("id", "values") VALUES ("1", "test")
INSERT INTO myTable ("id", "values") VALUES ("2", "test")
INSERT INTO myTable ("id", "values") VALUES ("3", "test")

Query for insert record one by one, but its take long time for execution,

Now i want to insert all record from one query...

INSERT INTO myTable ("id", "values") VALUES
 ("1", "test"),
 ("2", "test"),
 ("3", "test"),
 .....
 .....
 ("n", "test")

But this query not working with Sqllite, Can you please give me some guidance for solve this problem

Thanks,

Raj
  • 1,213
  • 2
  • 16
  • 34

4 Answers4

3

Please refer my answer here.

There is no query in sqlite that can support your structure, this is what I use to insert 1000s of records in db. Performance is good. You can give a try. :)

Community
  • 1
  • 1
DivineDesert
  • 6,924
  • 1
  • 29
  • 61
2

Insert into table_name (col1,col2) SELECT 'R1.value1', 'R1.value2' UNION SELECT 'R2.value1', 'R2.value2' UNION SELECT 'R3.value1', 'R3.value2' UNION SELECT 'R4.value1', 'R4.value2'

itechnician
  • 1,645
  • 1
  • 14
  • 24
1

You can follow this link on SO for more information. But be careful of the number of insertion you want make, cause there is a limitation for this kind of usage (see here)

Community
  • 1
  • 1
0
INSERT INTO 'tablename'
  SELECT 'data1' AS 'column1', 'data2' AS 'column2'
  UNION SELECT 'data3', 'data4'
  UNION SELECT 'data5', 'data6'
  UNION SELECT 'data7', 'data8'

As a further note, sqlite only seems to support upto 500 such union selects per query so if you are trying to throw in more data than that you will need to break it up into 500 element blocks
iKushal
  • 2,689
  • 24
  • 20