Friday, 18 November 2011

SQLite Query

On the terminal of Mac 10.6
(Application -> Utility -> Termincal )

sqlite3 abc.sql

CREATE TABLE IF NOT EXISTS InfoAll (sno INTEGER PRIMARY KEY AUTOINCREMENT,username TEXT, pswd TEXT, link TEXT, hint TEXT);

CREATE TABLE IF NOT EXISTS mainTable(mastersno INTEGER PRIMARY KEY AUTOINCREMENT,masterusername TEXT, masterpswd TEXT);

.quit

select 'DROP table ' || name from sqlite_master where type = 'table';
-----  =====>
DROP table sqlite_sequence
DROP table mainTable
DROP table InfoAll

select name from sqlite_master where type = 'table';
-----====>
sqlite_sequence
InfoAll
mainTable

select *from sqlite_master where type = 'table';
-----====> shows all structure of database



---------new Query
CREATE TABLE IF NOT EXISTS mainTable(mastersno INTEGER PRIMARY KEY AUTOINCREMENT,masterusername TEXT UNIQUE, masterpswd TEXT,mastername TEXT,
securityq TEXT,securitya TEXT);

-----6 columns

INSERT INTO mainTable (masterusername,masterpswd,mastername,securityq,securitya) VALUES ('gaurav@baltech.in','123','gaurav','Childhood Friend',
'ram');
--
CREATE TABLE IF NOT EXISTS InfoAll (sno INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT,username TEXT, pswd TEXT, hint TEXT, url TEXT,userID TEXT);

-----7 columns

INSERT INTO InfoAll (category,username,pswd,hint,url,userID) VALUES ('Emails','gaurav@baltech.in','pass123','serial password','Gmail.com','9');

--extra query
SELECT *FROM InfoAll WHERE category='Windows' AND userID='1';

SELECT *FROM InfoAll WHERE userID='1' AND (username LIKE '%RAM%' OR url LIKE '%RAM%');

UPDATE mainTable SET masterpswd ='123' WHERE masterusername='2'

SELECT *FROM mainTable WHERE mastersno=1;







No comments:

Post a Comment