MTA SQL - LAB Assignment 2019 - 20
MTA SQL - LAB Assignment 2019 - 20
Sr.
Name Of Program
No.
1. Create table Salespeople with fields snum, sname, city, commission, contact
create table salespeople1(
snum int primary key,
saname varchar(50),
city varchar(50),
commission int not null,
contact bigint)
2. Orders table with field's onum, odate, snum, cnum,amt
create table order1(onum int primary key,
odate datetime,
snum int references salespeople1(snum),
1
cnum int references customer(cnum),
amt int not null
)
3. Customers table with field's cnum, cname, city, rating, Contact
create table customer(cnum int primary key,
cname varchar(50),
city varchar(50),
rating float,
contact bigint
)
2 1. Insert records in the table Salespeople, Orders, Customers by single insertion, insert all and multiple
insertion. Write query to display all records of table
insert into salespeople1 values(11,'xyz','pune',500,8456123)
insert into salespeople1
1
values(12,'onkar','pune',1000,84556123)
insert into salespeople1
values(13,'savya','somatnephata',2000,8880021455)
insert into salespeople1
values(14,'abhishek','prayagraj',25000,9896546512)
insert into salespeople1
values(15,'kuldeep','delhi',1000,845787495)
insert into salespeople1
values(16,'milind','pune',500,8456123)
2
1. Display names of all customers matched with the names of salespeople in the database
2. Create a union of two queries that shows the names, cities & ratings of all customers. Those with a rating of
12 200 or greater will also have ratings "high rating", while the others will have the words "low rating".
3. Write a command that produces the name & number of each salesperson & each customer with more than
one current order. Put results in alphabetical order.
1. Write a query that uses a sub-query to obtain all orders for the customer named 'Gopal'. Assume you do not
know the customer number
13 2. Write a query that produces the names & ratings of all customers who have above-average orders.
3. Write a query that selects the total amt in orders for each salesperson for whom this total is greater than the
amount of the largest order in table
1. Find all orders by customers not located in same cities as their Salespersons.
2. select name & city of sales person who brought orders having amount greater than 15000
14
3. Select orders with their salespeople along with salespeople not brought orders
4. Find commission of salespeople for all orders in the order table. (Cross Join)
1. Find the square root of 167 and display the answer in absolute value
2. Find out power of 15.2456 and display the answer by rounding it up to 2 decimal points.
15
3. Find 168.5 %23 and display absolute result.
4. Find out floor and ceil of 128.485 & 76.65
1. Find out name, city and rating of customer, display name & city in capital letters.
16 2. Display details of employee with first letter of every word as capital
3. Show usage of string function substr() & length
1. Find out number of months of salespeople that they are bringing orders.
17 2. Find out the date of Thursday after 02-sep-15
3. Find out the date after 6 months from first order of every salespeople.
1. Create view of giving details about salespeople having commission between 15 and 30.
2. Create view with name & city of salespeople & total number of their orders with amount.
3. Create index on sname of salespeople
18
4. Create index on odate of orders
5. Show usage of Synonym
6. Show usage of Sequence
1. Write function ‘fJdate( )’ which will accept ‘emp_id’ and return his joining date.
19 2. Display all employees whose joining date falls between year 2011 to 2017. Use ‘fJdate( )’ to retrieve joining
date of employee.
1. Write a ‘instead of ‘ trigger for employees table which will moves the record on ‘delete’ to ‘emptemp’
20
table.