Wednesday, January 4, 2017

Essential commands for working with SQLite 3

1. Create Database

  > sqllite3 test.db



2. Create Table

sqlite> create table employees (id interger primary key,name text);


3. Inserting into Table

sqlite> insert into employees values(1, 'Sujata Regoti');



4. Representing in table format

 To display each record in different row and align column wise, set mode to column
sqlite> .mode column 
To display headers i.e column names set headers on
sqlite> .headers on
Now display Table using SQL Select command
sqlite> select * from employees;



5. As name field require more space set using width and specify width for each column

sqlite> .width 15 20
Now Display
sqlite>select * from employees;


6. Exit and Reopen

sqlite> .exit
> sqlite3 test.db


7. To see created tables

sqlite> .tables


Here I have 2 stables employees and student

8. To display each information on its own line set mode to line

sqlite> .mode line
Now display table
sqlite>select * from employees;


9. To see commands used for tables use schema

sqlite> .schema
Or for particular table then specify table name
sqlite> .schema employees



10. To see current settings

sqlite> .show


11. To set nullvalue to "NULL" instead of blank "" as shown in settings

sqlite> .nullvalue 'NULL'


12. To output database on screen use dump

sqlite> dump


13. To save about dump into file then use .output and specify destination

sqlite> .output  D:\study\Employees
sqlite> .dump
sqlite> .output stdout



14. Delete, Drop table

To delete records
sqlite> delete from employees;
To Drop Table
sqlite> drop table employees;



15. To read database which is created previously

Connect to new database



Read from sql file


16. To select table with insert commands

sqlite> .mode insert
sqlite> select * from employees;


17. Working with Different modes: 

> .mode html


>.mode list


>.mode tabs


>.mode tcl



> mode .csv


18. Extract information into CSV.

Use above command to set csv mode.Then
sqlite> .mode csv
sqlite> .output E:/study/Employees.csv
sqlite> select * from employees;
sqlite> .output stdout










                                                 







SQLite Very Simple way to install on Windows

1.Go to https://sqlite.org/download.html



2. Scroll down until you get Precompiled Binaries for Windows. 


3. Click on link to Download where you see command-line shell 
4. Unzip downloaded zip file.
5. Cut Paste .exe file(s) into C:/Windows/System32
6. Open cmd and type sqlite3


Thats It.. :)