1

Im new to databases. now im going to learm sqlite. I downloaded sqlite shell 3.7.14.1. Im trying to creat a database ang googling this for a long time. but cant find a answer.
in the shell I gave command sqlite3 test.db then it shows ...> then i exit with command .exit but I see no database is created. please can someone help me in this issue.

enter image description here enter image description here

5
  • How do you know no database is created? Have you tried creating any tables? sqlite.org/sqlite.html
    – Matt Ball
    Nov 29, 2012 at 15:39
  • yes I just created a table sqlite> create table mytable(id integer primary key, value text) also. there is no file created in the working directory called test.db Nov 29, 2012 at 15:44
  • @MattBall I want to know where is the .db file created. its not in the working directory Nov 29, 2012 at 15:48
  • 1
    You are trying this within a sqlite session! This can't work. End with a ; and start fresh with a clean create table.
    – Mithrandir
    Nov 29, 2012 at 16:26
  • @Mithrandir please explain me clearly. what am I doing wrong Nov 29, 2012 at 17:02

3 Answers 3

1

The command:

sqlite3 test.db

will create the database in the file called test.db. You can go on an create tables and you will be able to sore and query data in this database.

Try this:

sqlite3 test.db "create table test_table (someid INTEGER PRIMARY KEY, somedata TEXT);"
sqlite3 test.db "insert into test_table values (1, 'Some Text');"

then

sqlite3 test.db "select * from test_table;"

Here is a sample "session" on Windows

enter image description here

7
  • where is this file created. nothing is created in the working directory Nov 29, 2012 at 15:54
  • As soon as you put some data in it, actuallay a table definition will do, the file will be created. If you just start the client and exit it right away, no file will be written. The file will be created in the current directory.
    – Mithrandir
    Nov 29, 2012 at 15:56
  • yes also I created a table and add some data too. but when i give the command .exit it shows ...> . it dosnt exit or creat a .db file, what may be the reason Nov 29, 2012 at 16:03
  • @LakshanPerera: i think you might be doing something wrong, that has nothing to do with sqlite. The commands listed in many many many many tutorials are working brilliantly and exactly as described. Hard to tell, withot some more context. the "....>" part after you exit is strange....
    – Mithrandir
    Nov 29, 2012 at 16:10
  • Is "...>" your usual shell prompt? Are you using Linux/UNIX or MS Windows? Have you tried this thing in a "new", clean shell environment?
    – Mithrandir
    Nov 29, 2012 at 16:14
1

Are you sure it hasn't been created?

Try sqllite command .databases to make sure

0
1

The

...>

is a line-continuation prompt from SQLite. Follow the steps below instead.

$ sqlite3 test.db
SQLite version 3.7.9 2011-11-01 00:52:41
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table test (n integer primary key);
sqlite> .quit

$ ls test.db 
test.db

You can pipe a SQL string into SQLite, too.

$ echo "create table test_2 (n integer primary key);" | sqlite3 test.db

And you can look at the tables like this.

$ sqlite3 test.db
SQLite version 3.7.9 2011-11-01 00:52:41
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .tables
test    test_2

Or provide the SQL string as an argument to the sqlite3 executable.

$ sqlite3 test.db "create table test3 (n integer primary key);"
2
  • I edited my question and added the screenshot after following this. nothing happens its showing ...> only. am I doing something wrong Nov 29, 2012 at 16:41
  • 1
    The "$" in my example is my shell prompt, not something you type into SQLite. Get out of sqlite entirely, and start from your shell's prompt. Then begin again from my first example. Pay attention to your prompts. Nov 29, 2012 at 17:05

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.