QUESTION 1
Queries and Output :
q: Creating Client_Master Table
CREATE TABLE Client_Master (
ClientNo varchar(6) PRIMARY KEY,
Name varchar(20),
Address1 varchar(30),
Address2 varchar(30),
City varchar(15),
PinCode int,
State varchar(15),
BalDue int
);
q: Creating Product_Master Table
CREATE TABLE Product_Master (
ProductNo varchar(6) PRIMARY KEY,
Description varchar(15),
ProfitPercent varchar(4),
UnitMeasure varchar(10),
QtyOnHand int,
RecorderLvl int,
SellPrice int,
CostPrice int
);
q: Creating Salesman_Master Table
CREATE TABLE Salesman_Master (
SalesmanNo varchar(6) PRIMARY KEY,
SalesmanName varchar(20),
Address1 varchar(30),
Address2 varchar(30),
City varchar(20),
PinCode int,
State varchar(20),
SalAmt int,
TgttoGet int,
YtdSales int,
Remarks varchar(60)
a) Data for Client_Master Table
ClientNo Name Address1 Address2 City PinCode State BalDue
C00001 Ivan Bayross NULL NULL Mumbai 400054 Maharashtra 15000
C00002 Irmata Muzumdar NULL NULL Madras 780001 Tamil Nadu 0
C00003 Chhaya Bankar NULL NULL Mumbai 400057 Maharashtra 5000
C00004 Ashwini Joshi NULL NULL Bangalore 560001 Karnataka 0
C00005 Hanse Colaco NULL NULL Mumbai 400060 Maharashtra 2000
C00006 Deepak Sharma NULL NULL Manglore 560006 Karnataka 0
b
Queries and Output :
q: Inserting data into Client_Master
INSERT INTO Client_Master (ClientNo, Name, Address1, Address2, City, PinCode,
State, BalDue) VALUES
('C00001', 'Ivan Bayross', NULL, NULL, 'Mumbai', 400054, 'Maharashtra', 15000),
('C00002', 'Tomas Muzumdar', NULL, NULL, 'Madras', 7800054, 'Tamil Nadu',
NULL),
('C00003', 'Chamya Bankar', NULL, NULL, 'Mumbai', 400057, 'Maharashtra', 5000),
('C00004', 'Ashwini Joshi', NULL, NULL, 'Bangalore', 560001, 'Karnataka', NULL),
('C00005', 'Hansel Colaco', NULL, NULL, 'Mumbai', 400060, 'Maharashtra', 2000),
('C00006', 'Deepak Sharma', NULL, NULL, 'Mangalore', 560005, 'Karnataka', NULL);
q: Inserting data into Product_Master
INSERT INTO Product_Master (ProductNo, Description, ProfitPercent, UnitMeasure,
QtyOnHand, RecorderLvl, SellPrice, CostPrice) VALUES
('P0801', 'T-Shirts', 5, 'Piece', 150, 50, 500, 250),
('P8365', 'Shirts', 5, 'Piece', 100, 30, 750, 350),
('P0785', 'Jeans', 5, 'Piece', 150, 50, 1500, 750),
('P8785', 'Pull Overs', 2.5, 'Piece', 80, 30, 750, 450),
('P9875', 'Denim Shirts', 5, 'Piece', 200, 50, 1500, 750),
('P7975', 'Lycra Tops', 5, 'Piece', 75, 30, 750, 300),
('P8865', 'Skirts', 5, 'Piece', 75, 30, 750, 300);
q: Inserting data into Salesman_Master
INSERT INTO Salesman_Master (SalesmanNo, SalesmanName, Address1, Address2,
City, PinCode, State, SalAmt, TgttoGet, YtdSales, Remarks) VALUES
('S00001', 'World', NULL, NULL, 'Mumbai', 400022, 'Maharashtra', 3000, 200, 150,
'Good'),
('S00002', 'Omkar', NULL, NULL, 'Mumbai', 400021, 'Maharashtra', 3000, 200, 100,
'Good'),
('S00003', 'Raj', 'F-7', NULL, 'Nairnani', 400023, 'Maharashtra', 3000, 200, 100,
'Good'),
('S00004', 'Ashish', NULL, NULL, 'Mumbai', 400044, 'Maharashtra', 3500, 200, 150,
'Good');
EXERCISE 3: Exercise on retrieving the data:
a) Find out the name 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 the state of all the clients.
SELECT Name, City, State FROM Client_Master;
d) List the various products available from the Product_Master table.
SELECT Description FROM Product_Master;
e) List all the clients who live in Mumbai.
SELECT * FROM Client_Master WHERE City = 'Mumbai';
f) Find the names of salesmen who have a salary equal to Rs.3000.
SELECT SalesmanName FROM Salesman_Master WHERE SalAmt = 3000;
EXERCISE 4: Exercise on updating the records in the table:
a) Change the city of ClientNo ‘C00005’ to ‘Bangalore’.
UPDATE Client_Master
SET City = 'Bangalore'
WHERE ClientNo = 'C00005';
b) Change the BalDue of ClientNo ‘C00001’ to Rs.1000.
UPDATE Client_Master
SET BalDue = 1000
WHERE ClientNo = 'C00001';
c) Change the cost price of ‘Trousers’ to Rs.950.00.
UPDATE Product_Master
SET CostPrice = 950
WHERE Description = 'Jeans';
d) Change the city of the salesman to Pune.
UPDATE Salesman_Master
SET City = 'Pune';
EXERCISE 5: Exercise on deleting the records in the table:
a) Delete all the salesmen from the Salesman_Master whose salaries are equal to 3500.
DELETE FROM Salesman_Master WHERE SalAmt = 3500;
b) Delete all products from Product_Master where the QtyOnHand is equal to 100.
DELETE FROM Product_Master WHERE QtyOnHand = 100;
c) Delete from Client where the column state = "Mahrashtra"
DELETE FROM Client_Master WHERE state = "Maharashtra";
EXERCISE 6: Exercise on altering the table structure
d) Add a column ‘Telephone’ of data type number and size 10 to the Client_Master
table.
ALTER TABLE Client_Master
ADD Telephone int(10);
e) Change the size of SellPrice column of Product_Master to 10,2.
ALTER TABLE Client_Master
ADD Telephone NUMBER(10);
EXERCISE 5: Exercise on deleting the records in the table:
f) Destroy table Client_Master along with its data.
DROP TABLE Client_Master;
EXERCISE 5: Exercise on deleting the records in the table:
g) Change the name of the Salesman_Master to sman_mast.
ALTER TABLE Salesman_Master RENAME TO Smal_Mast;