You are on page 1of 4

Database Management System Lab Manual

Experiment 14
Open Ended Lab
CLO1 EXECUTE the Database Server using MS SQL Server 2017 by using Structure Query Language, students
will be able to apply DML and DDL commands in database management. Programming and debugging,
using different views, functions, procedures and forms in MS SQL Server can program and debug the
queries. [ P4, PLO - 5 ]
CLO2. Adopt the laboratory rules and safety procedures; perform the lab experiments and solve
problems on cohort Levels through effective communication [A3, PLO-8]

Lab Objective:
Purpose of this open ended lab is to develop an analytical, logical and thinking ability of a
student to solve any Database Management System related problems.
An Organization has a database which maintains the records for the customer which places the
order(s) through the salesmen. There can be more than on customer who places the order(s)
through a single salesman or there can be single customer which places the order(s) through
multiple salesmen.
The tables and details that you will have to enter in the database are:

Table 1 SALESMEN
SID SNAME CITY SALARY PRODUCT COMM
S101 Ajay Patel Ahmedabad 3000 books 1200

S102 Chintan Shah Baroda 4000 pencils 1500

S103 Vinay Mehra Pune 5000 skirts 1200

S104 Jay Pandey Surat 6000 apples 800

S105 Jimit Dave Mumbai 2000 oranges 300

S106 Manan Gandhi Ahmedabad 1000 pens 1200


Database Management System Lab Manual

Table 2 à CUSTOMERS
CID CNAME CITY STATE PINCODE PRODUCT CLASS
C301 Nirav Patel Nadiad Pakistan 001 books B
C302 Kiran Dave Delhi India 002 pencils A
C303 Sapan Shah Bangalore America 003 skirts B
C304 Saurabh Mehta Baroda India 004 Apple C

C305 Smriti Mishra Ahmedabad India Rajistan 005 orange B

C306 Harshal Pandya Mumbai India 006 pens A

C307 Sunil Gandhi Baroda India 007 mobiles B


C308 Bimal Thakkar Surat India 008 mangoes C

Table 3 à ORDERS
OID CID SID PRODUCT QUANTITY ODATE O_AMT
O501 C302 S102 books 2 02-JAN-09 700000
O502 C301 S105 pencils 12 21-JAN-09 10000
O503 C308 S103 skirts 1 10-FEB-09 250000
O504 C306 S104 apple 7 14-FEB-09 400000
O505 C306 S102 orange 10 29-MAR-09 100000
O506 C303 S101 pens 5 15-APR-09 90000.50
O507 C304 S105 mangoes 3 24-JUN-09 7500.75
O508 C306 S101 cellphone 1 27-SEP-09 900000
O509 C302 S102 car 1 21-DEC-09 205000
O510 C307 S102 ball 6 30-DEC-09 27800
O511 C303 S104 computer 2 31-DEC-09 15000

1. Create the database for this problem Statement.


2. Create tables and identity constraints from the given query.
3.Design the ER diagram for this database.
4. Solve the following queries:
a) List all the salesmen that live outside the Gujrat.
b) List the name of all the salesmen whose salary is greater than 2000.
c) Display order id and order date from orders table whose sales id is S102.
d) List all the information of customers in descending order according to their name.
e) Display total order amount for each salesman.
Database Management System Lab Manual

Solution:
1. Create the database for this problem Statement.
Query:
CREATE DATABASE ORGANIZATION;

2. Create tables and identity constraints from the given query.


CREATE TABLE CUSTOMERS
CREATE TABLE CUSTOMERS (CID VARCHAR2(5)
PRIMARY KEY, CNAME VARCHAR2(20), CITY
VARCHAR2(20), STATE VARCHAR2(15), PINCODE
NUMBER(8), PRODUCT VARCHAR2(20), CLASS CHAR(1)
DEFAULT ‘A’);
CREATE TABLE SALESMEN
CREATE TABLE SALESMEN (SID VARCHAR2(5) PRIMARY
KEY, SNAME VARCHAR2(20), CITY VARCHAR2(15),
SALARY NUMBER(5,2), PRODUCT VARCHAR2(20),
TGTTOGET NUMBER(5,2), COMM NUMBER(5,2));
CREATE TABLE ORDER
CREATE TABLE ORDER1(OID VARCHAR2(5) PRIMARY
KEY, CID VARCHAR2(5), SID VARCHAR2(5), PRODUCT
VARCHAR2(20), QTY NUMBER(5), ODATE DATE , O_AMT
NUMBER(8,2), FOREIGN KEY(CID) REFERENCES
CUSTOMERS, FOREIGN KEY(SID) REFERENCES
SALESMEN, CHECK (O_AMT >=0));

3.Design the ER diagram for this database.


Database Management System Lab Manual

4. Solve the following queries:


a. List all the salesmen that live outside the Gujrat.
Query:
SELECT* FROM SALESMEN WHERE CITY=”Gujrat”;

b. List the name of all the salesmen whose salary is greater than 2000.
Query:
SELECT SNAME FROM SALESMEN WHERE SALARY > 2000;

c. Display order id and order date from orders table whose sales id is S102.
Query:
SELECT OID, ODATE FROM ORDERS WHERE SALES ID=”S102”;

d. List all the information of customers in descending order according to their name.
Query:
SELECT* FROM CUSTOMER WHERE ORDER BY NAME DESC;

e. Display total order amount for each salesman.


Query:
SELECT O_AMT FROM ORDERS RIGHT JOIN SALESMEN ON
SALESMEN.SID=ORDERS.SID;

You might also like