Glaucon
Glaucon

Reputation: 935

SQlite: select into?

I'm not sure if I can use select into to import data from another table like this:

select * into
  bookmark1 
from bookmark;    

Is it true that SQlite doesn't support this syntax? are there any other alternatives?

Upvotes: 82

Views: 41201

Answers (5)

JeeyCi
JeeyCi

Reputation: 589

BUT be careful: "create table" from the other in such a way is not saving Data Types of new table's fields as so as they were in the source table, therefore I would prefer to "create table" with a separate statement & "insert into" statement also to do separately - as was mentioned above:

insert into bookmark_backup select * from bookmark;"

Upvotes: 1

neo
neo

Reputation: 6281

I assume that bookmark1 is a new table that you have created which is same as the bookmark table. In that case you can use the following format.

CREATE TABLE bookmark1 AS SELECT * FROM bookmark;

Or you can also use the insert statement with subquery. For different insert statement options refer: SQL As Understood By SQLite

Upvotes: 23

Wadood Chaudhary
Wadood Chaudhary

Reputation: 121

create table NewTable as
select * from OldTable where 1 <> 1

This will copy data structure for you.

Upvotes: 11

Nick Dandoulakis
Nick Dandoulakis

Reputation: 43110

You can try this query:

insert into bookmark1 select * from bookmark

Upvotes: 52

vit
vit

Reputation: 2685

You could do:

create table bookmark1 as select * from bookmark;

Upvotes: 193

Related Questions