Creating an sqlite database using command line shell in windows - sqlite

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

Related

Cannot open sqlite command line interface

I used the following on the cmd to try and open the sqlite command line interface, but somehow it is not recognised.
I can see the sqlite db has been created, so cannot see what I am doing wrong:
(env) E:\Python installation\myproject\myflaskproject>sqlite
'sqlite' is not recognized as an internal or external command,
operable program or batch file.
(env) E:\Python installation\myproject\myflaskproject>
I've also tried typing at the prompt: >>sqlite3
Still, the same error.
download slqlit3
to download slqlit3 go to this url: https://www.sqlite.org/download.html
since your are working on windows platform, under Precompiled Binaries for Windows section download sqlite-tools-win64-x64-3320300.zip or sqlite-tools-win32-x86-3320300.zip if your are like me working on the very OLD windows 7 32bit architecture
you have to know sqlite3 is a standalone and executable file meaning sqlite3 don't require to be installed like other programs:
A bundle of command-line tools for managing SQLite database files, including the command-line shell program, the sqldiff.exe program, and the sqlite3_analyzer.exe program.
unzip the downloaded file the under C:\ for e.g. and rename the folder to C:\sqlite3 to make things simple.
now, if you open : C:\sqlite3, you'll find 3 executable files:
C:\sqlite3
sqldiff.exe
**sqlite3.exe**
sqlite3_analyzer.exe
add an Environment Variable
open System Properties (see this post)
go to Advanced tab under System Properties and click Environment Variables
Under System Variables create those variables:
PYTHON_HOME = C:\Python37 (it depends where you already installed python and which version if you have multiple installations)
SQLITE_HOME = C:\sqlite3
go to User variables and add/append variables to PATH like so:
PATH = [..];%PYTHON_HOME%;%PYTHON_HOME%\Scripts;
open new console and check your current active python:
python --version
and then you can use sqlite3 command not sqlite (check the C:\sqlite3 installation folder):
(env) E:\Python installation\myproject\myflaskproject>sqlite
'sqlite' is not recognized as an internal or external command,
operable program or batch file.
(env) E:\Python installation\myproject\myflaskproject>sqlite3 -version
3.15.2 2016-11-28 19:13:37 bbd85d235f7037c6a033a9690534391ffeacecc8
now you can open the sqlite database file (e.g: data-dev.sqlite3 under /myflaskproject ) like
(env) E:\Python installation\myproject\myflaskproject>sqlite3 data-dev.sqlite3
SQLite version 3.15.2 2016-11-28 19:13:37
Enter ".help" for usage hints.
sqlite>
some quick useful sqlite commands
sqlite> .databases
seq name file
--- --------------- ----------------------------------------------------------
0 main E:\Python installation\myproject\myflaskproject\data-dev.sqlite3
sqlite> .tables
user
sqlite> .exit (to exit)
for more about sqlite have look at this site sqlitetutorial.net

Open .sqlite files from terminal Mac

I have to do a project with a SQL database. I am asked to use the following file:
https://github.com/jpwhite3/northwind-SQLite3/blob/master/Northwind_small.sqlite
But the file downloads as .sqlite and I can't open it from my terminal. It is part of the requirement to only open it from the terminal, I can't use SQLite studio or anything like that as I should be able to open it directly. When I try to open it I get the following error:
Error: near line 1: near "SQLite": syntax error
or got an empty database, but when I open it with SQLite studio, all the data is in the file.
This is a screenshot from my terminal:
Terminal
I need to download the data base and be able to manage it.

sqlite3 - getting trouble with SQLite3 shell

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).

SQLite installation problems

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

Locate Database File in SQLITE

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

Resources