SQLite批处理插入到多个表

时间:2014-10-22 14:17:09

标签: sqlite

这很好用:

insert into Genres (ID, Genre) 
select 1 AS ID, 'Action' AS Genre 
union select 2, 'Adventure' 

......这很好用:

insert into Movies_Genres (ID, MovieID, GenreID) 
select 1 AS ID, 2 AS MovieID, 1 AS GenreID 
union select 2, 3, 1 

...但是当我尝试将两个陈述结合起来时:

insert into Genres (ID, Genre) 
select 1 AS ID, 'Action' AS Genre 
union select 2, 'Adventure' 
insert into Movies_Genres (ID, MovieID, GenreID) 
select 1 AS ID, 2 AS MovieID, 1 AS GenreID 
union select 2, 3, 1 

...它会抛出错误。我也尝试用分号分隔2个表批次,但也出错了。 "解析提供的SQL语句时发生错误。"和#34;语法错误"。我有大量的插件要做,所以我需要最大化性能,我发现这种方法非常强大和快速:

How to insert multiple rows into a SQLite 3 table?

那么,将一堆针对不同表格的插入批处理在一起的正确语法是什么?

1 个答案:

答案 0 :(得分:1)

一个语句无法插入多个表。

只需执行多个语句。 (如果您使用单笔交易,这将很快。)