I tried using the following commands to create a database file at prompt, but none of them would work.
$ sqlite3 test.db
sqlite3 test.db
test.db
does it require a semi-colon at the end or is it that hard to create a database file using sqlite3 prompt?
Edit:
When I start the sqlite3 prompt, I get
SQLite version 3.6.22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>
when type "sqlite3 test.db" I get,
SQLite version 3.6.22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> sqlite3 test.db
...>
where should be the test.db file on the disk?
If you want a blank .db file just use:
touch stuff.db
I think the problem may actually be that the file does not seem to get created on disk until after you perform such action such as CREATE TABLE.
my actions:
C:\path\to\sqlite3.exe test.db
SQLite version 3.7.13 2012-06-11 02:05:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .quit
no file was created.
Then:
C:\path\to\sqlite3.exe test.db
SQLite version 3.7.13 2012-06-11 02:05:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table t1(t1key integer);
sqlite> .quit
File shows up!
For future readers, this is from SQLite.org website and works for me:
SQLite version 3.8.5 2014-05-29 12:36:14
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .open ex1.db
sqlite>
The example above causes the database file named "ex1.db" to be opened and used, and created if it does not previously exist. You might want to use a full pathname to ensure that the file is in the directory that you think it is in. Use forward-slashes as the directory separator character. In other words use "c:/work/ex1.db", not "c:\work\ex1.db".
Visit http://www.sqlite.org/cli.html for more details.
Hope this will help..
Go to command prompt
type cd \ (press enter)
cd sqlite (press enter)
sqlite3 mydb.db(press enter)
.databases(press enter)
That's strange, simply typing
sqlite3 test.db
Should create the sqlite database it does for me, does it show any errors?
When it use that command I get the following output
$ sqlite3 test.db
SQLite version 3.6.12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>
Which is the sqlite command line interface
In response to your edit you need to type sqlite3 test.db from your command line not from inside the sqlite prompt.
When you type it in your command prompt it will create the database in the directory where you are working and open the sqlite command prompt.
I faced same issue and then I logged into command prompt with Run as Administrator privilege and the issue is gone.
Hope this helps someone.
What you have is incorrect:
SQLite version 3.6.22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> sqlite3 test.db
...>
In particular the line : sqlite> sqlite3 test.db. It also does not match your statement: when type "sqlite3 test.db" I get,.
The command should be as follows:
sqlite3 test.db
This will then give you the following output:
SQLite version 3.20.0 2017-08-01 13:24:15
Enter ".help" for usage hints.
sqlite>
After this, you can must type .databases which will show you the full path to
your file and then type .quit to exit out of this prompt. If you don't do at
least .database command the file does not get created.
The file will be created in the directory you entered the
command.
This is clearly showns here: sqlite tutoriaspoint
Hope this helps.
You can create a SQLite database file using Linux: touch db_name.db
If you want to execute commands such as create table you have to open databse file first using: .open db_name.db
I also observed the same.
When I type sqlite3 test.db, I enter the sqlite3 prompt.
Then checked the databases using command .databases. Yahooo!! It shows the test.db and also in the directory I can see the test.db file.
I think the db file is visible only after we do any operation in the new database file. (Not sure)
It sounds like your Environment Variables haven't been setup to use SQLite3. Now I'm not sure of your OS, but here's how to set it under WinXP:
- Start -> Right-click 'My Computer'
- Select 'Properties'
- Select the 'Advanced' tab
- Click 'Environment Variables'
- (Under 'System Variables') Select 'Path'
- Click 'Edit'
- (Under 'Variable Value') Go to the end of the line and enter the path to your sqlite3.exe (minus sqlite3.exe) For example: C:\bin\sqlite3\;
And that's it! But remember that each path under 'Variable Value' is separated by a semi-colon, so make sure there is one before your new path.
Related
I am new to SQLite3.
I am trying to create a DB in the shell. When I run the shell, it already shows:
SQLite version 3..
Enter ".help" for instructions ..
Enter SQL...
Enter SQL statements terminated with a ";"
I read somewhere that I should be able to type "$" and codes like "$ sqlite3 mynotes.db"
Now, I need to be able to name my DB (like "mynotes.db") and be able to decide in which folder I want it to be saved.
Can someone help me? Cheers!
The $ somewhere was supposed to be a prompt of some shell (command processor), where you start sqlite3 and specify database name (which is created if does not exists).
If you're running sqlite3 without a shell (by clicking on sqlite3.exe?), it's time to try another way. CMD.EXE on Windows is as good for this job as a typical Unix shell.
As of the folder where the database will be: either cd to this folder before you run sqlite3 mynotes.db, or specify full pathname to the database: sqlite3 "C:\Users\Me\Documents and Settings\mynotes.db" (double quotes are needed when argument contains spaces).
When sqlite3 is started with no parameters, the database will be in memory. Sqlite3 supports "attaching" other databases (see ATTACH DATABASE description). This way, you can create and open on-disks databases even if starting sqlite3 with parameters is impossible for some reason (or too hard).
I need to convert from sqlite2 db to sqlite3, is there any tutorial that shows how to do it? And if I migrate correctly what to expect as I start the project?
The SQLite website says:
sqlite OLD.DB .dump | sqlite3 NEW.DB
where sqlite is version 2 and sqlite3 is version 3.
Converting an SQLite2 database to an SQLite3 database on Windows
-- Step-by-step instructions --
1- Download SQLite2 and SQLite3 command-line tools
Download links:
sqlite.exe
http://web.archive.org/web/20031203050807/http://sqlite.org/download.html
(Precompiled Binaries For Windows)
sqlite3.exe
http://www.sqlite.org/download.html
(Precompiled Binaries for Windows)
2- Copy sqlite.exe, sqlite3.exe and the db to convert to the same folder (i.e.: D:\TEMP)
3- Open a Windows command prompt ( [WINDOWS KEY] + [R], then type "cmd" or via the Start Menu)
4- Browse to the folder where you've just copied the files (i.e.: type "D:", then "cd temp")
5- Type "sqlite OLD.DB .dump | sqlite3 NEW.DB" (without the quotes), where OLD.DB is the db file you want to convert and NEW.DB is the name of the converted file that will be created.
Hope this helps.
EDITED: ANSWER TO THE QUESTION
To the conversion
Go to http://www.sqlite.org/download.html
Download sqlite-dll file (which stays in Precompiled Binaries For Windows)
Unpack it and copy to C:\Windows\System32 folder
What are the differences? (quoted from PHP - SQLite vs SQLite3)
SQLite2 internally stores every value as a string, regardless of its type.
Upgrading to SQLite3 will certainly shrink the database size since numbers and BLOBS get stored in their native formats, which could make things run faster.
starting from 3.6.23 version it supports foreign keys.
I downloaded the binaries for windos for sqlite and extracted them. There were three files
a shell
dll
analyzer
when I try to run to create a database and a table from the sqlite shell i get....
SQLite version 3.7.8 2011-09-19 14:49:19
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> sqlite3 test.db
...> create table tbl1(one varchar(10), two smallint);
Error: near "sqlite3": syntax error
sqlite>
when I try to run to create a database and a table from the command line(Vista) shell I get....
Microsoft Windows [Version 6.0.6000]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.
C:\Users\codenamejupiterx>sqlite3 test.db
'sqlite3' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\codenamejupiterx>
does anyone have any ideas?????
There is no "installation".
The error is that "sqlite3.exe" was not found in the search path as defined by the (Windows) PATH environment variable. Either add it to %PATH% (see How do I set or change the PATH system variable?) or use a complete file qualification that does not rely on %PATH%. A fully qualified invocation may look like:
C:\path\to\sqlite\sqlite3.exe test.db
Running sqlite3 by "double clicking" the executable in Windows Explorer is the same as above [as it uses an absolute path to run the sqlite3 executable] -- albeit without the ability to specify the database name or other options. (These can be specified in a "shortcut" to sqlite3, if desired.)
Happy coding.
You run the command sqlite3 test.db to start the sqlite shell. (your first example) From in there, you do not need that part of the command again, just issue the "create table " command.
I think you need this:
SQLite-1.0.66.0-setup.exe And sqliteadmin to open sqlite database
Regards
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?.
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
This opens the 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
This brings you to the SQLite install folder. Now you are ready to call SQLite. Type the following command at the SQLite prompt.
sqlite3
This opens the File menu where you can choose a database to connect to, or create a new database file.
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.
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.
You can use following command to create the sqlite database
.open databasename.db
or
.open c:/somefolder/databasename.db
I have created a file named "MyFile.db" using SQLite3 from my C#.net application. This file got created in my "D:\MyProject\bin" folder. I have created a table named "MyTable" inside "MyFile.db" from same C# app.
Now I am running sqlite3.exe from my "C:\" drive to get Command Line Shell For SQLite.
How can I get the file "D:\MyProject\bin\MyFile.db" in the SQLite Command Line Shell
i.e, how can I locate the file "MyFile.db" in the command shell to get the data from "MyTable".
You can start sqlite3.exe with the database as a paramater:
sqlite3.exe D:\MyProject\bin\MyFile.db
Or you could open sqlite3 as you are and attach the database at runtime using the syntax described here