Bash – Sqlite3
Wanted to use a very light weight file based Database Engine and Sqlite3 was my 1st choice. I am making this post on basic commands on Sqlite3 for my anytime reference.
Installing
sudo apt-get install sqlite3
Starting and using Basic commands
- $sqlite3 db_name.db – creates a new db with the give name
- sqlite3>.databases – list the available databases
- sqlite3>.tables – list the existing tables inside the selected database
- sqlite3>.schema tablename – displays the structure of the table.
- sqlite3>create table tablename (field1 datatype, field2 datatype, etc…);
Eg:- create table test(id INTEGER PRIMARY KEY AUTOINCREMENT, name CHAR(40)); - sqlite3>insert into tablename(fields) values(values);
Eg:- insert into test(NULL,”Pras”); or
insert into test(id,name) values(NULL,”Pras”); - sqlite3>update tablename set fieldname=value where fieldname=value;
Eg:- update test set name=”Prasanna” where name=”Pras”; - sqlite3>select * from tablename;
Eg:- select * from test; or
select * from test where name=”Prasanna”; - sqlite3>drop table test; – deletes my table even from the entry
- sqlite3>delete from tablename – deletes the values and schema of the table.
- sqlite3>.quit – Get out of sqlite shell prompt and return to Bash.