SQL
SQL
SQL
update employee
set sex = 'F' where ssn = 999823489
___________________________________________________________________________________
__________
Termwork-1
----------
create table person
( driver_id varchar(10) primary key,
name varchar(15) not null,
address varchar(20) not null);
update participated set damage_amt = 25000 where reg_no = '®_no' and report_no =
12;
___________________________________________________________________________________
__________
Termwork-2
-----------
create table customer(custno int,cname varchar(10),city varchar(10),primary
key(custno));
___________________________________________________________________________________
___________
create schema 5_Shopping;
#----------------------------------------------------------------------------------
--------------------------------------
create table customer(
c_no int,
c_name varchar(20),
city varchar(20),
constraint pk_c_noCustomer
primary key(c_no));
#----------------------------------------------------------------------------------
--------------------------------------
create table orders(
o_no int,
o_date date,
c_no int,
o_amt int,
constraint pk_o_noOrders
primary key(o_no),
constraint fk_c_noOrders
foreign key(c_no) references customer(c_no));
#----------------------------------------------------------------------------------
--------------------------------------
create table item(
i_no int,
i_price int,
constraint pk_i_noItem
primary key(i_no));
#----------------------------------------------------------------------------------
--------------------------------------
create table orderItem(
o_no int,
i_no int,
quantity int,
constraint fk_o_noOrderItem
foreign key(o_no) references orders(o_no),
constraint fk_i_noOrderItem
foreign key(i_no) references item(i_no));
#----------------------------------------------------------------------------------
--------------------------------------
create table warehouse(
w_no int,
city varchar(20),
constraint pk_w_noWarehouse
primary key(w_no));
#----------------------------------------------------------------------------------
--------------------------------------
create table shipment(
o_no int,
w_no int,
s_date date,
constraint pk_o_noShipment
primary key(o_no),
constraint fk_o_noShipment
foreign key(o_no) references orders(o_no),
constraint fk_w_noShipment
foreign key(w_no) references warehouse(w_no));
#----------------------------------------------------------------------------------
--------------------------------------
#1. Produce a listing: CUSTNAME, #oforders, AVG_ORDER_AMT, where the middle
# column is the total numbers of orders by the customer and the last column is
the
# average order amount for that customer.
#----------------------------------------------------------------------------------
--------------------------------------
#2. List the order# for orders that were shipped from all warehouses that the
company has
# in a specific city.
select o_no as Order_Number
from shipment, warehouse
where
shipment.w_no = warehouse.w_no and
warehouse.city = 'Bangalore';
#----------------------------------------------------------------------------------
--------------------------------------
#3. Demonstrate how you delete item# 10 from the ITEM table and make that field
null in
# the ORDER_ITEM table.
alter table orderItem drop foreign key fk_i_noOrderItem;
___________________________________________________________________________________
_____________
a. List the Order# and Ship_date for all orders shipped from Warehouse# "W2".
b. List the Warehouse information from which the Customer named "Jose Lopez" was
supplied his orders. Produce a listing of Order#, Warehouse#.
select Shipment.Order#
from Shipment, Warehouse
where Shipment.Warehouse# = Warehouse.Warehouse#
and Warehouse.City = "New York"
f. Move the shipping date by a week for all those orders originating from
warehouses
in Baltimore.
update Shipment
set Ship_date = Ship_date + 7
where Shipment.Warehouse# in (select Warehouse.Warehouse# from Warehouse where
City = "Baltimore")
g. List all items that have a price greater than the average price.
select Item#
from Item
where Unit_Price > all (select avg(Unti_Price) as Unit_Price
from Item)
Note: we are using > all construct here and the word "all" is needed and not
optional,
even though the subquery results in a single value relation.
h. Find out the maximum number of orders shipped out of warehouses in Baltimore.
select max(Num_Orders)
from (Select Warehouse#, count(#Orders)
from Shipment as S, Warehouse as W
where S.Warehouse# = W.Warehouse# and W.City = "Baltimore"
group by Warehouse#) as WOrders (Warehouse#, Num_Orders)
j. List all customer names whose orders were shipped from a warehouse in the same
city as they live in.
Select Cname
from Customer as C, Order as O, Shipment as S, Warehouse as W
where C.Cust# = O.Cust#
and O.Order# = S.Order#
and S.warehouse# = W.warehouse#
and C.City = W.City
___________________________________________________________________________________
____________________________________________________
Termwork -3
4)select distinct(c.course),c.cname,b.bookisbn,t.booktitle
from course c,textt,bookadoption b
where c.course=b.course and b.bookisbn=t.bookisbn and c.dept='&dept'
and c.course in(select course
from bookadoption
group by course
having count(course)>=2)
order by c.cname;
5) select dept
from((select c.dept,count(b.bookisbn)
from course c,bookadoption b
where c.course=b.course
group by c.dept)
intersect
(select c.dept,count(b.bookisbn)
from course c,bookadoption b,text t
where c.course=b.course and b.bookisbn=t.bookisbn and t.publisher='&publisher'
group by c.dept));
============================================================
CREATE TABLE STUDENT(
2 REGNO VARCHAR(10),
3 NAME VARCHAR(10),
4 MAJOR VARCHAR(10),
5 BDATE DATE,
6 PRIMARY KEY(REGNO));
___________________________________________________________________________________
_______________________________________________________________________________
Termwork-4
___________________________________________________________________________________
_________________________________________________________________________________
Termwork-5
create table Bank( Bank_Code int, Name varchar(10),address varchar(15), primary key
(Bank_Code));
create table Branch(Branch# int,Name varchar(10),address varchar(15), Bank_Code int
references Bank(Bank_Code), primary key(Bank_Code,Branch#));
create table Customer1(customer# int, Name varchar(10),telephone# int,address
varchar(20),primary key(customer#));
create table Account(acc# int, acc_type varchar(10),Branch# int, Bank_Code,primary
key(acc#),Foreign key (Branch#,Bank_Code) references Branch);
create table Loan(loan# int, loan_type varchar(10),Branch# int, Bank_Code
int,primary key(loan#),Foreign key (Branch#,Bank_Code) references Branch);
create table Availed_by(loan# int references Loan(loan#),customer# references
Customer1(customer#),primary key(loan#,customer#));
create table Held_by(acc# int references Account(acc#),customer# int references
Customer1(customer#),primary key(acc#, customer#));