0% found this document useful (0 votes)
122 views11 pages

Assignment 4

1. The document describes creating and populating various tables like Client_Master, Product_Master, etc. using SQL queries. 2. It then demonstrates retrieving data from the tables using queries with various WHERE and ORDER BY clauses. 3. The document also shows updating, modifying, deleting records and altering the tables using SQL queries.

Uploaded by

soham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
122 views11 pages

Assignment 4

1. The document describes creating and populating various tables like Client_Master, Product_Master, etc. using SQL queries. 2. It then demonstrates retrieving data from the tables using queries with various WHERE and ORDER BY clauses. 3. The document also shows updating, modifying, deleting records and altering the tables using SQL queries.

Uploaded by

soham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

ASSIGNMENT 4

Creating Tables
1. Creating the table Client_Master
Query:
CREATE TABLE Client_Master(
Client_no VARCHAR2(6) PRIMARY KEY CHECK(Client_no LIKE 'C%'),
Name VARCHAR2(20) NOT NULL,
City VARCHAR2(15),
Pincode NUMBER(8),
State VARCHAR2(15),
BalDue NUMBER(10,2));
Output:

2. Creating the table Product_Master


Query:
CREATE TABLE Product_Master(
Product_no VARCHAR2(6) PRIMARY KEY CHECK(Product_no LIKE 'P%'),
Description VARCHAR2(15) NOT NULL,
Qty_on_Hand NUMBER(8) NOT NULL,
Sell_Price NUMBER(8,2) NOT NULL CHECK(Sell_Price > 0),
Cost_Price NUMBER(8,2) NOT NULL CHECK(Cost_Price > 0));
Output:

3. Creating the Table Salesman_Master


Query:
CREATE TABLE Salesman_Master(
Salesman_no VARCHAR2(6) PRIMARY KEY CHECK(Salesman_no LIKE 'S%'),
Salesman_Name VARCHAR2(20) NOT NULL,
City VARCHAR2(20) NOT NULL,
Pincode NUMBER(8) NOT NULL,
State VARCHAR(20) NOT NULL,
Sal_Amt NUMBER(8,2) NOT NULL CHECK(Sal_Amt > 0));
Output:

4. Creating the table Sales_Order


Query:
CREATE TABLE Sales_Order(
Order_no VARCHAR2(6) PRIMARY KEY CHECK(Order_no LIKE 'O%'),
Client_no VARCHAR2(6),
Order_Date DATE,
Salesman_no VARCHAR2(6),
Dely_Type CHAR(1) DEFAULT 'F' CHECK(Dely_Type IN ('P','F')),
Dely_Date DATE,
FOREIGN KEY(Client_no) REFERENCES Client_Master(Client_no) ON DELETE
CASCADE,
FOREIGN KEY(Salesman_no) REFERENCES Salesman_Master(Salesman_no) ON
DELETE CASCADE);

Output:

5. Creating the table Sales_Order_Details


Query:
CREATE TABLE Sales_Order_Details(
Order_no VARCHAR2(6),
Product_no VARCHAR2(6),
Qty_Disp NUMBER(8),
Product_Rate NUMBER(10,2),
FOREIGN KEY(Order_no) REFERENCES Sales_Order(Order_no) ON DELETE
CASCADE,
FOREIGN KEY(Product_no) REFERENCES Product_Master(Product_no) ON
DELETE CASCADE);
Output:
Inserting Values
1. Inserting values into Client_Master
Query:
INSERT INTO Client_Master VALUES('C001','Soham Patra', 'Kolkata', 700091,
'West Bengal', 200);
INSERT INTO Client_Master VALUES('C002', 'Prinan Sil', 'Chennai', 811201,
'Tamil Nadu', 150);
INSERT INTO Client_Master VALUES('C003', 'Shubhadeep Saha', 'Mumbai',
565645, 'Maharashtra', 300);
INSERT INTO Client_Master VALUES('C004', 'Shayambhavi Bakshi', 'Mumbai',
565456, 'Maharashtra', 640);
INSERT INTO Client_Master VALUES('C005', 'Srimonti Banerjee', 'Chennai',
764641, 'Tamil Nadu', 510);
INSERT INTO Client_Master VALUES('C006', 'Aditi Das', 'Kolkata', 764114, 'West
Bengal', 400);

Output:

2. Inserting Values into Product_Master


Query:
INSERT INTO Product_Master VALUES('P1','Trousers', 150, 1400, 1000);
INSERT INTO Product_Master VALUES('P2','Shirt', 120, 1500, 800);
INSERT INTO Product_Master VALUES('P3','TShirt', 100, 600, 400);
INSERT INTO Product_Master VALUES('P4','Cap', 100, 200, 100);
INSERT INTO Product_Master VALUES('P5','Shoes', 80, 1000, 800);

Output:
3. Inserting Values into Salesman_Master
Query:
INSERT INTO Salesman_Master VALUES('S1','John', 'Kolkata', 700091, 'West
Bengal', 4000);
INSERT INTO Salesman_Master VALUES('S2','Joey', 'Chennai', 357353, 'Tamil
Nadu', 3000);
INSERT INTO Salesman_Master VALUES('S3','Ross', 'Bangalore', 575735,
'Karnataka', 3500);
INSERT INTO Salesman_Master VALUES('S4','Chandler', 'Mumbai', 787354,
'Maharashtra', 3000);
INSERT INTO Salesman_Master VALUES('S5','Zeke', 'New Delhi', 873734, 'New
Delhi', 3500);

Output:

4. Inserting Values into Sales_Order


Query:
INSERT INTO Sales_Order VALUES('O1','C001', '24-02-2022', 'S2', 'P', '24-03-2022');
INSERT INTO Sales_Order VALUES('O2','C001', '12-02-2022', 'S1', 'F', '12-04-2022');
INSERT INTO Sales_Order VALUES('O3','C002', '12-06-2022', 'S3', 'P', '12-07-2022');
INSERT INTO Sales_Order VALUES('O4','C003', '11-12-2022', 'S4', 'P', '11-01-2023');
INSERT INTO Sales_Order VALUES('O5','C005', '12-12-2022', 'S5', 'F', '11-02-2023');

Output:

5. Inserting Values into Sales_Order_Details


Query:
INSERT INTO Sales_Order_Details VALUES('O1','P2', 20, 4.5);
INSERT INTO Sales_Order_Details VALUES('O2','P1', 25, 4.3);
INSERT INTO Sales_Order_Details VALUES('O3','P4', 20, 4);
INSERT INTO Sales_Order_Details VALUES('O4','P3', 20, 4.6);
INSERT INTO Sales_Order_Details VALUES('O5','P5', 15, 4.3);
Output:

Queries
1. Exercise on retrieving records from a table
a. Find out the name of all clients
Query:
SELECT Name FROM Client_Master;

Output:

b. Retrieve entire content of the table Client_Master


Query:
SELECT * FROM Client_Master;

Output:

c. Retrieve the Name, city and state of all clients


Query:
SELECT Name,City,State FROM Client_Master;
Output:

d. List the various products available from the Product_Master Table


Query:
SELECT Product_no, Description FROM Product_Master;

Output:

e. List all clients who are located in Mumbai


Query:
SELECT Client_no, Name FROM Client_Master WHERE City=’Mumbai’;

Output:

f. Find the name of salesman who have a salary equal to 3000


Query:
SELECT Salesman_Name from Salesman_Master WHERE Sal_Amt=3000;

Output:
g. Show the details of Product_Master according to Cost_Price in Descending
Order
Query:
SELECT * FROM Product_Master ORDER BY Cost_Price DESC;

Output:

h. Show different types of Salary amounts of the salesman


Query:
SELECT DISTINCT Sal_Amt FROM Salesman _Master;

Output:

i. Show only unique product details


Query:
SELECT DISTINCT Description FROM Product_Master;

Output:
2. Exercise on updating records in a table
a. Change the city of client no ‘C001’ to ‘Bangalore’.
Query:
UPDATE Client_Master SET City = ‘Bangalore’ WHERE Client_no =
‘C001’;
SELECT * FROM Client_Master;

Output:

b. Change the BalDue of client no ‘C006’ to Rs. 1000.


Query:
UPDATE Client_Master SET BalDue=1000 WHERE Client_no = ‘C006’;
SELECT * FROM Client_Master;

Output:

c. Change the cost price of ‘Trousers’ to Rs. 950.00.


Query:
UPDATE Product_Master SET Cost_Price=950.00 WHERE Description =
‘Trousers’;
SELECT * FROM Product_Master;
Output:

d. Change the city of the salesman to ‘Pune’.


Query:
UPDATE Salesman_Master SET City= ‘Pune’ WHERE Salesman_no = ‘S1’;
SELECT * FROM Salesman_Master;

Output:

3. Add a column named ‘Telephone’ of datatype number and size = 10 to the


Client_Master Table
Query:
ALTER TABLE Client_Master ADD(Telephone NUMBER(10));
DESC Client_Master;

Output:

4. Change the size of Sell_Price column in Product_Master to 10, 2.


Query:
ALTER TABLE Product_Master MODIFY(Sell_Price NUMBER(10,2));
DESC Product_Master;
Output:

5. Drop the column Cost_Price from Product_Master.


Query:
ALTER TABLE Product_Master DROP Column Cost_Price;
DESC Product_Master;

Output:

6. Delete all salesmen from the Salesman_Master whose salaries are equal to Rs. 3500.
Query:
DELETE FROM Salesman_Master WHERE Sal_Amt=3500;
SELECT * FROM Salesman_Master;

Output:

7. Delete all products from Product_Master where the quantity on hand is equal to 100.
Query:
DELETE FROM Product_Master WHERE Qty_on_Hand = 100;
SELECT * FROM Product_Master;
Output:

8. Delete from Client_Master where the column state holds the value ‘Tamil Nadu’.
Query:
DELETE FROM Client_Master WHERE State= ‘Tamil Nadu’;
SELECT * FROM Client_Master;

Output:

9. Change the name of the Salesman_Master table to Sman_Mast.


Query:
RENAME Salesman_Master to Sman_Mast;
SELECT * FROM Sman_Mast;

Output:

10. Destroy the table Client_Master along with its data.


Query:
DROP TABLE Client_Master;

Output:

You might also like