9
votes

I have my sqlite3.exe file in C:\ and i want to create an sqlite database in C:\db\sqlite.I have tried sqlite3 ex1 as suggested on the docs http://www.sqlite.org/sqlite.html but i get the error Error Near "sqlite3".

What is the correct way of creating a new database from the shell?.

3

3 Answers

18
votes

Here is one way to use SQLite3 from the command prompt in Windows.

First you need to know the path to the folder where you installed the SQLite ODBC Driver. If you used the default settings this would be C:\Program Files\SQLite ODBC Driver on Windows XP

Go to Start -> Run -> type cmd -> click OK

Type cmd

This opens the command prompt.

Command prompt

In the Shell, type in the following command. You can use Alt + Space if you prefer to use cut and paste. Remember to modify the path for your setup if you installed SQLite in another folder.

cd C:\Program Files\SQLite ODBC Driver

Path to folder

This brings you to the SQLite install folder. Now you are ready to call SQLite. Type the following command at the SQLite prompt.

sqlite3

Call SQLite

This opens the File menu where you can choose a database to connect to, or create a new database file.

File menu

Navigate to C:\db\sqlite and create myDatabase.db, and click Open to close the file menu.

Now you are ready to work on your new database, run your queries, e.g. create a table.

Create table

11
votes

As new file is created in current directory, for creating file at different location you should follow this format:

eg. for storing file FILENAME.db at c:/users/xyz/abc you should type

sqlite>.open c:/users/xyz/abc/FILENAME.db

and then press enter a new file will be created at the mentioned path.

and now when you will type .databases you will see your file listed in the list of databases.

2
votes

You can use following command to create the sqlite database

.open databasename.db

or

.open c:/somefolder/databasename.db