5

It's possible to run more than one command in the direct SQL execution in SQlite Manager? (useful if you insert a lot of data)

e.g.

insert into TestTable (Name, Age) values("Thomas", 25)
insert into TestTable (Name, Age) values("Peter", 29)
...

Thx

1
  • Did you try it? What was the result? Commented Oct 5, 2012 at 7:53

4 Answers 4

16

Solution is very simple ;-)

-> use a semicolon to separate the commands

insert into TestTable (Name, Age) values("Thomas", 25);
insert into TestTable (Name, Age) values("Peter", 29);
...
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very very much.. ;) it totally solve the problem.
5

Alternatively, you could write the statement as:

insert into TestTable (Name, Age) 
values
("Thomas", 25),
("Peter", 29)
;

Edit: Please note, as per @DominiqueJacquel's comment, that this will only work in SQLite version 3.7.11+

2 Comments

That syntax will not work with all versions of SQLite, it was only added around 3.7.11 I think.
@DominiqueJacquel you are absolutely correct. This will only work in SQLite in version 3.7.11+
2

Perhaps you may work executemany() method instead of execute()

Something like:

values = [
    ("Thomas", 25),
    ("Peter", 29)
]
conn.executemany("insert into TestTable (Name, Age) values (?, ?)", values)

Will work fine.

Comments

1

Create a file like:

$ cat query-list.sql
insert into TestTable (Name, Age) values("Thomas", 25)
insert into TestTable (Name, Age) values("Peter", 29)
...

Now run the command:

$ sqlite3 my-database.db < query-list.sql

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.