In: Computer Science
Tables:
Create table Item( &nbs...
Bookmark
Tables:
Create table Item(
ItemId char(5) constraint itmid_unique primary key,
Decription varchar2(30),
Unitcost number(7,2));
Create table Customer(
custID char(5) constraint cid.unique primary key,
custName varchar2(20),
address varchar2(50));
Create table Orderdata(
orderID char(5) constraint oid_uniq primary key,
orderdate date,
shipdate date,
ItemId char(5) references Item.ItemId,
No_of_items number(4),
Unitcost number(7,2),
Order_total number(7,2),
custID char(5) references customer.custID);
Insert Into Item values(‘A123’,’Pencil’,2.5);
Insert Into Item values(‘B123’,’Pen’,15);
Insert Into Customer(‘C123’,’ABC Gen stores’,’Sanfransico’);
Insert Into Customer(‘C132’,’XYZ stores’,’California’);
Insert into Orderdata(‘o123’,’12-aug-2016’,’12-aug-2016’,’A123’,5,2.5,12.5,’c123’);
Insert into Orderdata(‘o124’,’14-aug-2016’,’14-aug-2016’,’B123’,5,15,75,’c132’);
_____________________________________________________________
Enhance your Module 5 CT database table structures, via your selected RDBMS, as you wish.
, using SQL and an SQL script file, create and execute advanced queries of your choice that demonstrate each of the following:
The use of a GROUP BY clause, with a HAVING clause, and one or more group functions
The use of UNION operator
The use of a subquery
The use of an outer join
Then create and execute at least one SQL UPDATE and at least one SQL DELETE query.
Finally, create and use an SQL view and in a SELECT query.
Submit the following outputs of your SQL script file processing, in this order and appropriately labeled, in a single Word file:
The SQL and results of your INSERT statements to further populate your tables
The SQL and results of your 4 advanced SELECT queries
The SQL and results of your UPDATE and DELETE queries
The SQL and results of your view creation and its use in a SELECT query
You must show all of your SQL as it executed in Management Studio or other development environments. This includes the results returned by your selected RDBMS.
(((((((((((Note)))))))))))))))): you must populate any other tables and show the execution of your SQL statements as required.
Use a SELECT statement using the UNION operator.
create a view and use it in a SELECT query...
Execute in Oracle PLSQL Developer
--1. The use of a GROUP BY clause, with a HAVING clause, and one
or more group functions
--This query returns the list of items whose cost is more than
2
select Description,Unitcost from Item group by
Description,Unitcost having Unitcost >=2;
--2 The use of UNION operator
--This query fetches all the records with columns ItemID,Unitcost
in Item table and Orderdata table
select ItemId,Unitcost from Item
union
select ItemId,Unitcost from Orderdata
---3 The use of a subquery
---this query will fetch all the orderdata info whose has maximum
Cost
select * from Orderdata where Unitcost in (select max(Unitcost)
from Item);
--4 The use of an outer join
--this query fetches all records along with their description of
items.
select a.*,b.Decription from Orderdata a
LEFT OUTER JOIN Item b
ON a.ItemId =b.ItemId
---5 Then create and execute at least one SQL UPDATE and at
least one SQL DELETE query.
--this sql statement updates the unit cost of the pencil item to
3.
UPDATE Item
set Unitcost=3
where ItemId='A123'
--delete orderdata of particular customer in Orderdata table
delete from Orderdata where custID ='C123'
---View
--this view fetches the orders done on curent date
create or replace view VW_OrderDetails as
select orderID,orderdate,shipdate,ItemId,No_of_items,Unitcost,Order_total,custID where
to_date(orderdate)= sysdate;
Usage of view:
select * from VW_OrderDetails ;