RDBMS - SQL - Tutorial - DBMS - Lab
RDBMS - SQL - Tutorial - DBMS - Lab
Q.1. A database is being constructed for storing sales information system. A product can be described
with a unique product number, product name, selling price, manufacturer name. The product can sale to
a particular client and each client have it own unique client number, client name, client addresses, city,
pin code, state and total balance to be required to paid. Each client order to buy product from the
salesman. In the order, it has unique sales order number, sales order date, client number, salesman
number (unique), billed whole payment by the party or not and its delivery date. The salesman have the
name, addresses, city, pin code, state, salary of the sales man, delivery date, total quantity ordered,
product rate.
Create table product (product_id varchar(10) primary key, product_name varchar(20), manufacturer_name
char(20),product_rate number(9,4), sell_price number(9,4),product_description varchar(25));
Create table client (client_id varchar(10) primary key, client_name char(20),address varchar(15), city
char(15),pin number(8), state char(15),bal_due number(9,4));
Create table salesman (salesman_id varchar(10) primary key, salesman_name char(20),address varchar(15), city
char(15),pin number(8), state char(15),salary number(9,4));
Create table sales_order_details (sales_order_no varchar(10) primary key, sales_order_date date, client_id
varchar(10) references client(client_id), salesman_id varchar(10) references salesman(salesman_id) ,
bill_payby_party char(5), delivery_date date,product_rate number(9,4), tot_quantity_order
number(8),cancel_date date default NULL);
(a) Retrieve the list of names and the cities of all the clients.
SQL> Select client_name, city from client;
CLIENT_NAME CITY
alak roy amarpur
suman roy agartala
priya das kamalpur
mita mia singur
pulak roy sonitpur
munni das sonitpur
kusum roy tezpur
mina das tezpur
moytree nayak tezpur
pauri mia tezpur
manali das tezpur
11 rows selected.
pauri mia
manali das
(e) Find the products whose selling price is greater than 2000 and less than or equal to
5000 SQL> SELECT * FROM product WHERE sell_price > 2000 AND (sell_price < 5000
OR
2 sell_price = 5000);
PRODUCT_ID PRODUCT_NAME MANUFACTURER_NAME PRODUCT_RATE SELL_PRICE PRODUCT_DESCRIPTION
SALES_ORDE SALES_ORD
on01001 01-AUG-08
on01003 12-AUG-08
on01004 13-AUG-08
on01005 14-AUG-08
on01006 15-AUG-08
on01007 16-JAN-08
on01008 01-FEB-08
7 rows selected.
(j) Delete all the records having delivery date before 25th August, 2008.
SQL> DELETE FROM sales_order_details WHERE delivery_date < '25-aug-2008';
2 rows deleted.
SQL> Select * from sales_order_details;
SALES_ORDE SALES_ORD CLIENT_ID SALESMAN_I BILL_ DELIVERY_ NEW_PRODUCT_RATE
TOT_QUANTITY_ORDER CANCEL_DA
1 row updated.
SQL> select * from sales_order_details sales_order_details WHERE sales_order_no = 'on01008';
(n) List the names, city and state of the clients not in the state of ‘ASSAM’
SQL> SELECT client_name,city,state FROM client WHERE NOT state =‘assam’;
CLIENT_NAME CITY STATE