-- 1. Creating tables
CREATE TABLE Client_Master (
    Clientno VARCHAR2(6),
    Name VARCHAR2(20),
    Address VARCHAR2(30),
    City VARCHAR2(10),
    Pincode NUMBER(8),
    State VARCHAR2(15),
    Baldue NUMBER(10,2)
);

CREATE TABLE Product_Master (
    Productno VARCHAR2(6),
    Description VARCHAR2(15),
    Um VARCHAR2(10),
    QOH NUMBER(10),
    Reorderlvl NUMBER(5),
    Sellprice NUMBER(8,2),
    Costprice NUMBER(8,2)
);

-- 2. Inserting data
-- Data for Client_Master table
INSERT INTO Client_Master VALUES ('C00001', 'Asha', 'A/14, worli', 'Mumbai', 400054, 'Maharashtra', 15000);
INSERT INTO Client_Master VALUES ('C00002', 'Lakshmi', '65, Nariman', 'Bangalore', 560001, 'Karnataka', 0);
INSERT INTO Client_Master VALUES ('C00003', 'Puja', 'P-76, Bandra', 'Mumbai', 400002, 'Maharashtra', 10000);
INSERT INTO Client_Master VALUES ('C00004', 'Shankar', 'A/6, Juhu', 'Mangalore', 400044, 'Karnataka', 5000);
INSERT INTO Client_Master VALUES ('C00005', 'Deepak', '68, TNagar', 'Chennai', 6320018, 'Tamilnadu', 0);

-- Data for Product_Master table
INSERT INTO Product_Master VALUES ('P00001', 'T-Shirts', 'Piece', 200, 40, 350, 250);
INSERT INTO Product_Master VALUES ('P0345', 'Shirts', 'Piece', 150, 50, 500, 350);
INSERT INTO Product_Master VALUES ('P06744', 'Cotton Jeans', 'Piece', 50, 20, 600, 450);
INSERT INTO Product_Master VALUES ('P0990', 'Chuddy', 'Piece', 100, 40, 400, 250);
INSERT INTO Product_Master VALUES ('P08823', 'Sarries', 'Piece', 60, 50, 500, 300);
select * from Client_Master;
select * from Product_Master;

-- 3. Retrieving records from a table
-- a. Find out the names of all the clients
SELECT Name FROM Client_Master;

-- b. Retrieve the entire contents of the Client_Master table
SELECT * FROM Client_Master;

-- c. Retrieve the list of names, city, and state of all the clients
SELECT Name, City, State FROM Client_Master;

-- d. List the various products available from the Product_Master table
SELECT * FROM Product_Master;

-- e. List all the clients who are located in Mumbai
SELECT * FROM Client_Master WHERE City = 'Mumbai';

-- 4. Updating records in a table
-- a. Change the City of Clientno ‘C00001’ to ‘Chennai’
UPDATE Client_Master SET City = 'Chennai' WHERE Clientno = 'C00001';

-- b. Change the Baldue of Clientno ‘C00005’ to Rs.1000
UPDATE Client_Master SET Baldue = 1000 WHERE Clientno = 'C00005';

-- c. Change the cost price of ‘Shirts’ to Rs. 400
UPDATE Product_Master SET Costprice = 400 WHERE Description = 'Shirts';

-- d. Change the QOH of the ‘T-Shirts’ to 150
UPDATE Product_Master SET QOH = 150 WHERE Description = 'T-Shirts';

-- 5. Deleting records in a table
-- a. Delete all products from Product_Master where the quantity on hand is equal to 100
DELETE FROM Product_Master WHERE QOH = 100;

-- b. Delete from Client_Master where the column state holds the value “Tamilnadu”
DELETE FROM Client_Master WHERE State = 'Tamilnadu';

-- c. Delete all clients from Client_Master where the Baldue is equal to 0
DELETE FROM Client_Master WHERE Baldue = 0;

-- 6. Altering the table structure
-- a. Add a column called Profitpercent of datatype NUMBER(10,2) to the Product_Master
ALTER TABLE Product_Master ADD Profitpercent NUMBER(10,2);

-- b. Change the size of the Sellprice column in Product_Master to 10,2
ALTER TABLE Product_Master MODIFY Sellprice NUMBER(10,2);

-- c. Change the name of the column UM to UnitMeasure in Product_Master
ALTER TABLE Product_Master RENAME COLUMN Um TO UnitMeasure;

-- d. Drop the column UnitMeasure
ALTER TABLE Product_Master DROP COLUMN UnitMeasure;

-- e. Drop the table Client_Master along with its data
DROP TABLE Client_Master;
 
by

SQLite online editor

Write, Run & Share SQLite queries online using OneCompiler's SQLite online editor and compiler for free. It's one of the robust, feature-rich online editor and compiler for SQLite. Getting started with the OneCompiler's SQLite editor is really simple and pretty fast. The editor shows sample boilerplate code when you choose language as 'SQLite' and start writing queries to learn and test online without worrying about tedious process of installation.

About SQLite

SQLite is an in-process C library that implements small, fast, serverless, zero-configuration, transactional SQL database engine.

Key Features:

  • Very small and light weight
  • Serverless
  • Free to use
  • Self contained as no other dependencies required.
  • zero config

Syntax help

Useful Commands

1. CREATE

CREATE TABLE table_name (
                column1 datatype,
                column2 datatype,
                ....);

Example

CREATE TABLE EMPLOYEE (
  empId INTEGER PRIMARY KEY,
  name TEXT NOT NULL,
  dept TEXT NOT NULL
);

2. ALTER

ALTER TABLE Table_name ADD column_name datatype;

Example

INSERT INTO EMPLOYEE VALUES (0001, 'Dave', 'Sales');

3. DROP

DROP TABLE table_name;

4. INSERT

INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);

Note: Column names are optional.

Example

INSERT INTO EMPLOYEE VALUES (0001, 'Ava', 'Sales');

5. SELECT

SELECT column1, column2, ...
FROM table_name
[where condition]; 

Example

SELECT * FROM EMPLOYEE where dept ='sales';

6. UPDATE

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition; 

Example

UPDATE EMPLOYEE SET dept = 'Sales' WHERE empId='0001'; 

7. DELETE

DELETE FROM table_name where condition;

Example

DELETE from EMPLOYEE where empId='0001'; 

8. CREATE INDEX

  CREATE [UNIQUE] INDEX index_name on table_name(column_name);

9. DROP INDEX

DROP INDEX index_name ON table_name;

10. Create a View

CREATE VIEW View_name AS 
Query;

11. How to call view

SELECT * FROM View_name;

12. Altering a View

ALTER View View_name AS 
Query;

13. Deleting a View

DROP VIEW View_name;

14. INNER JOIN

SELECT * FROM TABLE1 INNER JOIN TABLE2 where condition;

15. LEFT JOIN

SELECT * FROM TABLE1 LEFT JOIN TABLE2 ON condition;

16. RIGHT JOIN

SELECT * FROM TABLE1 RIGHT JOIN TABLE2 ON condition;

17. CROSS JOIN

SELECT select_list from TABLE1 CROSS JOIN TABLE2;