Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how we can save database created in sqlite3

Tags:

I am new to database. I am trying to create a database and table in it. but unable to save and open again after exiting from sqlite. I am using sqlite3 3.6.20 on centOS, when i will enter following command

.save ex1.db or .open ex1.db 

it will print following error message.

Error: unknown command or invalid arguments:  "save". Enter ".help" for help Error: unknown command or invalid arguments:  "open". Enter ".help" for help 

and when Print .help it wont show any command related to save and open existing database. thanks in advance.

like image 989
erdarshp Avatar asked Jan 19 '15 12:01

erdarshp


People also ask

How do I save a database as a DB file?

Open the database or database object. On the File tab, click Save As. Do one of the following steps: To save a database in a different format, click Save Database As.

How do I save a database in SQLite studio?

Right-click on the database, and select "Export the database".

Where do I save SQLite files?

The Android SDK provides dedicated APIs that allow developers to use SQLite databases in their applications. The SQLite files are generally stored on the internal storage under /data/data/<packageName>/databases.


2 Answers

I am trying to create a database and table in it. but unable to save and open again after exiting from sqlite.

You don't need to save. Each transaction writes to disk. (More or less.)

To create the database "test.sl3", you can do this. (From the command line. Programs work about the same way.)

$ sqlite3 test.sl3 SQLite version 3.8.7.2 2014-11-18 20:57:56 Enter ".help" for usage hints. sqlite> create table test (test_id integer primary key); sqlite> insert into test values (1); sqlite> select * from test; 1 .quit 

No .save. Now load the database again.

$ sqlite3 test.sl3 SQLite version 3.8.7.2 2014-11-18 20:57:56 Enter ".help" for usage hints. sqlite> select * from test; 1 

The data is still there.

like image 87
Mike Sherrill 'Cat Recall' Avatar answered Sep 19 '22 15:09

Mike Sherrill 'Cat Recall'


You're supposed to provide a filename as an argument for the .save command, e.g.:

sqlite> .save ex1.db 

docs: http://www.sqlite.org/cli.html

like image 41
bpgergo Avatar answered Sep 21 '22 15:09

bpgergo