SlideShare a Scribd company logo
Aisling Fallon Higher Diploma in Computing
1
Oracle SQL-Noel Tierney
Higher Diploma in Computing 2013/2014
Internet Cafe Users
2014
AislingFallon
A00203593
1/13/2014
Aisling Fallon Higher Diploma in Computing
1
Table of Contents Page No.
1. Introduction………..............................................……. 2
2. Data…………………………………………………………………….. 3
3. Identifying Primary and Foreign Keys………………… 4
4. ERD Entity Relationship Diagram………………………… 5
5. Extended ERD……………………………………………………… 6
6. Create Table Statements………………………………………. 7-10
7. Insert Statements………………………………………………… 11-20
8. Tables………………………………………………………………….. 21-23
9. Single Table Queries…………………………………………….. 24-29
10. Joins……………………………………………………………………. 30-36
11. Summary Queries………………………………………………… 37-41
12. Subqueries…………………………………………………………… 42-54
13. Inserts, Updates and Deletes………………………………… 55-68
14. Views……………………………………………………………………. 69-80
15. Alter Tables…………………………………………………………. 81-84
16. Security……………………………………………………………….. 85-87
17. Transaction Processing…………………………………………… 88-98
Aisling Fallon Higher Diploma in Computing
2
1. Introduction
This projectinvolved the use of oracleSQL. A set of tables and columns for an Internet Cafe User had to be
examined in order to identify the various linksbetween the tables and to establish theprimary and foreign
keys. An Entity Relationship Diagrams could then be created to show clearly the directlinks between the
tables.
When this was complete data was populated in the various columns of each table, then usingcreate table
statements and insertstatements the data was inserted into OracleSQL.
This allowed for the followingto be achieved usingselectstatements:
-DML(Data Manipulation Language)-Inserts,Updates,Deletes
-DDL(Data Description Language)-Create, Alter, Drop
-DCL(Data Control Language)-Grant Revoke
Aisling Fallon Higher Diploma in Computing
3
2. Data
Internet Café Users ICU
Aisling Fallon Internet Café Users ICU HDC Sep 2013
Organisation thatoperates a number of internet cafes around the country. Each cafe has a number of
computers and other gadgets (Ipads,laptops,tablets etc). Users details arestored and each time that a user
wants to avail of a computer a booking (café_user_booking) holds information aboutthe computer used, who
used itand for how long, as well as the amount charged to the customer. When computers break down or
need maintenance, one of the technicians employed by the organisation repairsthecomputer.
Internet_Café (Internet_Café_Id, Name, Address, Town, County, Web_Site, Email,Year_Opened,
Rate_Per_Hour, Facilities (Drinks, Snacks, Sandwiches)
(Note the opening and closing times are to be stored as numbers and will be whole numbers between 1 and 24
ie the 24 hour clock)
Café_User (Café_User_Id, Firstname, Lastname, Address, Town, County, Gender, Date_Of_Birth, Nationality,
Mobile_No, Email,Type (Student, Retired, Working, Unemployed), User_Level (Novice, Intermediate, Expert)
Gadget (Gadget_ID, Name, Type (Laptop, PC, Tablet etc,), Screen_Size, Hard_Disk_Size, RAM_Size,
Operating_System (eg Windows 2000,Linux, Vista etc), Video_Card (Yes, No), Sound_Card (Yes/No),
Date_Purchased, Cost_Price, Expected_Life (express in months), Resale_Value,Internet_Café_Id, Supplier_ID,)
Café_User_Booking( Café_User_ID, Gadget_Id,Date_Booked, Start_Time, End_Time, Amount_Due, Activity
(Email, Internet, Word Processing, Excel, Access, Other), Payment_Method (Cash, Credit Card, Laser Card)
Supplier (Supplier_Id,Name, Address, Country, Web_Site, Year_Founded, Specialism(PCs,Laptops,
Peripherals, Servers),Annual_Turnover)
Gadget_Repair(Gadget_Id, Repair_Date, Details,Cost, Time_Taken, (express in minutes), Technician_Id)
Technician (Technician_Id,FName, Sname, Address, Town, County, Qualifications(Certificate, Degree, MSc),
Expertise (Hardware, Software, Networks), Hourly_Rate, Date_Hired, Mobile_No)
Aisling Fallon Higher Diploma in Computing
4
3. Identifying Primary and Foreign Keys
Internet_Café PK-Internet_Café_Id, Name, Address, Town, County, Web_Site, Email,Year_Opened,
Rate_Per_Hour, Facilities
Café_UserPK-Café_User_Id, Firstname,Lastname, Address, Town, County, Gender, Date_Of_Birth, Nationality,
Mobile_No, Email,Type ,User_Level
Supplier PK- Supplier_Id, Name, Address, Country, Web_Site, Year_Founded, Specialism,Annual_Turnover
Gadget Pk-Gadget_ID, Name, Type Screen_Size, Hard_Disk_Size, RAM_Size,
Operating_System,Video_Card,Sound_Card,Date_Purchased, Cost_Price, Expected_Life,Resale_Value, FK-
Internet_Café_Id, FK- Supplier_ID
Café_User_BookingFk- Café_User_ID,FK- Gadget_Id,Date_Booked, Start_Time, End_Time, Amount_Due,
Activity, Payment_Method
Technician Pk- Technician_Id,FName, Sname, Address, Town, County, Qualifications,Expertise,Hourly_Rate,
Date_Hired, Mobile_No
Gadget_RepairPk-Gadget_Id, Repair_Date, Details,Cost, Time_TakenFK-Technician_Id
Aisling Fallon Higher Diploma in Computing
5
4. ERD-Entity Relationship Diagram
Aisling Fallon Higher Diploma in Computing
6
5. Extended ERD
Aisling Fallon Higher Diploma in Computing
7
6. Create Table Statements
drop
table Internet_Cafe ;
create
table Internet_Cafe (
Internet_Cafe_Id Number ( 3 ) ,
Name Varchar2 ( 19 ) ,
Address Varchar2 ( 15 ) ,
Town Varchar2 ( 14 ) ,
County Varchar2 ( 9 ) ,
Web_Site Varchar2 ( 19 ) ,
Email Varchar2 ( 24 ) ,
Year_Opened Number ( 4 ) ,
Rate_Per_Hour Number ( 1 )
ConstraintIntC_Rate_Per_Hour_NN NOT
NULL,
Facilities Varchar2 ( 11 ) ,
Constraint IntC_IntCId_PK Primary Key(Internet_Cafe_Id),
Constraint IntC_County_Ck Check(County In('Cavan', 'Clare', 'Cork', 'Sligo', 'Roscommon')),
Constraint IntC_Name_Uq Unique(Name));
drop
table Cafe_User ;
create
table Cafe_User (
Cafe_User_Id Number ( 2 ) ,
Firstname Varchar2 ( 7 ) ,
Lastname Varchar2 ( 9 ) ,
Address Varchar2 ( 13 ) ,
Town Varchar2 ( 14 ) ,
County Varchar2 ( 9 ) ,
Gender Varchar2 ( 6 ) ,
Date_Of_Birth Date
ConstraintCafe_User_Date_Of_Birth_NN
NOT NULL,
Nationality Varchar2 ( 7 ) ,
Mobile_No Number ( 11 ) ,
Email Varchar2 ( 21 ) ,
Type Varchar2 ( 10 ) ,
User_Level Varchar2 ( 12 ) ,
Constraint Cafe_User_Cafe_User_Id_PK Primary Key(Cafe_User_Id),
Constraint Café_User_Nationality_Ck Check(Nationality In('Irish', 'French', 'British', 'Italian', 'Welsh'))
Constraint Café_User_Email_Uq Unique(Email));
Aisling Fallon Higher Diploma in Computing
8
drop
table Supplier ;
create
table Supplier (
Supplier_Id Number ( 2 ) ,
Name Varchar2 ( 25 ) ConstraintSupplier_Name_NN NOT NULL,
Address Varchar2 ( 12 ) ,
Country Varchar2 ( 13 ) ,
Web_Site Varchar2 ( 20 ) ,
Year_Founded Number ( 4 ) ,
Specialism Varchar2 ( 11 ) ,
Annual_Turnover Varchar2 ( 5 ) ,
Constraint Supplier_Supplier_Id_PK Primary Key(Supplier_Id),
Constraint Supplier_Annual_Turnover_Ck Check(Annual_Turnover BETWEEN 55000 AND 74000),
Constraint Supplier_Name_Year_Founded_Uq Unique(Name, Year_Founded));
Column10 Number ( 6 ) ,
drop
table Gadget ;
create
table Gadget (
Gadget_Id Number ( 4 ) ,
Name Varchar2 ( 9 )
ConstraintGad_Name_NN Not
Null,
Type Varchar2 ( 11 ) ,
Screen_Size_Inches Number ( 5 ) ,
Hard_Disk_Size_Inches Number ( 4 ) ,
RAM_Size Number ( 1 ) ,
Operating_System Varchar2 ( 12 ) ,
Video_Card Varchar2 ( 3 ) ,
Sound_Card Varchar2 ( 3 ) ,
Date_Purchased Date ,
Cost_Price Number ( 3 ) ,
Expected_Life Number ( 2 ) ,
Resale_Value Number ( 4 ) ,
Internet_Cafe_Id Number ( 3 ) ,
Supplier_Id Number ( 2 ) ,
Constraint Gad_GadId_PK Primary Key(Gadget_Id),
Constraint Gad_IntCId_FK Foreign Key(Internet_Cafe_Id) References Internet_Cafe(Internet_Cafe_Id),
Constraint Gad_Supplier_Id_FK Foreign Key(Supplier_Id) References Supplier(Supplier_Id),
Constraint Gad_Type_Ck Check(Type In('Laptop', 'PC', 'Tablet', 'Netbook', 'Subnotebook')),
Constraint Gad_Name_Resale_Value_Uq Unique(Name, Resale_Value));
Aisling Fallon Higher Diploma in Computing
9
drop
table Cafe_User_Booking ;
create
table Cafe_User_Booking (
Cafe_User_Id Number ( 2 ) ,
Gadget_Id Number ( 4 ) ,
Date_Booked Date ,
Start_Time Varchar2 ( 17 ) ,
End_Time Varchar2 ( 17 ) ,
Amount_Due Number ( 1 ) ,
Activity Varchar2 ( 15 ) ,
Payment_Method Varchar2 ( 11 ) ,
Constraint CafeUBook_CafeU_Id_GadId_PK Primary Key(Cafe_User_Id,Gadget_Id),
Constraint CafeUBook_GadId_FK Foreign Key(Gadget_Id) References Gadget(Gadget_Id),
Constraint CafeUBook_Cafe_User_Id_FK Foreign Key(Cafe_User_Id) References
Cafe_User(Cafe_User_Id),
Constraint CafeUBook_Amount_Due_Ck Check(Amount_Due >=3));
drop
table Technician ;
create
table Technician (
Technician_Id Number ( 4 ) ,
FName Varchar2 ( 8 ) ,
Sname Varchar2 ( 9 ) ,
Address Varchar2 ( 13 ) ,
Town Varchar2 ( 14 ) ,
County Varchar2 ( 9 ) ,
Qualifications Varchar2 ( 11 ) ,
Expertise Varchar2 ( 8 ) ,
Hourly_Rate Number ( 2 ) ,
Date_Hired Date ConstraintDate_Hired_NN NOT NULL,
Mobile_No Number ( 11 ) ,
Constraint Tech_Tech_Id_PK Primary Key(Technician_Id),
Constraint Tech_Hourly_Rate_Ck Check(Hourly_Rate BETWEEN 15 AND 25),
Constraint Tech_Fname_Town_Uq Unique(Fname, Town));
Aisling Fallon Higher Diploma in Computing
10
Column13 Number ( 6 ) );
drop
table Gadget_Repair ;
create
table Gadget_Repair (
Gadget_Id Number ( 4 ) ,
Repair_Date Date ,
Details Varchar2 ( 18 ) ,
Cost Number ( 4 ) ,
Time_Taken Number ( 4 ) ,
Technician_Id Number ( 4 ) ,
Constraint GadRepair_GadId_Repair_Date_PK Primary Key(Gadget_Id,Repair_Date),
Constraint GadRepair_Tech_Id_FK Foreign Key(Technician_Id) References Technician(Technician_Id),
Constraint GadRepair_Cost_Ck Check(Cost Is NULL OR Cost BETWEEN 5 and 160));
0 Number ( 6 ) ,
0 Number ( 6 ) ,
0 Number ( 6 ) ,
Column13 Number ( 6 ) );
Aisling Fallon Higher Diploma in Computing
11
7. Insert Statements
Internet_Cafe Inserts
Insertinto Internet_Cafe values (101,'CruiseThe Net Cafe','Main Street','Shercock','Cavan','Cruise The Net
Cafe','cruisethenet@hotmail.com',2005,5,'Cold drinks');
Insertinto Internet_Cafe values (102,'Chill Internet Cafe','Lough North','Killaloe','Clare','Chill Internet
Cafe','chillinternet@gmail.com',2007,4,'Drinks');
Insertinto Internet_Cafe values (103,'Beans Cafe','North Street','Youghal','Cork','Beans
Cafe','beanscafe@hotmail.om',2006,5,'Sandwiches');
Insertinto Internet_Cafe values (104,'Net Station Cafe','Abbey Street','Carney','Sligo','Net Station
Cafe','netstation@yahhoo.ie',2004,5,'Snacks');
Insertinto Internet_Cafe values (105,'Angels Cafe','Killcrossbeg','Shercock','Cavan','Angels
Cafe','angelscafe@gmail.com',2010,4,'Drinks');
Insertinto Internet_Cafe values (106,'Relax Cafe','Roadford','Doolin','Clare','Relax
Cafe','relax@hotmail.ie',NULL,3,'Snacks');
Insertinto Internet_Cafe values (107,'Surfers Cafe','Granard Road','Ballyjamesduff','Cavan','Surfers
Cafe','surferscafe@hotmail.com',2005,4,'Snacks');
Insertinto Internet_Cafe values (108,'Net Play Cafe','Chapel Street','Castlebaldwin','Sli go','Net Play
Cafe','netpaly@hotmail.com',2006,5,'Snacks');
Insertinto Internet_Cafe values (109,'Comfy Cafe','Killaloe','Doolin ','Clare','Comfy
Cafe','comfycafe@yahoo.ie',2008,3,'Sandwiches');
Insertinto Internet_Cafe values (110,'MousePad Cafe','Main Street','Dysart ','Roscommon','Mouse Pad
Cafe','mousepad@gmail.com',2007,3,'Drinks');
Insertinto Internet_Cafe values (111,'TouristCafe','Barnavara Hill','Kinsale','Cork','Tourist
Cafe',NULL,2009,4,'Snacks');
Insertinto Internet_Cafe values (112,'Cyber Cafe','Church Street','Cootehill','Cavan','Cyber
Cafe','cybercaf@yahoo.com',NULL,4,NULL);
Insertinto Internet_Cafe values (113,'GlobeCafe','Station Road','Lahinch','Clare','Globe
Cafe','globescafe@gmail.com',2009,5,'Snacks');
Insertinto Internet_Cafe values (114,'One Stop Cafe','Cornaslieve','Virginia','Cavan','OneStop
Cafe','onestopcafe@hotmail.com',2008,5,'Drinks');
Insertinto Internet_Cafe values (115,'The Hangout Cafe','Market Street','Ballinode','Sligo','The Hangout
Cafe','hangout@gmail.com',2007,4,'Sandwiches');
Insertinto Internet_Cafe values (116,'Gamestation Cafe','Highfield Road','Ennis','Clare','Gamestation
Cafe','gamestation@hotmail.com',2006,3,'Snacks');
Aisling Fallon Higher Diploma in Computing
12
Insertinto Internet_Cafe values (117,'The Hub Cafe','Goff St','Mitchelstown','Cork','The Hub
Cafe','hubcafe@yahoo.ie',2005,3,NULL);
Insertinto Internet_Cafe values (118,'Neo Internet Cafe','Park Street','Athleague','Roscommon','Neo Internet
Cafe','neointernet@yahoo.ie',2009,5,'Sandwiches');
Insertinto Internet_Cafe values (119,'The Strand Cafe','Barrack Street','Aclare','Sligo','The Strand
Cafe','strandcafe@gmail.com',2008,3,'Snacks');
Commit;
Aisling Fallon Higher Diploma in Computing
13
Cafe_User Inserts
Insertinto Cafe_User values (10,'Colm','Hannon','Abbey Street','Shercock','Cavan','Male','23-Jan-
90','Irish',086-1234567,'colmh@gmail.com','Student','Novice');
Insertinto Cafe_User values (11,'Joan','Kavanagh','Church Street','Killaloe','Clare','Female','25-Dec-
50','Irish',085-7563985,'joank@gmail','Retired','Intermediate');
Insertinto Cafe_User values (12,'Niamh','Kelly','Main Street','Youghal','Cork','Female','02-Sep-
85','French',087-2578963,'niamhk@yahoo.co.uk','Working','Expert');
Insertinto Cafe_User values (13,'Aisling','McGrath','BridgeStreet','Carney','Sligo','Female','02-Sep-
85','Italian',086-9856321,'aislingmg@hotmail.com',NULL,'Expert');
Insertinto Cafe_User values (14,'Nigel','Brien','MarketSquare','Shercock','Cavan','Male','03-Jul-
76','British',089-4593621,NULL,'Unemployed','Novice');
Insertinto Cafe_User values (15,'Aoife','Donnelly','Abbey Street','Doolin','Clare','Female','19-May-
74','Welsh',089-7413259,'aoifed@hotmail.ocm','Unemployed',NULL);
Insertinto Cafe_User values (16,'Edel','Donoghue','Church Street','Ballyjamesduff','Cavan','Female','28-Mar-
80','Irish',085-0315269,'edeld@gmail.com','Unemployed',NULL);
Insertinto Cafe_User values (17,'Connell','Dowling','Main Street','Castlebaldwin','Sligo','Male','12-Feb-
91','Irish',089-7585123,'connelld@yahoo.com','Student','Novice');
Insertinto Cafe_User values (18,'Jessica','Kelly','Abbey Street','Doolin ','Clare','Female','21-Sep-
87',NULL,NULL,'jessicak@hotmil.com','Working','Expert');
Insertinto Cafe_User values (19,'Aaron','McDonald','Church Street','Dysart ','Roscommon','Male','13-Oct-
88','Irish',086-8932154,'aaronmcd@hotmail.com','Working','Expert');
Insertinto Cafe_User values (20,'Gary','Morrissey','Main Street','Kinsale','Cork','Male','14-Aug-81','Irish',085-
1212323,'garym@hotmail.com','Unemployed',NULL);
Insertinto Cafe_User values (21,'Daniel','Nevin','BridgeStreet','Cootehill','Cavan','Male','17-Feb-92','Irish',089-
9898654,'danieln@yahoo.co.uk','Student','Intermediate');
Insertinto Cafe_User values (22,'David','Quinlan','MarketSquare','Lahinch','Clare','Female','14-Aug-
81','Irish',085-8795698,'davidq@gmal.com','Retired','Intermediate');
Insertinto Cafe_User values (23,'Tracey','Brennan','Abbey Street','Virginia','Cavan','Female','06-Jun-
52','British',089-7875321,'traceyb@hotmail.om7','Retired','Novice');
Insertinto Cafe_User values (24,'Mary','McGrath','Church Street','Ballinode','Sligo','Male','24-Oct-
78','British',085-1313954,'marymcg@hotmail.com','Unemployed','Novice');
Insertinto Cafe_User values (25,'Cormac','Kavanagh','Main Street','Ennis','Clare','Female','19-Jan-
91','French',087-9568153,'cormacjk@gmail.com','Student','Novice');
Aisling Fallon Higher Diploma in Computing
14
Insertinto Cafe_User values (26,'Gillian','Kiernan','BridgeStreet','Mitchelstown','Cork','Female','16-May-
51','Italian',089-9516236,'gilliank@gmail.com','Retired','Intermediate');
Insertinto Cafe_User values (27,'Clodagh','Nolan','MarketSquare','Athleague','Roscommon','Female','28-Aug-
50','Irish',086-1425369,'clodaghn@yahoo.com','Retired','Intermediate');
Insertinto Cafe_User values (28,'Louise','Collins','Abbey Street','Aclare','Sligo','Female','08-Jul-77','Irish',085-
7875963,'louisec@hotmail.com','Working','Expert');
Insertinto Cafe_User values (29,'Ian','Donohoe','Main Street','Kilrush','Clare','Male','16-Apr-52','Irish',086-
4835915,'iand@gmail.com','Retired','Novice');
Commit;
Aisling Fallon Higher Diploma in Computing
15
Supplier Inserts
Insertinto Supplier values (50,'Tech Data Ltd.','Toronto','Canada','www.techdata.com',2009,'PCs',55000);
Insertinto Supplier values (51,'SGD IntertradingLtd.','Munich ','Germany','www.sgd.ie',2010,'Servers',56000);
Insertinto Supplier values (52,'Synnex Ltd.','Austin ','United States','www.synnes.com',2008,'Servers',57000);
Insertinto Supplier values (53,'SIS Distribution Ltd.','Bakersfield ','United
States',NULL,2007,'Peripherals',58000);
Insertinto Supplier values (54,'Eternal Distribution Ltd.','Baltimore','United
States','www.externaldist.com',2001,'Laptops',59000);
Insertinto Supplier values (55,'Intcomex Ltd.','Brampton ','Canada','www.intomex.com',2002,'PCs',60000);
Insertinto Supplier values (56,'ASBIS Ltd.','Nimes','Canada','www.asbis.ie',2003,'Servers',61000);
Insertinto Supplier values (57,'DIKO Global Ltd.','Tours','Canada','www.diko.com',NULL,'PCs',62000);
Insertinto Supplier values (58,'VST Computers Ltd.','Paris','France','www.vst.ie',2005,'Laptops',63000);
Insertinto Supplier values (59,'Nikoyo Ltd.','Lille','France','www.nikoyo.com',2006,'Servers',64000);
Insertinto Supplier values (60,'FDC International Ltd.','Lyon','France','www.fdc.ie',2007,'Peripherals',65000);
Insertinto Supplier values (61,'Avnet Ltd.','Berlin','Germany','www.avnet.com',2008,'Laptops',66000);
Insertinto Supplier values (62,'IngramMicro
Ltd.','Hamburg','Germany','www.ingrammicro.ie',2009,'PCs',57000);
Insertinto Supplier values (63,'Tech Data Ltd.','Zacatecas ','Mexico',NULL,2010,'Servers',58000);
Insertinto Supplier values (64,'SGD IntertradingLtd.','Zamora
','Mexico','www.sgd.ie',2011,'Peripherals',59000);
Insertinto Supplier values (65,'Synnex Ltd.','Zapopan ','Mexico','www.synnes.com',2005,'Peripherals',60000);
Insertinto Supplier values (66,'SIS Distribution Ltd.','Bremen','Germany','www.sis.ie',2006,'Laptops',61000);
Insertinto Supplier values (67,'Eternal Distribution
Ltd.','Nurnberg','Germany','www.externaldist.com',NULL,'Laptops',62000);
Insertinto Supplier values (68,'Intcomex Ltd.','Rochester ','United
States','www.intomex.com',2008,'Servers',63000);
Insertinto Supplier values (69,'FDC International Ltd.','Rockford ','United
States','www.fdc.ie',2009,'PCs',74000);
Commit;
Aisling Fallon Higher Diploma in Computing
16
Gadget Inserts
Insertinto Gadget values (1000,'Acer','Laptop',17.3,3.5,2,'Linux','Yes','No','13-Nov-10',650,36,550,101,50);
Insertinto Gadget values (1001,'Apple','PC',21,3.5,2,'Windows 2000','No','Yes','04-Mar-
11',700,48,550,102,51);
Insertinto Gadget values (1002,'Asus','Tablet',7,1.8,1,'Android','Yes','No','04-Mar-10',320,24,250,103,52);
Insertinto Gadget values (1003,'Dell','Netbook',10,1.8,1,'Android','Yes','No','12-Nov-12',350,18,300,104,53);
Insertinto Gadget values (1004,'Philips','Subnotebook',22,3.5,2,'Vista','Yes','No','10-Jun-
10',450,20,410,105,54);
Insertinto Gadget values (1005,'Samsung','Laptop',18.5,3.5,2,'Mac OS','Yes','No','10-Jun-
11',530,30,450,106,55);
Insertinto Gadget values (1006,'Sony','PC',22,3.5,2,'Mac OS','No','Yes','07-Nov-12',630,25,550,107,56);
Insertinto Gadget values (1007,'HP','Subnotebook',14,3.5,2,'Linux','Yes','No','07-Nov-11',650,24,600,108,57);
Insertinto Gadget values (1008,'Sharp','Tablet',8,2.5,1,NULL,'Yes','No','06-Nov-11',360,18,NULL,109,58);
Insertinto Gadget values (1009,'Zalman','Netbook',10.5,2.5,1,'Android','Yes','No','25-May-
12',390,18,290,110,59);
Insertinto Gadget values (1010,'Asus','Subnotebook',14.5,3.5,2,'Windows 2000','Yes','No','20-Jul-
10',520,18,450,106,60);
Insertinto Gadget values (1011,'Compaq','Laptop',18,3.5,2,'Vista','No','No','13-May-11',525,48,450,107,55);
Insertinto Gadget values (1012,'Epson','Tablet',8,2.5,1,'Android','Yes','No','23-Nov-10',635,20,500,108,56);
Insertinto Gadget values (1013,'Toshiba','Netbook',9.5,1.8,1,'Android','Yes','No','14-Jun-
13',360,24,300,109,57);
Insertinto Gadget values (1014,'Panasonic','PC',21.5,3.5,2,'Mac OS','No','Yes ','09-Jun-13',380,24,295,110,58);
Insertinto Gadget values (1015,'Intel','Netbook',10,2.5,1,NULL,'Yes','No ','09-Jun-13',550,36,495,104,59);
Insertinto Gadget values (1016,'Sharp','PC',21,3.5,2,'Vista','No','Yes','10-Nov-11',320,24,250,105,60);
Insertinto Gadget values (1017,'Zalman','Subnotebook',14,3.5,2,'Linux','Yes','No','10-Nov-
12',385,12,295,106,53);
Insertinto Gadget values (1018,'Asus','PC',21.5,3.5,2,'Windows 2000','No','Yes','29-Jun-
13',560,36,490,107,54);
Insertinto Gadget values (1019,'Compaq','PC',22,3.5,2,'Mac OS','No','Yes','02-Apr-11',700,18,NULL,108,55);
Commit;
Aisling Fallon Higher Diploma in Computing
17
Cafe_User_Booking Inserts
Insertinto Cafe_User_Booking values (10,1000,'01-Sep-13','09:30','10:30',5,'Email','Cash');
Insertinto Cafe_User_Booking values (11,1001,'02-Sep-13','10:30','11:30',4,'Intermet',NULL);
Insertinto Cafe_User_Booking values (12,1002,'04-Sep-13','11:30','12:30',5,'Word Processing','Laser');
Insertinto Cafe_User_Booking values (13,1003,'03-Sep-13','12:30','13:30',5,NULL,'Laser');
Insertinto Cafe_User_Booking values (14,1004,'06-Sep-13','13:30','14:30',4,'Access','Cash');
Insertinto Cafe_User_Booking values (15,1005,'05-Sep-13','14:30','15:30',3,'Other','Credit Card');
Insertinto Cafe_User_Booking values (16,1006,'07-Sep-13','15:30','16:30',4,'Internet','Credit Card');
Insertinto Cafe_User_Booking values (17,1007,'09-Sep-13','16:30','17:30',5,'Word Processing','Cash');
Insertinto Cafe_User_Booking values (18,1008,'10-Sep-13','17:30','18:30',3,'Excel','Laser');
Insertinto Cafe_User_Booking values (19,1009,'11-Sep-13','18:30','19:30',3,'Email','Laser');
Insertinto Cafe_User_Booking values (20,1010,'12-Sep-13','19:30','20:30',4,'Other','Cash');
Insertinto Cafe_User_Booking values (21,1003,'01-Sep-13','20:30','21:30',4,'Access','Cash');
Insertinto Cafe_User_Booking values (22,1004,'02-Sep-13','10:30','11:30',5,NULL,'Cash');
Insertinto Cafe_User_Booking values (23,1005,'04-Sep-13','11:30','12:30',5,'Access','Cash');
Insertinto Cafe_User_Booking values (24,1006,'03-Sep-13','12:30','13:30',4,'Internet','Credit Card');
Insertinto Cafe_User_Booking values (25,1007,'06-Sep-13','13:30','14:30',3,'Email','CreditCard');
Insertinto Cafe_User_Booking values (26,1008,'05-Sep-13','14:30','15:30',3,'Other','Laser');
Insertinto Cafe_User_Booking values (27,1009,'07-Sep-13','15:30','16:30',5,'Email','Cash');
Insertinto Cafe_User_Booking values (28,1010,'20-Sep-13','16:30','17:30',3,'Excel',NULL);
Insertinto Cafe_User_Booking values (29,1001,'21-Sep-13','17:30','18:30',4,'Excel','CreditCard');
Commit;
Aisling Fallon Higher Diploma in Computing
18
Technician Inserts
Insertinto Technician values (2000,'Aidan','Cassidy','Market
Square','Shercock','Cavan','Certificate','Software',15,'23-Oct-08',086-4536578);
Insertinto Technician values (2001,'Joe','Dougan','Abbey Street','Killaloe','Clare',NULL,'Networks',20,'22-Jun-
05',085-9685412);
Insertinto Technician values (2002,'Fionan','Downey','Church Street','Youghal','Cork','MSc','Hardware',25,'15 -
Mar-09',089-9587412);
Insertinto Technician values (2003,'Stephen','McCusker','Main
Street','Carney','Sligo','Degree','Hardware',20,'26-Jun-05',087-3698752);
Insertinto Technician values (2004,'Podsie','Muldoon','Abbey
Street','Shercock','Cavan','Degree','Software',20,'09-May-08',NULL);
Insertinto Technician values (2005,'Des','Murray','Church Street','Doolin','Clare','MSc','Networks',25,'10-Mar-
09',086-7894321);
Insertinto Technician values (2006,'Kevin','McCloskey','Main
Street','Ballyjamesduff','Cavan','Certificate','Hardware',15,'15-Jan-10',089-1476532);
Insertinto Technician values (2007,'Fachtna','McCusker','Bridge
Street','Castlebaldwin','Sligo','Degree','Software',20,'09-Sep-11',086-2369851);
Insertinto Technician values (2008,'Nicholas','Heaney','MarketSquare','Doolin ','Clare
','Msc','Hardware',25,'03-Jun-10',085-7478958);
Insertinto Technician values (2009,'Michael','Rocks','Abbey Street','Dysart
','Roscommon','Certificate','Software',15,'04-Sep-11',085-3969369);
Insertinto Technician values (2010,'Gary','Tohill','Church Street','Kinsale','Cork','Degree','Hardware',20,'05-
Jun-10',NULL);
Insertinto Technician values (2011,'Henry','Campbell','Main Street','Cootehill','Cavan','Degree',NULL,20,'15 -
Jan-08',089-1212121);
Insertinto Technician values (2012,'Sean','Crosson','BridgeStreet','Lahinch','Clare','MSc','Networks',15,'25-Jul-
09',087-3232356);
Insertinto Technician values (2013,'Johnny','Diver','Market
Square','Virginia','Cavan','Certificate','Software',25,'26-Aug-10',086-7985456);
Insertinto Technician values (2014,'Niall','Hegarty','Abbey Street','Ballinode','Sligo','Degree','Software',20,'29-
Nov-11',085-5858587);
Insertinto Technician values (2015,'Paul','McGinley','Main Street','Ennis','Clare','Msc','Hardware',15,'21-Feb-
12',089-0326587);
Insertinto Technician values (2016,'Kieran','Reid','Bridge
Street','Mitchelstown','Cork','Certificate','Software',20,'12-May-09',086-0202123);
Insertinto Technician values (2017,'David','Ruane','Market
Square','Athleague','Roscommon','MSc','Hardware',25,'18-May-09',086-8495369);
Aisling Fallon Higher Diploma in Computing
19
Insertinto Technician values (2018,'Paddy','Sweeney','Abbey Street','Aclare','Sligo',NULL,'Networks',15,'17-
Apr-11',089-3577532);
Insertinto Technician values (2019,'Eamonn','Boyle','Main Street','Kilrush','Clare','MSc','Networks',25,'24 -Oct-
10',086-7569874);
Commit;
Aisling Fallon Higher Diploma in Computing
20
Gadget_Repair Inserts
Insertinto Gadget_Repair values (1000,'01-Nov-11','Remove Virus',30,120,2000);
Insertinto Gadget_Repair values (1001,'06-Jun-12','ReplaceHard Drive',10,30,2001);
Insertinto Gadget_Repair values (1002,'05-Oct-11','Memory Upgrade',25,60,2002);
Insertinto Gadget_Repair values (1003,'02-May-13','Screen Replacement',5,15,2003);
Insertinto Gadget_Repair values (1004,'05-Dec-10','DC Socket Repairs',60,180,2004);
Insertinto Gadget_Repair values (1005,'02-May-12',NULL,50,120,2005);
Insertinto Gadget_Repair values (1006,'09-Mar-13','Windows re-install',60,240,2006);
Insertinto Gadget_Repair values (1007,'09-Mar-12','MalwareInfection',100,NULL,2007);
Insertinto Gadget_Repair values (1008,'01-May-12','Memory Upgrade',25,60,2008);
Insertinto Gadget_Repair values (1009,'08-Jul-13','Remove Virus',90,360,2009);
Insertinto Gadget_Repair values (1010,'21-Jun-12','ReplaceHard Drive',40,120,2010);
Insertinto Gadget_Repair values (1011,'17-Sep-13','Memory Upgrade',60,180,2002);
Insertinto Gadget_Repair values (1012,'24-Sep-12','Screen Replacement',30,120,2003);
Insertinto Gadget_Repair values (1013,'15-Sep-13','DC Socket Repairs',NULL,60,2004);
Insertinto Gadget_Repair values (1014,'10-Jul-13','Service',160,480,2005);
Insertinto Gadget_Repair values (1015,'10-Sep-13','Windows re-install',90,360,2006);
Insertinto Gadget_Repair values (1016,'26-Oct-12','MalwareInfection',80,240,2007);
Insertinto Gadget_Repair values (1017,'03-May-13','Memory Upgrade',75,180,2009);
Insertinto Gadget_Repair values (1018,'27-Aug-13','ReplaceHard Drive',30,120,2010);
Insertinto Gadget_Repair values (1019,'06-Jun-12',NULL,NULL,60,2002);
Commit;
Aisling Fallon Higher Diploma in Computing
21
8. Tables
Internet_Cafe
Cafe_User
Supplier
Aisling Fallon Higher Diploma in Computing
22
Gadget
Cafe_User_Booking
Aisling Fallon Higher Diploma in Computing
23
Technician
Gadget_Repair
Aisling Fallon Higher Diploma in Computing
24
9. Single Table Queries
Question 1
Show the internet cafes in Roscommon and Cavan which were opened after 2005,with an hourly rate of
between 3 and 5 euro and where the name of the cafe contains an “a”.
Select Name,Year_Opened, County, Rate_Per_Hour
From Internet_Cafe
Where Year_Opened >2005
And Name LIKE ‘%a%’
And County IN(’Roscommon’,’Cavan’)
And Rate_Per_Hour BETWEEN 3 AND 5;
Select Internet_Cafe.Name, Internet_Cafe.Year_Opened, Internet_Cafe.County,
Internet_Cafe.Rate_Per_Hour
From Internet_Cafe
Where Internet_Cafe.Year_Opened >2005
And Internet_Cafe.Name LIKE ‘%a%’
And Internet_Cafe.County IN(’Roscommon’,’Cavan’)
And Internet_Cafe.Rate_Per_Hour BETWEEN 3 AND 5;
Aisling Fallon Higher Diploma in Computing
25
Question 2
Show the first names of the cafe users except those who end with a “k”, excluding those from Cavan and
Roscommon, who have a user level and cafe user number not between 10 and 15.
Select Firstname, County, Cafe_User_Id, User_Level
From Cafe_User
Where FirstnameNOT LIKE ‘%k’
And User_Level IS NOT NULL
And County NOT IN (‘Cavan’,’Roscommon’)
And Cafe_User_Id NOT BETWEEN 10 AND 15;
Select Cafe_User.Firstname, Cafe_User.County, Cafe_User.Cafe_User_Id, Cafe_User.User_Level
From Cafe_User
Where Cafe_User.Firstname NOT LIKE ‘%k’
And Cafe_User.User_Level IS NOT NULL
And Cafe_User.County NOT IN (‘Cavan’,’Roscommon’)
And Cafe_User.Cafe_User_Id NOT BETWEEN 10 AND 15;
Aisling Fallon Higher Diploma in Computing
26
Question 3
Show the suppliers from Canada with a name containing an “e” that specialise in Servers and PC’s with the year
founded in ascending order.
Select Name, Country, Specialism,Year_Founded
From Supplier
Where Country=’Canada’
And SpecialismIN(‘PCs’,‘Servers’)
And Name LIKE ‘%e%’
Order By Year_Founded ASC;
Select S.Name, S.Country, S.Specialism,S.Year_Founded
From Supplier S
Where S.Country=’Canada’
And S.SpecialismIN(‘PCs’,‘Servers’)
And S.Name LIKE ‘%e%’
Order By S.Year_Founded ASC;
Aisling Fallon Higher Diploma in Computing
27
Question 4
Show the gadgets where the resale value is not 550 euro, also show the resale values ascending, give name
uppercase and type lowercase.
Select UPPER(Name), LOWER(Type), Cost_Price,Resale_Value
From Gadget
Where Cost_Price<>550
And Length(Name)>6
Order By Resale_Value DESC;
Select UPPER(G.Name), LOWER(G.Type), G.Cost_Price, G.Resale_Value
From Gadget G
Where G.Cost_Price<>550
And Length(Name)>6
Order By G.Resale_Value DESC;
Aisling Fallon Higher Diploma in Computing
28
Question 5
Show the technicians who have an hourly rate less than or equal to 20 euro, there qualification not starting
with a “D”. Also give the Surname in capitals and leave a white space on the left and right side of the name and
town.
Select RTRIM(FName), INITCAP(Sname), LTRIM(Town), Hourly_Rate, Qualifications
From Technician
Where Hourly_Rate<=5
Or QualificationsNOTLIKE ‘D%’;
Select RTRIM(T.FName), INITCAP(T.Sname), LTRIM(T.Town),T.Hourly_Rate, Qualifications
From Technician T
Where T.Hourly_Rate<=5
Or T.QualificationsNOTLIKE ‘D%’;
Aisling Fallon Higher Diploma in Computing
29
Question 6
Show the details of gadget repair not including “Remove virus”, “Service” and “DC Socket Repairs” where the
time taken is greater than or equal to 30mins, also showing the cost multiplied by 12 assuming each job is
performed on a monthly basis. Also show the time taken in ascending order.
Select Details,SUBSTR(Details, 1,3), Time_Taken, Cost*12
From Gadget_Repair
Where Time_Taken>=30
And Details NOT IN(‘Remove Virus’,‘Service’, ‘DC Socket Repairs’)
Order By Time_Taken ASC;
Select GR.Details,SUBSTR(GR.Details, 1,3), GR.Time_Taken, GR.Cost*12
From Gadget_Repair GR
Where GR.Time_Taken>=30
And GR.Details NOT IN(‘Remove Virus’,‘Service’, ‘DC Socket Repairs’)
Order By GR.Time_Taken ASC;
Aisling Fallon Higher Diploma in Computing
30
10. Joins
Question 1
(Parent Child Query involving 2 tables)
Show the firstname and qualification of the technicians and the cost and time taken for the associated
technicians of gadget repair.Show the technicians with and id of between 2000 and 2009 only, with their
address containing an “a” and the time taken in descending order.
Select Fname, Qualifications,Cost,Time_Taken, Address,Technician.Technician_Id
From Technician,Gadget_Repair
Where Technician.Technician_Id=Gadget_Repair.Technician_Id
And Address LIKE ‘%a%’
And Technician.Technician_Id BETWEEN 2000 AND 2009
Order By Time_Taken DESC;
Select Technician.Fname,Technician.Qualifications,Gadget_Repair.Cost, Gadget_Repair.Time_Taken,
Technician.Address,Technician.Technician_Id
From Technician,Gadget_Repair
Where Technician.Technician_Id=Gadget_Repair.Technician_Id
And Technician.Address LIKE‘%a%’
And Technician.Technician_Id BETWEEN 2000 AND 2009
Order By Gadget_Repair.Time_Taken DESC;
Aisling Fallon Higher Diploma in Computing
31
Question 2
(Parent Child Query involving 3 tables)
List the supplier’s name (in uppercase), annual turnover, specialism and year founded, also the cost price and
type of the gadgets they supply and the activity associated with the cafe users booking. Confine the output to
exclude any specialism beginning with the letter “S” and the year founded to exclude the years between 2002
and 2004.
Select UPPER(Supplier.Name), Annual_Turnover, Type, Cost_Price, Activity, Specialism,Year_Founded
From Supplier,Gadget, Cafe_User_Booking
Where Supplier.Supplier_Id=Gadget.Supplier_Id
And Gadget.Gadget_Id=Cafe_User_Booking.Gadget_Id
And SpecialismNOT LIKE ‘S%’
And Year_Founded NOT BETWEEN 2002 AND 2004;
Select UPPER(S.Name), S.Annual_Turnover, G.Type, G.Cost_Price, CUB.Activity, S.Specialism,
S.Year_Founded
From Supplier S, Gadget G, Cafe_User_Booking CUB
Where S.Supplier_Id=G.Supplier_Id
And G.Gadget_Id=CUB.Gadget_Id
And S.SpecialismNOTLIKE ‘S%’
And S.Year_Founded NOT BETWEEN 2002 AND 2004;
Aisling Fallon Higher Diploma in Computing
32
Question 3
(Parent Child Query involving all tables)
Using all tables show the year opened of each internet café after 2009, the counties of the café users and the
technicians in Cavan and Clare. Also show the annual turnover of the suppliers, the different types of gadgets,
the activity of the café user where the technician id is between 2000 and 2001. In the results sort the supplier’s
annual turnover starting with the lowest.
Select Internet_Cafe.Year_Opened, Cafe_User.County, Supplier.Annual_Turnover, Gadget.Type,
Cafe_User_Booking. Activity, Technician.County,Gadget_Repair.Technician_Id
From Internet_Cafe, Cafe_User, Supplier,Gadget, Cafe_User_Booking, Technician,Gadget_Repair
Where Internet_Cafe.Internet_Cafe_Id=Gadget. Internet_Cafe_Id
And Cafe_User.Cafe_User_Id=Cafe_User_Booking. Cafe_User_Id
And Supplier.Supplier_Id=Gadget.Supplier_Id
And Gadget.Gadget_Id=Cafe_User_Booking.Gadget_Id
And Technician.Technician_Id=Gadget_Repair.Technician_Id
And Technician.CountyIN(‘Cavan’,‘Clare’)
And Gadget_Repair.Technician_Id BETWEEN 2000 AND 2001
And Internet_Cafe.Year_Opened>2009
Order By Supplier.Annual_Turnover ASC;
Select IC.Year_Opened, CU.County, S.Annual_Turnover, G.Type, CUB. Activity, T.County, GR.Technician_Id
From Internet_Cafe IC, Cafe_User CU, Supplier S, Gadget G, Cafe_User_Booking CUB, Technician T,
Gadget_Repair GR
Where IC.Internet_Cafe_Id=G. Internet_Cafe_Id
And CU.Cafe_User_Id=CUB. Cafe_User_Id
And S.Supplier_Id=G.Supplier_Id
And G.Gadget_Id=CUB.Gadget_Id
And T.Technician_Id=GR.Technician_Id
And T.CountyIN(‘Cavan’, ‘Clare’)
And GR.Technician_Id BETWEEN 2000 AND 2001
And IC.Year_Opened>2009
Order By S.Annual_Turnover ASC;
Aisling Fallon Higher Diploma in Computing
33
Question 4
(An equijoin on two tables)
Show the first name and town of the cafe user and the name and country of the supplier where the length (in
letters) of the town is equal to the length (in letters) of the country. Confine the output to countries not in
Germany, Canada, Mexico or the United States. Give the first name uppercase and the suppliers name in lower
case.....
Select UPPER(Firstname), Cafe_User.Town, LOWER(Supplier.Name), Country
From Cafe_User, Supplier
Where Length(Cafe_User.Town)=Length(Country)
And Supplier.Country NOT IN (‘Germany’, ‘Canada’,‘Mexico’, ‘United States’);
Select UPPER(CU.Firstname), CU.Town, LOWER(S.Name), S.Country
From Cafe_User CU, Supplier S
Where Length(CU.Town)=Length(S.Country)
And S.Country NOT IN (‘Germany’, ‘Canada’,‘Mexico’, ‘United States’);
Aisling Fallon Higher Diploma in Computing
34
Question 5
(Non Equijoin between 2 tables)
List the names and year opened of the internet cafes in 2010 or after and the name of the suppliers and year
founded where the year opened of the internet cafe exceeds the year founded of the supplier. Also show the
difference in years between the year opened and year founded.
Select INITCAP(Internet_Cafe.Name),Year_Opened,INITCAP(Supplier.Name), Year_Founded, Year_Opened-
Year_Founded “Difference in Years”
From Internet_Cafe, Supplier
Where Year_Opened>Year_Founded
And Year_Opened>=2010;
Select IC.Name,IC.Year_Opened, INITCAP(S.Name), S. Year_Founded, IC.Year_Opened-S.Year_Founded
“Difference in Years”
From Internet_Cafe IC, Supplier S
Where IC.Year_Opened>S.Year_Founded
And IC.Year_Opened>=2010;
Aisling Fallon Higher Diploma in Computing
35
Question 6
(A Self join)
Show the name and screen sizes of the gadgets where the screen sizes are the same size. Show the screen size
(in inches) in ascending order.
Select G1.Name, G1.Screen_Size_Inches, G2.Name, G2.Screen_Size_Inches
From Gadget G1, Gadget G2
Where G1.Screen_Size_Inches= G2.Screen_Size_Inches
And G1.Gadget_Id<G2.Gadget_Id
Order By G1.Screen_Size_Inches ASC;
Aisling Fallon Higher Diploma in Computing
36
Question 7
(Outer Join)
Give the first names of the technicians and the associated cost for the gadget repair including technicians who
may not yet have had a gadget to repair. Sort the cost in descending order.
Select (Fname) “Firstname”, (Cost) “Total Cost”
From Technician,Gadget_Repair
Where Technician.Technician_Id=Gadget_Repair.Technician_Id(+)
Order byCost DESC;
Select (Technician.Fname) “Firstname”, (Gadget_Repair.Cost) “Total Cost”
From Technician,Gadget_Repair
Where Technician.Technician_Id=Gadget_Repair.Technician_Id(+)
Order byGadget_Repair.Cost DESC;
Aisling Fallon Higher Diploma in Computing
37
11. Summary Queries
Question 1
Find the maximum and minimum time taken for technicians in gadget repair and also the average cost, where
the details of repair contain an “e”.
Select Max(GR.Time_Taken), Min(GR.Time_Taken), Avg(GR.Cost)
From Gadget_Repair GR
Where Gr.DetailsLIKE’%e%’;
Question 2
Find the number of gadgets including the average hard disk size and the sum of the cost price for each one,
excluding the gadgets that end with the letter “n” and have a resale value between 300 and 500 euro.
Select Sum(G.Cost_Price), Avg(G.Hard_Disk_Size_Inches), Count(G.Gadget_Id)
From Gadget G
Where G.Resale_Value NOT BETWEEN 300 and 500
And G.Name NOT LIKE ‘%n’;
Aisling Fallon Higher Diploma in Computing
38
Question 3
Count the number of suppliers who have no email address.
Select Count(*)
From Supplier S
Where S.Web_Site IS NULL;
Question 4
Find the maximum and minimum rate per hour for the Internet Cafes which have no facilities.
Select Max(IC.Rate_Per_Hour), Min(IC.Rate_Per_Hour)
From Internet_Cafe IC
Where IC.Facilities IS NULL;
Aisling Fallon Higher Diploma in Computing
39
Question 5
Show the min and max annual turnover for suppliers and the difference between them, where the year founded
is less than or equal to 2008.
Select Max(S.Annual_Turnover) Highest , Min(S.Annual_Turnover) Lowest, Max(S.Annual_Turnover)-
Min(S.Annual_Turnover) Difference
From Supplier S
Where S.Year_Founded<=2008;
Question 6
Show the gadget types along with the max and min screen size for each type and the average ram size for each
of the types. Show the results in reverse alphabetical order by type and where the length of “type” (in letters) is
greater than 5.
Select G.Type, Max(G.Screen_Size_Inches) “Max Screen Size”, Min(G.Hard_Disk_Size_Inches) “Min Screen
Size”, Avg(G.Ram_Size)
From Gadget G
Where Length(G.Type)>5
Group By G.Type
Order By G.TypeDESC;
Aisling Fallon Higher Diploma in Computing
40
Question 7
List each technician name, the average time taken to do the job, the sum of the cost and the number of jobs
each technician had, where the time taken is greater than 100 minutes, arrange the names in alphabetical
order.
Select T.Fname,Avg(GR.Time_Taken), Sum(GR.Cost),Count(*)
From Technician T, Gadget_Repair GR
Where T.Technician_Id=GR.Technician_Id
And GR.Time_Taken>100
Group By T.Fname
Order By T.Fname ASC;
Question 8
Listthe activity types for the café user, showingalso the lateststarttime and the sum of the amount due for
each activity,where the amount due is greater than or equal to 10. Also sort the amount due in ascending
order.
Select CUB.Activity, (CUB.Start_Time)”Latest Time”, Sum(CUB.Amount_Due)
From Cafe_User_Booking CUB
Group By CUB.Activity
Having Sum(CUB.Amount_Due)>=10
Order By Sum(CUB.Amount_Due) ASC;
Aisling Fallon Higher Diploma in Computing
41
Question 9
Listthe names of the internet cafes in Cavan with an hourly rate of €5 or in Sligo with an hourly rate of €4, with
the year opened is between 2005 and 2008 in descending oreder……………
Select IC.Name, Sum(IC.Rate_Per_Hour), Sum(IC.Year_Opened)
From Internet_Cafe IC
Where (IC.County=’Cavan’ and IC.Rate_Per_Hour=5)
Or (IC.County=’Sligo’ and Rate_Per_Hour=4)
Group By IC.Name
Having Sum(IC.Year_Opened) BETWEEN 2005 and 2008
Order By Sum(IC.Year_Opened) DESC;
Aisling Fallon Higher Diploma in Computing
42
12. Subqueries
Question 1
Select the name of the gadgets with the highest cost price, where the resale value is between 450 and 600.
Select Name
From Gadget
Where Cost_PriceIN
(Select Max(Cost_Price)
From Gadget
Where Resale_ValueBETWEEN 450 AND 600);
Aisling Fallon Higher Diploma in Computing
43
Question 2
Name the suppliers who live in Germany and have an annual turnover less than the highest annual turnover of
a supplier in Canada and where the names do not end with an “l”.
Select Name, Annual_Turnover
From Supplier
Where Name NOT LIKE ‘%l’
And Country=’Germany’
And Annual_Turnover<
(Select Max(Annual_Turnover)
From Supplier
Where Country=’Canada’
And Name NOT LIKE ‘%l’);
Aisling Fallon Higher Diploma in Computing
44
Question 3
Name the technicians with Degrees who have an hourly rate greater than the average hourly rate for
technicians with no qualification.
Select T.FName
From Technician T
Where T.Qualifications=’Degree’
And T.Hourly_Rate>
(Select Avg(T.Hourly_Rate)
From Technician T
Where T.QualificationsIS NULL);
Aisling Fallon Higher Diploma in Computing
45
Question 4
Name the café users with an id between 10 and 25, who are unemployed and have the same nationality as
student café users.
Select Firstname, Nationality
From Cafe_User
Where Type=’Unemployed’
And Cafe_User_Id BETWEEN 10 and 25
And Nationality IN
(Select Nationality
From Cafe_User
Where Type=’Student’
And Cafe_User_Id BETWEEN 10 and 25);
Aisling Fallon Higher Diploma in Computing
46
Question 5
Show the name, town and facilities of an internet café who have PC as their gadgets and their name contains a
“u”.
Select Name, Town, Facilities
From Internet_Cafe
Where Name LIKE ‘%u%’
And Internet_Cafe .Internet_Cafe_IdIN(
Select Gadget.Internet_Cafe_Id
From Gadget
Where Type=’PC’);
Aisling Fallon Higher Diploma in Computing
47
Question 6
Show the name, town and facilities of an internet café who do not have PC as their gadgets and contain the
letter “u” in their name.
Select Name, Town, Facilities
From Internet_Cafe
Where Name LIKE ‘%u%’
And Internet_Cafe .Internet_Cafe_Id NOT IN(
Select Gadget.Internet_Cafe_Id
From Gadget
Where Type=’PC’);
Aisling Fallon Higher Diploma in Computing
48
Question 7
List the names and year founded of the suppliers of gadgets with an annual turnover less than 65000 and
where the length of the café user booking activity associated to the gadget is the same as the length of the
payment method(in letters).
Select Supplier.Name, Supplier.Year_Founded
From Supplier
Where Annual_Turnover< 65000
And Supplier.Supplier_IdIN(
Select Gadget.Supplier_Id
From Gadget
Where Gadget.Gadget_IdIN(
Select Cafe_User_Booking.Gadget_Id
From Cafe_User_Booking
Where
Length(Cafe_User_Booking.Activity)=Length(Caf
e_User_Booking.Payment_Method)));
Aisling Fallon Higher Diploma in Computing
49
Question 8
List the café user activity where the length of the café user booking activity is the same as the length of the
payment method(in letters)…..and where the annual turnover is less than 65000 for supplier….
Select Activity
From Cafe_User_Booking
Where Length(Cafe_User_Booking.Activity)=Length(Cafe_User_Booking.Payment_Method)
And Cafe_User_Booking.Gadget_IdIN(
Select Gadget.Gadget_Id
From Gadget
Where Gadget.Supplier_IdIN(
Select Supplier.Supplier_Id
From Supplier
Where Annual_Turnover< 65000));
Aisling Fallon Higher Diploma in Computing
50
Question 9
Show the name and year opened of internet cafes where the year opened is after 2003, the cost price of the gadget
associated to the café is greater than 300, where the café user booking activity is email, internet or access, the nationality
of the café user is French or Irish, the annual turnover is greater than 50000 for the supplier of the internet café, the tim e
taken for the gadget repair is greater than 25 minutes and the technician from either Cavan, Clare or Roscommon.
Select Internet_Cafe.Year_Opened, Internet_Cafe.Name
From Internet_Cafe
Where Internet_Cafe.Year_Opened>2003
And Internet_Cafe.Internet_Cafe_IdIN(
Select Gadget.Internet_Cafe_Id
From Gadget
Where Gadget.Cost_Price>300
And Gadget.Gadget_IdIN(
Select Cafe_User_Booking. Gadget_Id
From Cafe_User_Booking
Where Cafe_User_Booking. ActivityIN(‘Email’,’Internet’, ‘Access’)
And Cafe_User_Booking.Cafe_User_IdIN(
Select Cafe_User.Cafe_User_Id
From Cafe_User
Where Cafe_User.NationalityIn(‘Irish’, ‘French’)
And Gadget.Supplier_IdIN(
Select Supplier.Supplier_Id
From Supplier
Where Supplier.Annual_Turnover>50000
And Gadget.Gadget_IdIN(
Select Gadget_Repair.Gadget_Id
From Gadget_Repair
Where Gadget_Repair.Time_Taken>15
AndGadget_Repair.Technician_IdIN(
Select Technician.Technician_Id
From Technician
Where Technician.CountyIN(‘Cavan’, ‘Clare’,
‘Roscommon’)))))));
Aisling Fallon Higher Diploma in Computing
51
Select DISTINCT Internet_Cafe.Year_Opened, Internet_Cafe.Name
From Internet_Cafe, Gadget, Cafe_User_Booking, Cafe_User, Supplier, Gadget_Repair, Technician
Where Internet_Cafe.Internet_Cafe_Id=Gadget.Internet_Cafe_Id
And Gadget.Gadget_Id=Cafe_User_Booking. Gadget_Id
And Cafe_User_Booking.Cafe_User_Id=Cafe_User.Cafe_User_Id
And Gadget.Supplier_Id=Supplier.Supplier_Id
And Gadget.Gadget_Id=Gadget_Repair.Gadget_Id
And Gadget_Repair.Technician_Id=Technician.Technician_Id
And Internet_Cafe.Year_Opened>2003
And Gadget.Cost_Price>300
And Cafe_User_Booking. Activity IN(‘Email’,’Internet’, ‘Access’)
And Cafe_User.NationalityIn(‘Irish’, ‘French’)
And Supplier.Annual_Turnover>50000
And Gadget_Repair.Time_Taken>15
And Technician.CountyIN(‘Cavan’,‘Clare’, ‘Roscommon’);
Aisling Fallon Higher Diploma in Computing
52
Question 10
List the technician’s first name and surname where the cost of their gadget repair is not greater than €15.
Select T.Fname, T.Sname
From Technician T
Where T.Technician_Id NOT IN(
Select GR.Technician_Id
From Gadget_Repair GR
Where GR.Cost>15);
Aisling Fallon Higher Diploma in Computing
53
Question 11
List the names of the suppliers(at least one) who supply laptops who have an annual turnover greater than the
supplier of netbooks.
Select S.Name, S.Annual_Turnover
From Supplier S, Gadget G
Where S.Supplier_Id=G.Supplier_Id
And G.Type=’Laptop’
And S.Annual_Turnover>ANY
(Select S.Annual_Turnover
From Supplier S, Gadget G
Where S.Supplier_Id=G.Supplier_Id
And G.Type=’Netbook’);
Aisling Fallon Higher Diploma in Computing
54
Question 12
Name all the technicians from Cavan that spend less time doing gadget repairs compared to all the technicians
who come from Roscommon.
Select T.Fname
From Technician T, Gadget_Repair GR
Where T.Technician_Id=GR.Technician_Id
And T.County=’Cavan’
And Gr.Time_Taken<ALL
(Select Gr.Time_Taken
From Technician T, Gadget_Repair GR
Where T.Technician_Id = GR.Technician_Id
And T.County=’Roscommon’);
Aisling Fallon Higher Diploma in Computing
55
13. Inserts, Updates and Deletes
Question 1
Failed delete due to integrity constraint.
Delete
From Technician
Where Technician_Id=2001;
Aisling Fallon Higher Diploma in Computing
56
Question 2
Remove the cafe users who use credit card as a payment method
Delete
From Cafe_User
Where Cafe_User.Cafe_User_IdIN(
Select Cafe_User_Booking.Cafe_User_Id
From Cafe_User_Booking
Where Payment_Method=’Credit Card’);
Remove the café users from Cavan as they no longer make a booking.
Select Activity
From Cafe_User_Booking
Where Cafe_User_Booking.Cafe_User_IdIN(
Select Cafe_User. Cafe_User_Id
From Cafe_User
Where County=’Cavan’);
Delete
From Cafe_User_Booking
Where Cafe_User_Booking.Cafe_User_IdIN(
Select Cafe_User. Cafe_User_Id
From Cafe_User
Where County=’Cavan’);
Aisling Fallon Higher Diploma in Computing
57
Rollback;
Aisling Fallon Higher Diploma in Computing
58
Question 3
Café Users who are assigned to gadgets where their suppliers have an annual turnover less than 58000 should
be removed.
Select Activity
From Cafe_User_Booking
Where Cafe_User_Booking.Gadget_IdIN(
Select Gadget. Gadget_Id
From Gadget
Where Gadget.Supplier_IdIN(
Select Supplier.Supplier_Id
From Supplier
Where Annual_Turnover< 58000));
Delete
From Cafe_User_Booking
Where Cafe_User_Booking.Gadget_IdIN(
Select Gadget. Gadget_Id
From Gadget
Where Gadget.Supplier_IdIN(
Select Supplier.Supplier_Id
From Supplier
Where Annual_Turnover< 58000));
Rollback;
Aisling Fallon Higher Diploma in Computing
59
Question 4
Delete the internet cafes who do not have PCs as their gadget types and contain the letter “u” in their name
(ON DELETE CASCADE).
Select Name, Town, Facilities
From Internet_Cafe
Where Name LIKE ‘%u%’
And Internet_Cafe .Internet_Cafe_Id NOT IN
(Select Gadget.Internet_Cafe_Id
From Gadget
Where Type=’PC’);
Delete
From Internet_Cafe
Where Name LIKE ‘%u%’
And Internet_Cafe .Internet_Cafe_Id NOT IN
(Select Gadget.Internet_Cafe_Id
From Gadget
Where Type=’PC’);
Rollback;
Aisling Fallon Higher Diploma in Computing
60
Question 5
Insert involving columns in random order.
Insertinto Gadget_Repair(Repair_Date, Gadget_Id, Details,Time_Taken, Technician_Id,Cost)Values( ‘01-Dec-
11’, 2007, ‘Repair’, 112,2002,50);
Question 6
Insert involving NULL.
Insertinto Supplier(Annual_Turnover,Name, Country, Web_Site, Address, Year_Founded, Specialism,
Supplier_Id)Values(60000,‘Techo’, ‘Ireland’,‘www.techo.com’, ‘Dublin’, NULL, ‘Servers’, 84);
Aisling Fallon Higher Diploma in Computing
61
Question 7
Insert attempting to violate a foreign key.
Insertinto Gadget(Gadget_Id, Hard_Disk_Size_Inches,RAM_Size, Screen_Size_Inches, Cost_Price,
Expected_Life, Date_Purchased, Sound_Card, Video_Card, Name, Type, Operating_System, Supplier_Id,
Internet_Cafe_Id, Resale_Value)Values (2500,3.5, 3, 17.5, 650,38, '13-Nov-10', 'Yes','No', 'Acer', ‘Laptop’,
‘Vista’, 53,200,650);
Insertinto Gadget(Gadget_Id, Hard_Disk_Size_Inches,RAM_Size, Screen_Size_Inches, Cost_Price,
Expected_Life, Date_Purchased, Sound_Card, Video_Card, Name, Type, Operating_System, Supplier_Id,
Internet_Cafe_Id, Resale_Value )Values (2500,3.5, 3, 17.5, 650,38, '13-Nov-10', 'Yes', 'No', 'Acer', ‘Laptop’,
‘Vista’, 53,104,650);
Rollback;
Aisling Fallon Higher Diploma in Computing
62
Question 8
Show the details and costfor gadget repair for technician 2006 and then attempt to update to 2020,then
successfully updateto 2007….
Select Details,Cost
From Gadget_Repair
Where Technician_Id=2006;
Update Gadget_Repair
Set Technician_Id=2020
Where Technician_Id=2006;
Update Gadget_Repair
Set Technician_Id=2007
Where Technician_Id=2006;
Rollback;
Aisling Fallon Higher Diploma in Computing
63
Question 9
Attempt to update a primary key for a parent that has children.
Select Name, Address
From Supplier
Where Supplier_Id=55;
Update Supplier
Set Supplier_Id=56
Where Supplier_Id=55;
Aisling Fallon Higher Diploma in Computing
64
Question 10
On Delete Cascade feature for all foreign keys
Delete
From Cafe_User_Booking
Where Cafe_User_Booking.Gadget_IdIN(
Select Gadget. Gadget_Id
From Gadget
Where Gadget.Supplier_IdIN(
Select Supplier.Supplier_Id
From Supplier
Where Annual_Turnover< 58000
Select Count(*)
From Cafe_User_Booking;
Select Count(*)
From Gadget;
Aisling Fallon Higher Diploma in Computing
65
Select Count(*)
From Supplier;
Select Count(*)
From Cafe_User_Booking
Where Gadget_Id=1000;
Select Count(*)
From Gadget
Where Gadget_Id=1000;
Aisling Fallon Higher Diploma in Computing
66
Select Count(*)
From Supplier
Where Supplier.Supplier_IdIN(
Select Gadget.Supplier_Id
From Gadget
Where Gadget_Id=1000);
Delete From Cafe_User_Booking
Where Gadget_Id=1000;
Aisling Fallon Higher Diploma in Computing
67
Delete
From Gadget
Where Gadget_Id=1000;
Delete
From Supplier
Where Supplier.Supplier_IdIN(
Select Gadget.Supplier_Id
From Gadget
Where Gadget_Id=1000);
Aisling Fallon Higher Diploma in Computing
68
Rollback;
Aisling Fallon Higher Diploma in Computing
69
14. Views
Question 1
Create a vertical view to show the name, address, country, specialism and annual turnover for the supplier of
laptops.
Drop View Supplier_Laptops;
Create View Supplier_Laptops As
Select Name, Address,Country, Specialism,Annual_Turnover
From Supplier;
Select Name, Country, Address, Specialism,Annual_Turnover
From Supplier_Laptops;
Aisling Fallon Higher Diploma in Computing
70
Question 2
Create a horizontal view using all columns in the supplier table.
Drop View Supplier_Laptops;
Create View Supplier_Laptops(Supplier_Id,Name, Address,Country, Web_Site, Year_Founded,
Specialism,Annual_Turnover,Monthly_Wage)As
Select Supplier_Id,Name, Address,Country, Web_Site, Year_Founded, Specialism,Annual_Turnover,
Annual_Turnover/12
From Supplier
Where Specialism=’Laptops’
And Year_Founded<2005;
Select *
From Supplier_Laptops;
Aisling Fallon Higher Diploma in Computing
71
Question 3
Create a view based on a join of at least three tables.
Drop View Supplier_Gadget_Cafe_User_Book; As
Create View Supplier_Gadget_Cafe_User_Book As
Select Supplier.Name, Supplier.Country,Gadget.Type, Gadget.Cost_Price, Cafe_User_Booking.Amount_Due,
Cafe_User_Booking.Activity, Cafe_User_Booking.Payment_Method
From Supplier,Gadget, Cafe_User_Booking
Where Supplier.Supplier_Id=Gadget.Supplier_Id
And Gadget.Gadget_Id=Cafe_User_Booking.Gadget_Id;
Select *
From Supplier_Gadget_Cafe_User_Book;
Select Supplier.Name, Gadget.Type, Cafe_User_Booking.Activity
From Supplier_Gadget_ Cafe_User_Booking;
Aisling Fallon Higher Diploma in Computing
72
Question 4
Create a view based on a summary query.
Drop View Gadget_Repair_Time_Cost;
Create View Gadget_Repair_Time_Cost As
Select Details,Max(Time_Taken) Max_Time, Min(Time_Taken)Min_Time, Avg(Cost) Avg_Cost
From Gadget_Repair GR
Group By Details;
DescribeGadget_Repair_Time_Cost;
Select *
From Gadget_Repair_Time_Cost;
Aisling Fallon Higher Diploma in Computing
73
Question 5
Create a view based on a singletablethat doesn’t have a WITH CHECK OPTION clause and attempt an insert
and update.
Drop View Internet_Cafe_Opened_County;
Create View Internet_Cafe_Opened_County As
Select Internet_Cafe_Id, Name,Year_Opened, County, Rate_Per_Hour, Facilities
From Internet_Cafe
Where Year_Opened >2005
And Name LIKE ‘%n%’
And County IN(’Roscommon’,’Clare’);
Select Count(*)
From Internet_Cafe_Opened_County;
Select *
From Internet_Cafe_Opened_County;
Insertinto Internet_Cafe_Opened_County(Internet_Cafe_Id, Name,Year_Opened, County, Rate_Per_Hour,
Facilities)
Values(259,‘Techet’, 2003, ‘Sligo’,4, ‘Drinks’);
Aisling Fallon Higher Diploma in Computing
74
Insertinto Internet_Cafe_Opened_County(Internet_Cafe_Id, Name,Year_Opened, County, Rate_Per_Hour,
Facilities)
Values(256,‘Cruising’,2007,‘Roscommon’, 4, ‘Drinks’);
Select Count(*)
From Internet_Cafe_Opened_County;
Select *
From Internet_Cafe_Opened_County;
UPDATE
Update Internet_Cafe_Opened_County
Set County=’Galway’
Where County=’Roscommon’;
Aisling Fallon Higher Diploma in Computing
75
Update Internet_Cafe_Opened_County
Set Name=’Techno’
Where Name= ‘Gamestation Cafe’;
In this view all the inserts and updates succeeded even though some of them did not meet the conditions
outlined, this was because the view did not contain a with check option
Aisling Fallon Higher Diploma in Computing
76
Question 6
Create the same view but include a WITH CHECK OPTION for an insert, update and delete.
Drop View Internet_Cafe_Opened_County;
Create View Internet_Cafe_Opened_County As
Select Internet_Cafe_Id, Name,Year_Opened, County, Rate_Per_Hour, Facilities
From Internet_Cafe
Where Year_Opened >2005
And Name LIKE ‘%n%’
And County IN(’Roscommon’,’Clare’)
With Check Option;
Insertinto Internet_Cafe_Opened_County(Internet_Cafe_Id, Name,Year_Opened, County, Rate_Per_Hour,
Facilities)
Values(259,‘Techet’, 2003, ‘Sligo’,‘4’, ‘Drinks’);
Insertinto Internet_Cafe_Opened_County(Internet_Cafe_Id, Name,Year_Opened, County, Rate_Per_Hour,
Facilities)
Values(256,‘Cruising’,2007,‘Roscommon’, 4, ‘Drinks’);
Aisling Fallon Higher Diploma in Computing
77
Select Count(*)
From Internet_Cafe_Opened_County;
Select *
From Internet_Cafe_Opened_County;
UPDATE
Update Internet_Cafe_Opened_County
Set County=’Galway’
Where County=’Roscommon’;
Update Internet_Cafe_Opened_County
Set Name=’Techno’
Where Name= ‘Gamestation Cafe’;
Aisling Fallon Higher Diploma in Computing
78
DELETE
Delete
From Internet_Cafe_Opened_County
Where Internet_Cafe_Id=103;
Delete
From Internet_Cafe_Opened_County
Where County=’Roscommon’;
The insert that doesn’t comply with the where clause restriction will fail due to the with check option(where-
clause violation) The insert which should comply will simply be inserted. The same can be said for the
updates….the first one which did not meet the conditions failed due to the check option again, however the
one which met the conditions in the view updated without any problem.
Aisling Fallon Higher Diploma in Computing
79
Question 7
Attempt an invalid insert into a view containing a WITH CHECK OPTION clause, demonstrating when it succeeds
and fails.
Drop View Supplier_Canada;
Create View Supplier_Canada As
Select Supplier_Id,Annual_Turnover, Name, Country, Web_Site, Address, Year_Founded, Specialism
From Supplier
Where Country=’Canada’
With Check Option;
Select *
From Supplier_Canada;
Insertinto Supplier_Canada(Supplier_Id,Annual_Turnover,Name, Country, Web_Site, Address, Year_Founded,
Specialism)Values(84,60000,‘Techo’, ‘Canada’,‘www.techo.com’, ‘Dublin’, 2006,‘Servers’);
Insertinto Supplier_Canada(Supplier_Id,Annual_Turnover,Name, Country, Web_Site, Address, Year_Founded,
Specialism)Values(50,60000,‘Techo’, ‘Ireland’,‘www.techo.com’, ‘Dublin’, 2006,‘Servers’);
Aisling Fallon Higher Diploma in Computing
80
Question 8
Attempt an invalid update into a view containing a WITH CHECK OPTION clause, also showing the update when
it succeeds.
Drop View Gadget_Repair_Details;
Create View Gadget_Repair_Details As
Select Details,Cost, Technician_Id
From Gadget_Repair
Where Cost<50
And Details LIKE’%n%’
WITH CHECK OPTION;
Select *
From Gadget_Repair_Details;
Update Gadget_Repair_Details
Set Details=’Repair’
Where Technician_Id=2003;
Update Gadget_Repair_Details
Set Details=’Re-install’
Where Technician_Id=2003;
Aisling Fallon Higher Diploma in Computing
81
Alter Tables
Question 1
(Adding a column to a table)
Alter TableGadget
Add Region Varchar2(12);
Alter TableGadget
DROP Column Region;
Question 2
(Add a column with check constraint)
Alter TableGadget
Add ConstraintGadget_Region_CK Check (Region In(‘NORTH’, ‘SOUTH’,’EAST’));
Aisling Fallon Higher Diploma in Computing
82
Question 3
(Increasewidth of existingcolumn)
Alter TableGadget
Modify Region Varchar2(12);
Question 4
(Remove a column from a table)
DROP Column Region;
Aisling Fallon Higher Diploma in Computing
83
Question 5
(Drop a Pk constraintbut you need to drop Fk constraintfirst)
Alter TableGadget
Drop ConstraintGad_Supplier_Id_FK;
Alter TableSupplier
Drop ConstraintSupplier_Supplier_Id_PK;
Question 6
(Add the pk constraintyou justdropped)
Alter TableSupplier
Add ConstraintSupplier_Supplier_Id_PK Primary Key(Supplier_Id);
Alter TableGadget
Add ConstraintGad_Supplier_Id_FK Foreign Key(Supplier_Id) References Supplier(Supplier_Id);
Aisling Fallon Higher Diploma in Computing
84
Question 7
(Drop a Fk Constraint)
Alter TableGadget
Drop ConstraintGad_Supplier_Id_FK;
Question 8
(Disableand enablea foreign key constraint)
Alter TableGadget
DisableConstraintGad_Supplier_Id_FK;
Aisling Fallon Higher Diploma in Computing
85
14. Security
Question 1
(Grant select, update and delete to two students).
Grant select on Supplier to student145, student142;
Grant inserton Supplier to student145, student142;
Grant update on Supplier to student145, student142;
Question 2
(Grant permission on select to public)
Grant select on Gadget to Public;
Aisling Fallon Higher Diploma in Computing
86
Question 3
(Grant two conditions to one student)
Grant select, update on Gadget_Repair to student145;
Question 4
(Grant select with permission for the privileges to be passed on)
Grant select on Internet_Cafe to student142 with grantoption;
Question 5
(Grant a student select and insert to a view)
Grant select, inserton Supplier_Laptops to student142;
Aisling Fallon Higher Diploma in Computing
87
Question 6
(Grant an update and delete on a view to two students)
Grant update, delete on Supplier_Laptops to student142, student145;
Question 7
(Revoke privileges from one of the students)
Revoke select, update on Gadget_Repair from student145;
Question 8
(Revoke privileges from the other students)
Revoke select, inserton Supplier_Laptops from student142;
Aisling Fallon Higher Diploma in Computing
88
14. Transaction Processing
Time Session1 (client1) Session2 (client2) Observations
T1 Select Sum(Cost)
From Gadget_Repair;
Select Sum(Cost)
From Gadget_Repair;
Both Client1 and Client2 can see the the
result-Sum(Cost)
T2 Update Gadget_Repair
Set Cost=Cost +10
Where Technician_Id=2002;
Client1 has updated rows in the Gadget
Repair table, no other clientcan update
these rows until client1 completes the
transcation
Aisling Fallon Higher Diploma in Computing
89
T3 Select Sum(Cost)
From Gadget_Repair;
Select Sum(Cost)
From Gadget_Repair;
Here you can see Client1 update rows
on the Gadget Repair table. Client 2 has
not yet been updated.
T4 Update Gadget_Repair
Set Cost=Cost +10
Where
Technician_Id=2002;
Here you can see Client2 is blocked as
the rows arelocked by Client1
T5 Select Sum(Cost)
From Gadget_Repair;
Select Sum(Cost)
From Gadget_Repair;
T6 Rollback; Now client2 update will be processed as
the transaction is completed by client1
due to the rollback.Now Client1
updates arereversed whileclient2 is
now updated.
Aisling Fallon Higher Diploma in Computing
90
T7 Select Sum(Cost)
From Gadget_Repair;
Select Sum(Cost)
From Gadget_Repair;
Client1 will nowsees the original while
client2 will seethe updates.
T8 Rollback;
T9 Select Sum(Cost)
From Gadget_Repair;
Select Sum(Cost)
From Gadget_Repair;
Now client1 and client2 will both have
the same amount for Sum(Cost)
Aisling Fallon Higher Diploma in Computing
91
TIME SESSION1 (CLIENT1) SESSION2
(CLIENT2)
SESSION3
(CLIENT3)
OBSERVATIONS
T1 Select Sum(Cost)
From
Gadget_Repair;
Select Sum(Cost)
From
Gadget_Repair;
Select Sum(Cost)
From
Gadget_Repair;
All clients will seethis result
T2 Update
Gadget_Repair
Set Cost=Cost +10
Where
Technician_Id=200
2;
Aisling Fallon Higher Diploma in Computing
92
T3 Select Sum(Cost)
From
Gadget_Repair;
Select Sum(Cost)
From
Gadget_Repair;
Select Sum(Cost)
From
Gadget_Repair;
This will haveclientone with the
new update figureand client2
and 3 with the original figure
T4 Update
Gadget_Repair
Set Cost=Cost
+10
Where
Technician_Id=20
02;
This will notupdate as client1
updates arenot processed this
will stay in waitingmode until
client1 rollbacksor commits.
Aisling Fallon Higher Diploma in Computing
93
T5 Select Sum(Cost)
From
Gadget_Repair;
Select Sum(Cost)
From
Gadget_Repair;
Select Sum(Cost)
From
Gadget_Repair;
T6 Update
Gadget_Repair
Set Cost=Cost +10
Where
Technician_Id=20
02;
Aisling Fallon Higher Diploma in Computing
94
T7 Select Sum(Cost)
From
Gadget_Repair;
Select Sum(Cost)
From
Gadget_Repair;
Client2 and Client3 will notupdate
as Client1 has not been commited
or rollback.
T8 Rollback; Rollback; Rollback;
Aisling Fallon Higher Diploma in Computing
95
T9 Select Sum(Cost)
From
Gadget_Repair;
Select Sum(Cost)
From
Gadget_Repair;
Select Sum(Cost)
From
Gadget_Repair;
The updates have been rolled
back so now the 3 clients havethe
same figure.
T10 Update
Gadget_Repair
Set Cost=Cost +10
Where
Technician_Id=200
2;
Aisling Fallon Higher Diploma in Computing
96
T11 Select Sum(Cost)
From
Gadget_Repair;
Select Sum(Cost)
From
Gadget_Repair;
Select Sum(Cost)
From
Gadget_Repair;
T12 Update
Gadget_Repair
Set Cost=Cost
+10
Where
Technician_Id=20
02;
T13 Select Sum(Cost)
From
Gadget_Repair;
Select Sum(Cost)
From
Gadget_Repair;
Select Sum(Cost)
From
Gadget_Repair;
Aisling Fallon Higher Diploma in Computing
97
T14 Commit;
T15 Select Sum(Cost)
From
Gadget_Repair;
Select Sum(Cost)
From
Gadget_Repair;
Select Sum(Cost)
From
Gadget_Repair;
When itis commited atclient1 the
update then runs for client2.
T16 Commit;
Aisling Fallon Higher Diploma in Computing
98
T17 Select Sum(Cost)
From
Gadget_Repair;
Select Sum(Cost)
From
Gadget_Repair;
Select Sum(Cost)
From
Gadget_Repair;
Client1 and Client2 have
commited so therefore updates
will occur for all threeclients.
Aisling Fallon Higher Diploma in Computing
99

More Related Content

Similar to SQL Project

project
projectproject
project
craig smith
 
DB 3 Sybase ASE 15 & MS SQL Server
DB 3 Sybase ASE 15 & MS SQL Server DB 3 Sybase ASE 15 & MS SQL Server
DB 3 Sybase ASE 15 & MS SQL Server
Sunny U Okoro
 
Advanced SQLCharles WilliamsCS352 Unit 4 IPProfessor Jeffe.docx
Advanced SQLCharles WilliamsCS352 Unit 4 IPProfessor Jeffe.docxAdvanced SQLCharles WilliamsCS352 Unit 4 IPProfessor Jeffe.docx
Advanced SQLCharles WilliamsCS352 Unit 4 IPProfessor Jeffe.docx
coubroughcosta
 
Jash mehta ist 659 final project report
Jash mehta ist 659 final project reportJash mehta ist 659 final project report
Jash mehta ist 659 final project report
Jash Mehta
 
Rich relational data from thin air john stinson
Rich relational data from thin air   john stinsonRich relational data from thin air   john stinson
Rich relational data from thin air john stinson
John Stinson
 
project Presentation1
project Presentation1project Presentation1
project Presentation1
Shefali Raj
 
Implementing Server Side Data Synchronization for Mobile Apps
Implementing Server Side Data Synchronization for Mobile AppsImplementing Server Side Data Synchronization for Mobile Apps
Implementing Server Side Data Synchronization for Mobile Apps
Michele Orselli
 

Similar to SQL Project (7)

project
projectproject
project
 
DB 3 Sybase ASE 15 & MS SQL Server
DB 3 Sybase ASE 15 & MS SQL Server DB 3 Sybase ASE 15 & MS SQL Server
DB 3 Sybase ASE 15 & MS SQL Server
 
Advanced SQLCharles WilliamsCS352 Unit 4 IPProfessor Jeffe.docx
Advanced SQLCharles WilliamsCS352 Unit 4 IPProfessor Jeffe.docxAdvanced SQLCharles WilliamsCS352 Unit 4 IPProfessor Jeffe.docx
Advanced SQLCharles WilliamsCS352 Unit 4 IPProfessor Jeffe.docx
 
Jash mehta ist 659 final project report
Jash mehta ist 659 final project reportJash mehta ist 659 final project report
Jash mehta ist 659 final project report
 
Rich relational data from thin air john stinson
Rich relational data from thin air   john stinsonRich relational data from thin air   john stinson
Rich relational data from thin air john stinson
 
project Presentation1
project Presentation1project Presentation1
project Presentation1
 
Implementing Server Side Data Synchronization for Mobile Apps
Implementing Server Side Data Synchronization for Mobile AppsImplementing Server Side Data Synchronization for Mobile Apps
Implementing Server Side Data Synchronization for Mobile Apps
 

SQL Project

  • 1. Aisling Fallon Higher Diploma in Computing 1 Oracle SQL-Noel Tierney Higher Diploma in Computing 2013/2014 Internet Cafe Users 2014 AislingFallon A00203593 1/13/2014
  • 2. Aisling Fallon Higher Diploma in Computing 1 Table of Contents Page No. 1. Introduction………..............................................……. 2 2. Data…………………………………………………………………….. 3 3. Identifying Primary and Foreign Keys………………… 4 4. ERD Entity Relationship Diagram………………………… 5 5. Extended ERD……………………………………………………… 6 6. Create Table Statements………………………………………. 7-10 7. Insert Statements………………………………………………… 11-20 8. Tables………………………………………………………………….. 21-23 9. Single Table Queries…………………………………………….. 24-29 10. Joins……………………………………………………………………. 30-36 11. Summary Queries………………………………………………… 37-41 12. Subqueries…………………………………………………………… 42-54 13. Inserts, Updates and Deletes………………………………… 55-68 14. Views……………………………………………………………………. 69-80 15. Alter Tables…………………………………………………………. 81-84 16. Security……………………………………………………………….. 85-87 17. Transaction Processing…………………………………………… 88-98
  • 3. Aisling Fallon Higher Diploma in Computing 2 1. Introduction This projectinvolved the use of oracleSQL. A set of tables and columns for an Internet Cafe User had to be examined in order to identify the various linksbetween the tables and to establish theprimary and foreign keys. An Entity Relationship Diagrams could then be created to show clearly the directlinks between the tables. When this was complete data was populated in the various columns of each table, then usingcreate table statements and insertstatements the data was inserted into OracleSQL. This allowed for the followingto be achieved usingselectstatements: -DML(Data Manipulation Language)-Inserts,Updates,Deletes -DDL(Data Description Language)-Create, Alter, Drop -DCL(Data Control Language)-Grant Revoke
  • 4. Aisling Fallon Higher Diploma in Computing 3 2. Data Internet Café Users ICU Aisling Fallon Internet Café Users ICU HDC Sep 2013 Organisation thatoperates a number of internet cafes around the country. Each cafe has a number of computers and other gadgets (Ipads,laptops,tablets etc). Users details arestored and each time that a user wants to avail of a computer a booking (café_user_booking) holds information aboutthe computer used, who used itand for how long, as well as the amount charged to the customer. When computers break down or need maintenance, one of the technicians employed by the organisation repairsthecomputer. Internet_Café (Internet_Café_Id, Name, Address, Town, County, Web_Site, Email,Year_Opened, Rate_Per_Hour, Facilities (Drinks, Snacks, Sandwiches) (Note the opening and closing times are to be stored as numbers and will be whole numbers between 1 and 24 ie the 24 hour clock) Café_User (Café_User_Id, Firstname, Lastname, Address, Town, County, Gender, Date_Of_Birth, Nationality, Mobile_No, Email,Type (Student, Retired, Working, Unemployed), User_Level (Novice, Intermediate, Expert) Gadget (Gadget_ID, Name, Type (Laptop, PC, Tablet etc,), Screen_Size, Hard_Disk_Size, RAM_Size, Operating_System (eg Windows 2000,Linux, Vista etc), Video_Card (Yes, No), Sound_Card (Yes/No), Date_Purchased, Cost_Price, Expected_Life (express in months), Resale_Value,Internet_Café_Id, Supplier_ID,) Café_User_Booking( Café_User_ID, Gadget_Id,Date_Booked, Start_Time, End_Time, Amount_Due, Activity (Email, Internet, Word Processing, Excel, Access, Other), Payment_Method (Cash, Credit Card, Laser Card) Supplier (Supplier_Id,Name, Address, Country, Web_Site, Year_Founded, Specialism(PCs,Laptops, Peripherals, Servers),Annual_Turnover) Gadget_Repair(Gadget_Id, Repair_Date, Details,Cost, Time_Taken, (express in minutes), Technician_Id) Technician (Technician_Id,FName, Sname, Address, Town, County, Qualifications(Certificate, Degree, MSc), Expertise (Hardware, Software, Networks), Hourly_Rate, Date_Hired, Mobile_No)
  • 5. Aisling Fallon Higher Diploma in Computing 4 3. Identifying Primary and Foreign Keys Internet_Café PK-Internet_Café_Id, Name, Address, Town, County, Web_Site, Email,Year_Opened, Rate_Per_Hour, Facilities Café_UserPK-Café_User_Id, Firstname,Lastname, Address, Town, County, Gender, Date_Of_Birth, Nationality, Mobile_No, Email,Type ,User_Level Supplier PK- Supplier_Id, Name, Address, Country, Web_Site, Year_Founded, Specialism,Annual_Turnover Gadget Pk-Gadget_ID, Name, Type Screen_Size, Hard_Disk_Size, RAM_Size, Operating_System,Video_Card,Sound_Card,Date_Purchased, Cost_Price, Expected_Life,Resale_Value, FK- Internet_Café_Id, FK- Supplier_ID Café_User_BookingFk- Café_User_ID,FK- Gadget_Id,Date_Booked, Start_Time, End_Time, Amount_Due, Activity, Payment_Method Technician Pk- Technician_Id,FName, Sname, Address, Town, County, Qualifications,Expertise,Hourly_Rate, Date_Hired, Mobile_No Gadget_RepairPk-Gadget_Id, Repair_Date, Details,Cost, Time_TakenFK-Technician_Id
  • 6. Aisling Fallon Higher Diploma in Computing 5 4. ERD-Entity Relationship Diagram
  • 7. Aisling Fallon Higher Diploma in Computing 6 5. Extended ERD
  • 8. Aisling Fallon Higher Diploma in Computing 7 6. Create Table Statements drop table Internet_Cafe ; create table Internet_Cafe ( Internet_Cafe_Id Number ( 3 ) , Name Varchar2 ( 19 ) , Address Varchar2 ( 15 ) , Town Varchar2 ( 14 ) , County Varchar2 ( 9 ) , Web_Site Varchar2 ( 19 ) , Email Varchar2 ( 24 ) , Year_Opened Number ( 4 ) , Rate_Per_Hour Number ( 1 ) ConstraintIntC_Rate_Per_Hour_NN NOT NULL, Facilities Varchar2 ( 11 ) , Constraint IntC_IntCId_PK Primary Key(Internet_Cafe_Id), Constraint IntC_County_Ck Check(County In('Cavan', 'Clare', 'Cork', 'Sligo', 'Roscommon')), Constraint IntC_Name_Uq Unique(Name)); drop table Cafe_User ; create table Cafe_User ( Cafe_User_Id Number ( 2 ) , Firstname Varchar2 ( 7 ) , Lastname Varchar2 ( 9 ) , Address Varchar2 ( 13 ) , Town Varchar2 ( 14 ) , County Varchar2 ( 9 ) , Gender Varchar2 ( 6 ) , Date_Of_Birth Date ConstraintCafe_User_Date_Of_Birth_NN NOT NULL, Nationality Varchar2 ( 7 ) , Mobile_No Number ( 11 ) , Email Varchar2 ( 21 ) , Type Varchar2 ( 10 ) , User_Level Varchar2 ( 12 ) , Constraint Cafe_User_Cafe_User_Id_PK Primary Key(Cafe_User_Id), Constraint Café_User_Nationality_Ck Check(Nationality In('Irish', 'French', 'British', 'Italian', 'Welsh')) Constraint Café_User_Email_Uq Unique(Email));
  • 9. Aisling Fallon Higher Diploma in Computing 8 drop table Supplier ; create table Supplier ( Supplier_Id Number ( 2 ) , Name Varchar2 ( 25 ) ConstraintSupplier_Name_NN NOT NULL, Address Varchar2 ( 12 ) , Country Varchar2 ( 13 ) , Web_Site Varchar2 ( 20 ) , Year_Founded Number ( 4 ) , Specialism Varchar2 ( 11 ) , Annual_Turnover Varchar2 ( 5 ) , Constraint Supplier_Supplier_Id_PK Primary Key(Supplier_Id), Constraint Supplier_Annual_Turnover_Ck Check(Annual_Turnover BETWEEN 55000 AND 74000), Constraint Supplier_Name_Year_Founded_Uq Unique(Name, Year_Founded)); Column10 Number ( 6 ) , drop table Gadget ; create table Gadget ( Gadget_Id Number ( 4 ) , Name Varchar2 ( 9 ) ConstraintGad_Name_NN Not Null, Type Varchar2 ( 11 ) , Screen_Size_Inches Number ( 5 ) , Hard_Disk_Size_Inches Number ( 4 ) , RAM_Size Number ( 1 ) , Operating_System Varchar2 ( 12 ) , Video_Card Varchar2 ( 3 ) , Sound_Card Varchar2 ( 3 ) , Date_Purchased Date , Cost_Price Number ( 3 ) , Expected_Life Number ( 2 ) , Resale_Value Number ( 4 ) , Internet_Cafe_Id Number ( 3 ) , Supplier_Id Number ( 2 ) , Constraint Gad_GadId_PK Primary Key(Gadget_Id), Constraint Gad_IntCId_FK Foreign Key(Internet_Cafe_Id) References Internet_Cafe(Internet_Cafe_Id), Constraint Gad_Supplier_Id_FK Foreign Key(Supplier_Id) References Supplier(Supplier_Id), Constraint Gad_Type_Ck Check(Type In('Laptop', 'PC', 'Tablet', 'Netbook', 'Subnotebook')), Constraint Gad_Name_Resale_Value_Uq Unique(Name, Resale_Value));
  • 10. Aisling Fallon Higher Diploma in Computing 9 drop table Cafe_User_Booking ; create table Cafe_User_Booking ( Cafe_User_Id Number ( 2 ) , Gadget_Id Number ( 4 ) , Date_Booked Date , Start_Time Varchar2 ( 17 ) , End_Time Varchar2 ( 17 ) , Amount_Due Number ( 1 ) , Activity Varchar2 ( 15 ) , Payment_Method Varchar2 ( 11 ) , Constraint CafeUBook_CafeU_Id_GadId_PK Primary Key(Cafe_User_Id,Gadget_Id), Constraint CafeUBook_GadId_FK Foreign Key(Gadget_Id) References Gadget(Gadget_Id), Constraint CafeUBook_Cafe_User_Id_FK Foreign Key(Cafe_User_Id) References Cafe_User(Cafe_User_Id), Constraint CafeUBook_Amount_Due_Ck Check(Amount_Due >=3)); drop table Technician ; create table Technician ( Technician_Id Number ( 4 ) , FName Varchar2 ( 8 ) , Sname Varchar2 ( 9 ) , Address Varchar2 ( 13 ) , Town Varchar2 ( 14 ) , County Varchar2 ( 9 ) , Qualifications Varchar2 ( 11 ) , Expertise Varchar2 ( 8 ) , Hourly_Rate Number ( 2 ) , Date_Hired Date ConstraintDate_Hired_NN NOT NULL, Mobile_No Number ( 11 ) , Constraint Tech_Tech_Id_PK Primary Key(Technician_Id), Constraint Tech_Hourly_Rate_Ck Check(Hourly_Rate BETWEEN 15 AND 25), Constraint Tech_Fname_Town_Uq Unique(Fname, Town));
  • 11. Aisling Fallon Higher Diploma in Computing 10 Column13 Number ( 6 ) ); drop table Gadget_Repair ; create table Gadget_Repair ( Gadget_Id Number ( 4 ) , Repair_Date Date , Details Varchar2 ( 18 ) , Cost Number ( 4 ) , Time_Taken Number ( 4 ) , Technician_Id Number ( 4 ) , Constraint GadRepair_GadId_Repair_Date_PK Primary Key(Gadget_Id,Repair_Date), Constraint GadRepair_Tech_Id_FK Foreign Key(Technician_Id) References Technician(Technician_Id), Constraint GadRepair_Cost_Ck Check(Cost Is NULL OR Cost BETWEEN 5 and 160)); 0 Number ( 6 ) , 0 Number ( 6 ) , 0 Number ( 6 ) , Column13 Number ( 6 ) );
  • 12. Aisling Fallon Higher Diploma in Computing 11 7. Insert Statements Internet_Cafe Inserts Insertinto Internet_Cafe values (101,'CruiseThe Net Cafe','Main Street','Shercock','Cavan','Cruise The Net Cafe','cruisethenet@hotmail.com',2005,5,'Cold drinks'); Insertinto Internet_Cafe values (102,'Chill Internet Cafe','Lough North','Killaloe','Clare','Chill Internet Cafe','chillinternet@gmail.com',2007,4,'Drinks'); Insertinto Internet_Cafe values (103,'Beans Cafe','North Street','Youghal','Cork','Beans Cafe','beanscafe@hotmail.om',2006,5,'Sandwiches'); Insertinto Internet_Cafe values (104,'Net Station Cafe','Abbey Street','Carney','Sligo','Net Station Cafe','netstation@yahhoo.ie',2004,5,'Snacks'); Insertinto Internet_Cafe values (105,'Angels Cafe','Killcrossbeg','Shercock','Cavan','Angels Cafe','angelscafe@gmail.com',2010,4,'Drinks'); Insertinto Internet_Cafe values (106,'Relax Cafe','Roadford','Doolin','Clare','Relax Cafe','relax@hotmail.ie',NULL,3,'Snacks'); Insertinto Internet_Cafe values (107,'Surfers Cafe','Granard Road','Ballyjamesduff','Cavan','Surfers Cafe','surferscafe@hotmail.com',2005,4,'Snacks'); Insertinto Internet_Cafe values (108,'Net Play Cafe','Chapel Street','Castlebaldwin','Sli go','Net Play Cafe','netpaly@hotmail.com',2006,5,'Snacks'); Insertinto Internet_Cafe values (109,'Comfy Cafe','Killaloe','Doolin ','Clare','Comfy Cafe','comfycafe@yahoo.ie',2008,3,'Sandwiches'); Insertinto Internet_Cafe values (110,'MousePad Cafe','Main Street','Dysart ','Roscommon','Mouse Pad Cafe','mousepad@gmail.com',2007,3,'Drinks'); Insertinto Internet_Cafe values (111,'TouristCafe','Barnavara Hill','Kinsale','Cork','Tourist Cafe',NULL,2009,4,'Snacks'); Insertinto Internet_Cafe values (112,'Cyber Cafe','Church Street','Cootehill','Cavan','Cyber Cafe','cybercaf@yahoo.com',NULL,4,NULL); Insertinto Internet_Cafe values (113,'GlobeCafe','Station Road','Lahinch','Clare','Globe Cafe','globescafe@gmail.com',2009,5,'Snacks'); Insertinto Internet_Cafe values (114,'One Stop Cafe','Cornaslieve','Virginia','Cavan','OneStop Cafe','onestopcafe@hotmail.com',2008,5,'Drinks'); Insertinto Internet_Cafe values (115,'The Hangout Cafe','Market Street','Ballinode','Sligo','The Hangout Cafe','hangout@gmail.com',2007,4,'Sandwiches'); Insertinto Internet_Cafe values (116,'Gamestation Cafe','Highfield Road','Ennis','Clare','Gamestation Cafe','gamestation@hotmail.com',2006,3,'Snacks');
  • 13. Aisling Fallon Higher Diploma in Computing 12 Insertinto Internet_Cafe values (117,'The Hub Cafe','Goff St','Mitchelstown','Cork','The Hub Cafe','hubcafe@yahoo.ie',2005,3,NULL); Insertinto Internet_Cafe values (118,'Neo Internet Cafe','Park Street','Athleague','Roscommon','Neo Internet Cafe','neointernet@yahoo.ie',2009,5,'Sandwiches'); Insertinto Internet_Cafe values (119,'The Strand Cafe','Barrack Street','Aclare','Sligo','The Strand Cafe','strandcafe@gmail.com',2008,3,'Snacks'); Commit;
  • 14. Aisling Fallon Higher Diploma in Computing 13 Cafe_User Inserts Insertinto Cafe_User values (10,'Colm','Hannon','Abbey Street','Shercock','Cavan','Male','23-Jan- 90','Irish',086-1234567,'colmh@gmail.com','Student','Novice'); Insertinto Cafe_User values (11,'Joan','Kavanagh','Church Street','Killaloe','Clare','Female','25-Dec- 50','Irish',085-7563985,'joank@gmail','Retired','Intermediate'); Insertinto Cafe_User values (12,'Niamh','Kelly','Main Street','Youghal','Cork','Female','02-Sep- 85','French',087-2578963,'niamhk@yahoo.co.uk','Working','Expert'); Insertinto Cafe_User values (13,'Aisling','McGrath','BridgeStreet','Carney','Sligo','Female','02-Sep- 85','Italian',086-9856321,'aislingmg@hotmail.com',NULL,'Expert'); Insertinto Cafe_User values (14,'Nigel','Brien','MarketSquare','Shercock','Cavan','Male','03-Jul- 76','British',089-4593621,NULL,'Unemployed','Novice'); Insertinto Cafe_User values (15,'Aoife','Donnelly','Abbey Street','Doolin','Clare','Female','19-May- 74','Welsh',089-7413259,'aoifed@hotmail.ocm','Unemployed',NULL); Insertinto Cafe_User values (16,'Edel','Donoghue','Church Street','Ballyjamesduff','Cavan','Female','28-Mar- 80','Irish',085-0315269,'edeld@gmail.com','Unemployed',NULL); Insertinto Cafe_User values (17,'Connell','Dowling','Main Street','Castlebaldwin','Sligo','Male','12-Feb- 91','Irish',089-7585123,'connelld@yahoo.com','Student','Novice'); Insertinto Cafe_User values (18,'Jessica','Kelly','Abbey Street','Doolin ','Clare','Female','21-Sep- 87',NULL,NULL,'jessicak@hotmil.com','Working','Expert'); Insertinto Cafe_User values (19,'Aaron','McDonald','Church Street','Dysart ','Roscommon','Male','13-Oct- 88','Irish',086-8932154,'aaronmcd@hotmail.com','Working','Expert'); Insertinto Cafe_User values (20,'Gary','Morrissey','Main Street','Kinsale','Cork','Male','14-Aug-81','Irish',085- 1212323,'garym@hotmail.com','Unemployed',NULL); Insertinto Cafe_User values (21,'Daniel','Nevin','BridgeStreet','Cootehill','Cavan','Male','17-Feb-92','Irish',089- 9898654,'danieln@yahoo.co.uk','Student','Intermediate'); Insertinto Cafe_User values (22,'David','Quinlan','MarketSquare','Lahinch','Clare','Female','14-Aug- 81','Irish',085-8795698,'davidq@gmal.com','Retired','Intermediate'); Insertinto Cafe_User values (23,'Tracey','Brennan','Abbey Street','Virginia','Cavan','Female','06-Jun- 52','British',089-7875321,'traceyb@hotmail.om7','Retired','Novice'); Insertinto Cafe_User values (24,'Mary','McGrath','Church Street','Ballinode','Sligo','Male','24-Oct- 78','British',085-1313954,'marymcg@hotmail.com','Unemployed','Novice'); Insertinto Cafe_User values (25,'Cormac','Kavanagh','Main Street','Ennis','Clare','Female','19-Jan- 91','French',087-9568153,'cormacjk@gmail.com','Student','Novice');
  • 15. Aisling Fallon Higher Diploma in Computing 14 Insertinto Cafe_User values (26,'Gillian','Kiernan','BridgeStreet','Mitchelstown','Cork','Female','16-May- 51','Italian',089-9516236,'gilliank@gmail.com','Retired','Intermediate'); Insertinto Cafe_User values (27,'Clodagh','Nolan','MarketSquare','Athleague','Roscommon','Female','28-Aug- 50','Irish',086-1425369,'clodaghn@yahoo.com','Retired','Intermediate'); Insertinto Cafe_User values (28,'Louise','Collins','Abbey Street','Aclare','Sligo','Female','08-Jul-77','Irish',085- 7875963,'louisec@hotmail.com','Working','Expert'); Insertinto Cafe_User values (29,'Ian','Donohoe','Main Street','Kilrush','Clare','Male','16-Apr-52','Irish',086- 4835915,'iand@gmail.com','Retired','Novice'); Commit;
  • 16. Aisling Fallon Higher Diploma in Computing 15 Supplier Inserts Insertinto Supplier values (50,'Tech Data Ltd.','Toronto','Canada','www.techdata.com',2009,'PCs',55000); Insertinto Supplier values (51,'SGD IntertradingLtd.','Munich ','Germany','www.sgd.ie',2010,'Servers',56000); Insertinto Supplier values (52,'Synnex Ltd.','Austin ','United States','www.synnes.com',2008,'Servers',57000); Insertinto Supplier values (53,'SIS Distribution Ltd.','Bakersfield ','United States',NULL,2007,'Peripherals',58000); Insertinto Supplier values (54,'Eternal Distribution Ltd.','Baltimore','United States','www.externaldist.com',2001,'Laptops',59000); Insertinto Supplier values (55,'Intcomex Ltd.','Brampton ','Canada','www.intomex.com',2002,'PCs',60000); Insertinto Supplier values (56,'ASBIS Ltd.','Nimes','Canada','www.asbis.ie',2003,'Servers',61000); Insertinto Supplier values (57,'DIKO Global Ltd.','Tours','Canada','www.diko.com',NULL,'PCs',62000); Insertinto Supplier values (58,'VST Computers Ltd.','Paris','France','www.vst.ie',2005,'Laptops',63000); Insertinto Supplier values (59,'Nikoyo Ltd.','Lille','France','www.nikoyo.com',2006,'Servers',64000); Insertinto Supplier values (60,'FDC International Ltd.','Lyon','France','www.fdc.ie',2007,'Peripherals',65000); Insertinto Supplier values (61,'Avnet Ltd.','Berlin','Germany','www.avnet.com',2008,'Laptops',66000); Insertinto Supplier values (62,'IngramMicro Ltd.','Hamburg','Germany','www.ingrammicro.ie',2009,'PCs',57000); Insertinto Supplier values (63,'Tech Data Ltd.','Zacatecas ','Mexico',NULL,2010,'Servers',58000); Insertinto Supplier values (64,'SGD IntertradingLtd.','Zamora ','Mexico','www.sgd.ie',2011,'Peripherals',59000); Insertinto Supplier values (65,'Synnex Ltd.','Zapopan ','Mexico','www.synnes.com',2005,'Peripherals',60000); Insertinto Supplier values (66,'SIS Distribution Ltd.','Bremen','Germany','www.sis.ie',2006,'Laptops',61000); Insertinto Supplier values (67,'Eternal Distribution Ltd.','Nurnberg','Germany','www.externaldist.com',NULL,'Laptops',62000); Insertinto Supplier values (68,'Intcomex Ltd.','Rochester ','United States','www.intomex.com',2008,'Servers',63000); Insertinto Supplier values (69,'FDC International Ltd.','Rockford ','United States','www.fdc.ie',2009,'PCs',74000); Commit;
  • 17. Aisling Fallon Higher Diploma in Computing 16 Gadget Inserts Insertinto Gadget values (1000,'Acer','Laptop',17.3,3.5,2,'Linux','Yes','No','13-Nov-10',650,36,550,101,50); Insertinto Gadget values (1001,'Apple','PC',21,3.5,2,'Windows 2000','No','Yes','04-Mar- 11',700,48,550,102,51); Insertinto Gadget values (1002,'Asus','Tablet',7,1.8,1,'Android','Yes','No','04-Mar-10',320,24,250,103,52); Insertinto Gadget values (1003,'Dell','Netbook',10,1.8,1,'Android','Yes','No','12-Nov-12',350,18,300,104,53); Insertinto Gadget values (1004,'Philips','Subnotebook',22,3.5,2,'Vista','Yes','No','10-Jun- 10',450,20,410,105,54); Insertinto Gadget values (1005,'Samsung','Laptop',18.5,3.5,2,'Mac OS','Yes','No','10-Jun- 11',530,30,450,106,55); Insertinto Gadget values (1006,'Sony','PC',22,3.5,2,'Mac OS','No','Yes','07-Nov-12',630,25,550,107,56); Insertinto Gadget values (1007,'HP','Subnotebook',14,3.5,2,'Linux','Yes','No','07-Nov-11',650,24,600,108,57); Insertinto Gadget values (1008,'Sharp','Tablet',8,2.5,1,NULL,'Yes','No','06-Nov-11',360,18,NULL,109,58); Insertinto Gadget values (1009,'Zalman','Netbook',10.5,2.5,1,'Android','Yes','No','25-May- 12',390,18,290,110,59); Insertinto Gadget values (1010,'Asus','Subnotebook',14.5,3.5,2,'Windows 2000','Yes','No','20-Jul- 10',520,18,450,106,60); Insertinto Gadget values (1011,'Compaq','Laptop',18,3.5,2,'Vista','No','No','13-May-11',525,48,450,107,55); Insertinto Gadget values (1012,'Epson','Tablet',8,2.5,1,'Android','Yes','No','23-Nov-10',635,20,500,108,56); Insertinto Gadget values (1013,'Toshiba','Netbook',9.5,1.8,1,'Android','Yes','No','14-Jun- 13',360,24,300,109,57); Insertinto Gadget values (1014,'Panasonic','PC',21.5,3.5,2,'Mac OS','No','Yes ','09-Jun-13',380,24,295,110,58); Insertinto Gadget values (1015,'Intel','Netbook',10,2.5,1,NULL,'Yes','No ','09-Jun-13',550,36,495,104,59); Insertinto Gadget values (1016,'Sharp','PC',21,3.5,2,'Vista','No','Yes','10-Nov-11',320,24,250,105,60); Insertinto Gadget values (1017,'Zalman','Subnotebook',14,3.5,2,'Linux','Yes','No','10-Nov- 12',385,12,295,106,53); Insertinto Gadget values (1018,'Asus','PC',21.5,3.5,2,'Windows 2000','No','Yes','29-Jun- 13',560,36,490,107,54); Insertinto Gadget values (1019,'Compaq','PC',22,3.5,2,'Mac OS','No','Yes','02-Apr-11',700,18,NULL,108,55); Commit;
  • 18. Aisling Fallon Higher Diploma in Computing 17 Cafe_User_Booking Inserts Insertinto Cafe_User_Booking values (10,1000,'01-Sep-13','09:30','10:30',5,'Email','Cash'); Insertinto Cafe_User_Booking values (11,1001,'02-Sep-13','10:30','11:30',4,'Intermet',NULL); Insertinto Cafe_User_Booking values (12,1002,'04-Sep-13','11:30','12:30',5,'Word Processing','Laser'); Insertinto Cafe_User_Booking values (13,1003,'03-Sep-13','12:30','13:30',5,NULL,'Laser'); Insertinto Cafe_User_Booking values (14,1004,'06-Sep-13','13:30','14:30',4,'Access','Cash'); Insertinto Cafe_User_Booking values (15,1005,'05-Sep-13','14:30','15:30',3,'Other','Credit Card'); Insertinto Cafe_User_Booking values (16,1006,'07-Sep-13','15:30','16:30',4,'Internet','Credit Card'); Insertinto Cafe_User_Booking values (17,1007,'09-Sep-13','16:30','17:30',5,'Word Processing','Cash'); Insertinto Cafe_User_Booking values (18,1008,'10-Sep-13','17:30','18:30',3,'Excel','Laser'); Insertinto Cafe_User_Booking values (19,1009,'11-Sep-13','18:30','19:30',3,'Email','Laser'); Insertinto Cafe_User_Booking values (20,1010,'12-Sep-13','19:30','20:30',4,'Other','Cash'); Insertinto Cafe_User_Booking values (21,1003,'01-Sep-13','20:30','21:30',4,'Access','Cash'); Insertinto Cafe_User_Booking values (22,1004,'02-Sep-13','10:30','11:30',5,NULL,'Cash'); Insertinto Cafe_User_Booking values (23,1005,'04-Sep-13','11:30','12:30',5,'Access','Cash'); Insertinto Cafe_User_Booking values (24,1006,'03-Sep-13','12:30','13:30',4,'Internet','Credit Card'); Insertinto Cafe_User_Booking values (25,1007,'06-Sep-13','13:30','14:30',3,'Email','CreditCard'); Insertinto Cafe_User_Booking values (26,1008,'05-Sep-13','14:30','15:30',3,'Other','Laser'); Insertinto Cafe_User_Booking values (27,1009,'07-Sep-13','15:30','16:30',5,'Email','Cash'); Insertinto Cafe_User_Booking values (28,1010,'20-Sep-13','16:30','17:30',3,'Excel',NULL); Insertinto Cafe_User_Booking values (29,1001,'21-Sep-13','17:30','18:30',4,'Excel','CreditCard'); Commit;
  • 19. Aisling Fallon Higher Diploma in Computing 18 Technician Inserts Insertinto Technician values (2000,'Aidan','Cassidy','Market Square','Shercock','Cavan','Certificate','Software',15,'23-Oct-08',086-4536578); Insertinto Technician values (2001,'Joe','Dougan','Abbey Street','Killaloe','Clare',NULL,'Networks',20,'22-Jun- 05',085-9685412); Insertinto Technician values (2002,'Fionan','Downey','Church Street','Youghal','Cork','MSc','Hardware',25,'15 - Mar-09',089-9587412); Insertinto Technician values (2003,'Stephen','McCusker','Main Street','Carney','Sligo','Degree','Hardware',20,'26-Jun-05',087-3698752); Insertinto Technician values (2004,'Podsie','Muldoon','Abbey Street','Shercock','Cavan','Degree','Software',20,'09-May-08',NULL); Insertinto Technician values (2005,'Des','Murray','Church Street','Doolin','Clare','MSc','Networks',25,'10-Mar- 09',086-7894321); Insertinto Technician values (2006,'Kevin','McCloskey','Main Street','Ballyjamesduff','Cavan','Certificate','Hardware',15,'15-Jan-10',089-1476532); Insertinto Technician values (2007,'Fachtna','McCusker','Bridge Street','Castlebaldwin','Sligo','Degree','Software',20,'09-Sep-11',086-2369851); Insertinto Technician values (2008,'Nicholas','Heaney','MarketSquare','Doolin ','Clare ','Msc','Hardware',25,'03-Jun-10',085-7478958); Insertinto Technician values (2009,'Michael','Rocks','Abbey Street','Dysart ','Roscommon','Certificate','Software',15,'04-Sep-11',085-3969369); Insertinto Technician values (2010,'Gary','Tohill','Church Street','Kinsale','Cork','Degree','Hardware',20,'05- Jun-10',NULL); Insertinto Technician values (2011,'Henry','Campbell','Main Street','Cootehill','Cavan','Degree',NULL,20,'15 - Jan-08',089-1212121); Insertinto Technician values (2012,'Sean','Crosson','BridgeStreet','Lahinch','Clare','MSc','Networks',15,'25-Jul- 09',087-3232356); Insertinto Technician values (2013,'Johnny','Diver','Market Square','Virginia','Cavan','Certificate','Software',25,'26-Aug-10',086-7985456); Insertinto Technician values (2014,'Niall','Hegarty','Abbey Street','Ballinode','Sligo','Degree','Software',20,'29- Nov-11',085-5858587); Insertinto Technician values (2015,'Paul','McGinley','Main Street','Ennis','Clare','Msc','Hardware',15,'21-Feb- 12',089-0326587); Insertinto Technician values (2016,'Kieran','Reid','Bridge Street','Mitchelstown','Cork','Certificate','Software',20,'12-May-09',086-0202123); Insertinto Technician values (2017,'David','Ruane','Market Square','Athleague','Roscommon','MSc','Hardware',25,'18-May-09',086-8495369);
  • 20. Aisling Fallon Higher Diploma in Computing 19 Insertinto Technician values (2018,'Paddy','Sweeney','Abbey Street','Aclare','Sligo',NULL,'Networks',15,'17- Apr-11',089-3577532); Insertinto Technician values (2019,'Eamonn','Boyle','Main Street','Kilrush','Clare','MSc','Networks',25,'24 -Oct- 10',086-7569874); Commit;
  • 21. Aisling Fallon Higher Diploma in Computing 20 Gadget_Repair Inserts Insertinto Gadget_Repair values (1000,'01-Nov-11','Remove Virus',30,120,2000); Insertinto Gadget_Repair values (1001,'06-Jun-12','ReplaceHard Drive',10,30,2001); Insertinto Gadget_Repair values (1002,'05-Oct-11','Memory Upgrade',25,60,2002); Insertinto Gadget_Repair values (1003,'02-May-13','Screen Replacement',5,15,2003); Insertinto Gadget_Repair values (1004,'05-Dec-10','DC Socket Repairs',60,180,2004); Insertinto Gadget_Repair values (1005,'02-May-12',NULL,50,120,2005); Insertinto Gadget_Repair values (1006,'09-Mar-13','Windows re-install',60,240,2006); Insertinto Gadget_Repair values (1007,'09-Mar-12','MalwareInfection',100,NULL,2007); Insertinto Gadget_Repair values (1008,'01-May-12','Memory Upgrade',25,60,2008); Insertinto Gadget_Repair values (1009,'08-Jul-13','Remove Virus',90,360,2009); Insertinto Gadget_Repair values (1010,'21-Jun-12','ReplaceHard Drive',40,120,2010); Insertinto Gadget_Repair values (1011,'17-Sep-13','Memory Upgrade',60,180,2002); Insertinto Gadget_Repair values (1012,'24-Sep-12','Screen Replacement',30,120,2003); Insertinto Gadget_Repair values (1013,'15-Sep-13','DC Socket Repairs',NULL,60,2004); Insertinto Gadget_Repair values (1014,'10-Jul-13','Service',160,480,2005); Insertinto Gadget_Repair values (1015,'10-Sep-13','Windows re-install',90,360,2006); Insertinto Gadget_Repair values (1016,'26-Oct-12','MalwareInfection',80,240,2007); Insertinto Gadget_Repair values (1017,'03-May-13','Memory Upgrade',75,180,2009); Insertinto Gadget_Repair values (1018,'27-Aug-13','ReplaceHard Drive',30,120,2010); Insertinto Gadget_Repair values (1019,'06-Jun-12',NULL,NULL,60,2002); Commit;
  • 22. Aisling Fallon Higher Diploma in Computing 21 8. Tables Internet_Cafe Cafe_User Supplier
  • 23. Aisling Fallon Higher Diploma in Computing 22 Gadget Cafe_User_Booking
  • 24. Aisling Fallon Higher Diploma in Computing 23 Technician Gadget_Repair
  • 25. Aisling Fallon Higher Diploma in Computing 24 9. Single Table Queries Question 1 Show the internet cafes in Roscommon and Cavan which were opened after 2005,with an hourly rate of between 3 and 5 euro and where the name of the cafe contains an “a”. Select Name,Year_Opened, County, Rate_Per_Hour From Internet_Cafe Where Year_Opened >2005 And Name LIKE ‘%a%’ And County IN(’Roscommon’,’Cavan’) And Rate_Per_Hour BETWEEN 3 AND 5; Select Internet_Cafe.Name, Internet_Cafe.Year_Opened, Internet_Cafe.County, Internet_Cafe.Rate_Per_Hour From Internet_Cafe Where Internet_Cafe.Year_Opened >2005 And Internet_Cafe.Name LIKE ‘%a%’ And Internet_Cafe.County IN(’Roscommon’,’Cavan’) And Internet_Cafe.Rate_Per_Hour BETWEEN 3 AND 5;
  • 26. Aisling Fallon Higher Diploma in Computing 25 Question 2 Show the first names of the cafe users except those who end with a “k”, excluding those from Cavan and Roscommon, who have a user level and cafe user number not between 10 and 15. Select Firstname, County, Cafe_User_Id, User_Level From Cafe_User Where FirstnameNOT LIKE ‘%k’ And User_Level IS NOT NULL And County NOT IN (‘Cavan’,’Roscommon’) And Cafe_User_Id NOT BETWEEN 10 AND 15; Select Cafe_User.Firstname, Cafe_User.County, Cafe_User.Cafe_User_Id, Cafe_User.User_Level From Cafe_User Where Cafe_User.Firstname NOT LIKE ‘%k’ And Cafe_User.User_Level IS NOT NULL And Cafe_User.County NOT IN (‘Cavan’,’Roscommon’) And Cafe_User.Cafe_User_Id NOT BETWEEN 10 AND 15;
  • 27. Aisling Fallon Higher Diploma in Computing 26 Question 3 Show the suppliers from Canada with a name containing an “e” that specialise in Servers and PC’s with the year founded in ascending order. Select Name, Country, Specialism,Year_Founded From Supplier Where Country=’Canada’ And SpecialismIN(‘PCs’,‘Servers’) And Name LIKE ‘%e%’ Order By Year_Founded ASC; Select S.Name, S.Country, S.Specialism,S.Year_Founded From Supplier S Where S.Country=’Canada’ And S.SpecialismIN(‘PCs’,‘Servers’) And S.Name LIKE ‘%e%’ Order By S.Year_Founded ASC;
  • 28. Aisling Fallon Higher Diploma in Computing 27 Question 4 Show the gadgets where the resale value is not 550 euro, also show the resale values ascending, give name uppercase and type lowercase. Select UPPER(Name), LOWER(Type), Cost_Price,Resale_Value From Gadget Where Cost_Price<>550 And Length(Name)>6 Order By Resale_Value DESC; Select UPPER(G.Name), LOWER(G.Type), G.Cost_Price, G.Resale_Value From Gadget G Where G.Cost_Price<>550 And Length(Name)>6 Order By G.Resale_Value DESC;
  • 29. Aisling Fallon Higher Diploma in Computing 28 Question 5 Show the technicians who have an hourly rate less than or equal to 20 euro, there qualification not starting with a “D”. Also give the Surname in capitals and leave a white space on the left and right side of the name and town. Select RTRIM(FName), INITCAP(Sname), LTRIM(Town), Hourly_Rate, Qualifications From Technician Where Hourly_Rate<=5 Or QualificationsNOTLIKE ‘D%’; Select RTRIM(T.FName), INITCAP(T.Sname), LTRIM(T.Town),T.Hourly_Rate, Qualifications From Technician T Where T.Hourly_Rate<=5 Or T.QualificationsNOTLIKE ‘D%’;
  • 30. Aisling Fallon Higher Diploma in Computing 29 Question 6 Show the details of gadget repair not including “Remove virus”, “Service” and “DC Socket Repairs” where the time taken is greater than or equal to 30mins, also showing the cost multiplied by 12 assuming each job is performed on a monthly basis. Also show the time taken in ascending order. Select Details,SUBSTR(Details, 1,3), Time_Taken, Cost*12 From Gadget_Repair Where Time_Taken>=30 And Details NOT IN(‘Remove Virus’,‘Service’, ‘DC Socket Repairs’) Order By Time_Taken ASC; Select GR.Details,SUBSTR(GR.Details, 1,3), GR.Time_Taken, GR.Cost*12 From Gadget_Repair GR Where GR.Time_Taken>=30 And GR.Details NOT IN(‘Remove Virus’,‘Service’, ‘DC Socket Repairs’) Order By GR.Time_Taken ASC;
  • 31. Aisling Fallon Higher Diploma in Computing 30 10. Joins Question 1 (Parent Child Query involving 2 tables) Show the firstname and qualification of the technicians and the cost and time taken for the associated technicians of gadget repair.Show the technicians with and id of between 2000 and 2009 only, with their address containing an “a” and the time taken in descending order. Select Fname, Qualifications,Cost,Time_Taken, Address,Technician.Technician_Id From Technician,Gadget_Repair Where Technician.Technician_Id=Gadget_Repair.Technician_Id And Address LIKE ‘%a%’ And Technician.Technician_Id BETWEEN 2000 AND 2009 Order By Time_Taken DESC; Select Technician.Fname,Technician.Qualifications,Gadget_Repair.Cost, Gadget_Repair.Time_Taken, Technician.Address,Technician.Technician_Id From Technician,Gadget_Repair Where Technician.Technician_Id=Gadget_Repair.Technician_Id And Technician.Address LIKE‘%a%’ And Technician.Technician_Id BETWEEN 2000 AND 2009 Order By Gadget_Repair.Time_Taken DESC;
  • 32. Aisling Fallon Higher Diploma in Computing 31 Question 2 (Parent Child Query involving 3 tables) List the supplier’s name (in uppercase), annual turnover, specialism and year founded, also the cost price and type of the gadgets they supply and the activity associated with the cafe users booking. Confine the output to exclude any specialism beginning with the letter “S” and the year founded to exclude the years between 2002 and 2004. Select UPPER(Supplier.Name), Annual_Turnover, Type, Cost_Price, Activity, Specialism,Year_Founded From Supplier,Gadget, Cafe_User_Booking Where Supplier.Supplier_Id=Gadget.Supplier_Id And Gadget.Gadget_Id=Cafe_User_Booking.Gadget_Id And SpecialismNOT LIKE ‘S%’ And Year_Founded NOT BETWEEN 2002 AND 2004; Select UPPER(S.Name), S.Annual_Turnover, G.Type, G.Cost_Price, CUB.Activity, S.Specialism, S.Year_Founded From Supplier S, Gadget G, Cafe_User_Booking CUB Where S.Supplier_Id=G.Supplier_Id And G.Gadget_Id=CUB.Gadget_Id And S.SpecialismNOTLIKE ‘S%’ And S.Year_Founded NOT BETWEEN 2002 AND 2004;
  • 33. Aisling Fallon Higher Diploma in Computing 32 Question 3 (Parent Child Query involving all tables) Using all tables show the year opened of each internet café after 2009, the counties of the café users and the technicians in Cavan and Clare. Also show the annual turnover of the suppliers, the different types of gadgets, the activity of the café user where the technician id is between 2000 and 2001. In the results sort the supplier’s annual turnover starting with the lowest. Select Internet_Cafe.Year_Opened, Cafe_User.County, Supplier.Annual_Turnover, Gadget.Type, Cafe_User_Booking. Activity, Technician.County,Gadget_Repair.Technician_Id From Internet_Cafe, Cafe_User, Supplier,Gadget, Cafe_User_Booking, Technician,Gadget_Repair Where Internet_Cafe.Internet_Cafe_Id=Gadget. Internet_Cafe_Id And Cafe_User.Cafe_User_Id=Cafe_User_Booking. Cafe_User_Id And Supplier.Supplier_Id=Gadget.Supplier_Id And Gadget.Gadget_Id=Cafe_User_Booking.Gadget_Id And Technician.Technician_Id=Gadget_Repair.Technician_Id And Technician.CountyIN(‘Cavan’,‘Clare’) And Gadget_Repair.Technician_Id BETWEEN 2000 AND 2001 And Internet_Cafe.Year_Opened>2009 Order By Supplier.Annual_Turnover ASC; Select IC.Year_Opened, CU.County, S.Annual_Turnover, G.Type, CUB. Activity, T.County, GR.Technician_Id From Internet_Cafe IC, Cafe_User CU, Supplier S, Gadget G, Cafe_User_Booking CUB, Technician T, Gadget_Repair GR Where IC.Internet_Cafe_Id=G. Internet_Cafe_Id And CU.Cafe_User_Id=CUB. Cafe_User_Id And S.Supplier_Id=G.Supplier_Id And G.Gadget_Id=CUB.Gadget_Id And T.Technician_Id=GR.Technician_Id And T.CountyIN(‘Cavan’, ‘Clare’) And GR.Technician_Id BETWEEN 2000 AND 2001 And IC.Year_Opened>2009 Order By S.Annual_Turnover ASC;
  • 34. Aisling Fallon Higher Diploma in Computing 33 Question 4 (An equijoin on two tables) Show the first name and town of the cafe user and the name and country of the supplier where the length (in letters) of the town is equal to the length (in letters) of the country. Confine the output to countries not in Germany, Canada, Mexico or the United States. Give the first name uppercase and the suppliers name in lower case..... Select UPPER(Firstname), Cafe_User.Town, LOWER(Supplier.Name), Country From Cafe_User, Supplier Where Length(Cafe_User.Town)=Length(Country) And Supplier.Country NOT IN (‘Germany’, ‘Canada’,‘Mexico’, ‘United States’); Select UPPER(CU.Firstname), CU.Town, LOWER(S.Name), S.Country From Cafe_User CU, Supplier S Where Length(CU.Town)=Length(S.Country) And S.Country NOT IN (‘Germany’, ‘Canada’,‘Mexico’, ‘United States’);
  • 35. Aisling Fallon Higher Diploma in Computing 34 Question 5 (Non Equijoin between 2 tables) List the names and year opened of the internet cafes in 2010 or after and the name of the suppliers and year founded where the year opened of the internet cafe exceeds the year founded of the supplier. Also show the difference in years between the year opened and year founded. Select INITCAP(Internet_Cafe.Name),Year_Opened,INITCAP(Supplier.Name), Year_Founded, Year_Opened- Year_Founded “Difference in Years” From Internet_Cafe, Supplier Where Year_Opened>Year_Founded And Year_Opened>=2010; Select IC.Name,IC.Year_Opened, INITCAP(S.Name), S. Year_Founded, IC.Year_Opened-S.Year_Founded “Difference in Years” From Internet_Cafe IC, Supplier S Where IC.Year_Opened>S.Year_Founded And IC.Year_Opened>=2010;
  • 36. Aisling Fallon Higher Diploma in Computing 35 Question 6 (A Self join) Show the name and screen sizes of the gadgets where the screen sizes are the same size. Show the screen size (in inches) in ascending order. Select G1.Name, G1.Screen_Size_Inches, G2.Name, G2.Screen_Size_Inches From Gadget G1, Gadget G2 Where G1.Screen_Size_Inches= G2.Screen_Size_Inches And G1.Gadget_Id<G2.Gadget_Id Order By G1.Screen_Size_Inches ASC;
  • 37. Aisling Fallon Higher Diploma in Computing 36 Question 7 (Outer Join) Give the first names of the technicians and the associated cost for the gadget repair including technicians who may not yet have had a gadget to repair. Sort the cost in descending order. Select (Fname) “Firstname”, (Cost) “Total Cost” From Technician,Gadget_Repair Where Technician.Technician_Id=Gadget_Repair.Technician_Id(+) Order byCost DESC; Select (Technician.Fname) “Firstname”, (Gadget_Repair.Cost) “Total Cost” From Technician,Gadget_Repair Where Technician.Technician_Id=Gadget_Repair.Technician_Id(+) Order byGadget_Repair.Cost DESC;
  • 38. Aisling Fallon Higher Diploma in Computing 37 11. Summary Queries Question 1 Find the maximum and minimum time taken for technicians in gadget repair and also the average cost, where the details of repair contain an “e”. Select Max(GR.Time_Taken), Min(GR.Time_Taken), Avg(GR.Cost) From Gadget_Repair GR Where Gr.DetailsLIKE’%e%’; Question 2 Find the number of gadgets including the average hard disk size and the sum of the cost price for each one, excluding the gadgets that end with the letter “n” and have a resale value between 300 and 500 euro. Select Sum(G.Cost_Price), Avg(G.Hard_Disk_Size_Inches), Count(G.Gadget_Id) From Gadget G Where G.Resale_Value NOT BETWEEN 300 and 500 And G.Name NOT LIKE ‘%n’;
  • 39. Aisling Fallon Higher Diploma in Computing 38 Question 3 Count the number of suppliers who have no email address. Select Count(*) From Supplier S Where S.Web_Site IS NULL; Question 4 Find the maximum and minimum rate per hour for the Internet Cafes which have no facilities. Select Max(IC.Rate_Per_Hour), Min(IC.Rate_Per_Hour) From Internet_Cafe IC Where IC.Facilities IS NULL;
  • 40. Aisling Fallon Higher Diploma in Computing 39 Question 5 Show the min and max annual turnover for suppliers and the difference between them, where the year founded is less than or equal to 2008. Select Max(S.Annual_Turnover) Highest , Min(S.Annual_Turnover) Lowest, Max(S.Annual_Turnover)- Min(S.Annual_Turnover) Difference From Supplier S Where S.Year_Founded<=2008; Question 6 Show the gadget types along with the max and min screen size for each type and the average ram size for each of the types. Show the results in reverse alphabetical order by type and where the length of “type” (in letters) is greater than 5. Select G.Type, Max(G.Screen_Size_Inches) “Max Screen Size”, Min(G.Hard_Disk_Size_Inches) “Min Screen Size”, Avg(G.Ram_Size) From Gadget G Where Length(G.Type)>5 Group By G.Type Order By G.TypeDESC;
  • 41. Aisling Fallon Higher Diploma in Computing 40 Question 7 List each technician name, the average time taken to do the job, the sum of the cost and the number of jobs each technician had, where the time taken is greater than 100 minutes, arrange the names in alphabetical order. Select T.Fname,Avg(GR.Time_Taken), Sum(GR.Cost),Count(*) From Technician T, Gadget_Repair GR Where T.Technician_Id=GR.Technician_Id And GR.Time_Taken>100 Group By T.Fname Order By T.Fname ASC; Question 8 Listthe activity types for the café user, showingalso the lateststarttime and the sum of the amount due for each activity,where the amount due is greater than or equal to 10. Also sort the amount due in ascending order. Select CUB.Activity, (CUB.Start_Time)”Latest Time”, Sum(CUB.Amount_Due) From Cafe_User_Booking CUB Group By CUB.Activity Having Sum(CUB.Amount_Due)>=10 Order By Sum(CUB.Amount_Due) ASC;
  • 42. Aisling Fallon Higher Diploma in Computing 41 Question 9 Listthe names of the internet cafes in Cavan with an hourly rate of €5 or in Sligo with an hourly rate of €4, with the year opened is between 2005 and 2008 in descending oreder…………… Select IC.Name, Sum(IC.Rate_Per_Hour), Sum(IC.Year_Opened) From Internet_Cafe IC Where (IC.County=’Cavan’ and IC.Rate_Per_Hour=5) Or (IC.County=’Sligo’ and Rate_Per_Hour=4) Group By IC.Name Having Sum(IC.Year_Opened) BETWEEN 2005 and 2008 Order By Sum(IC.Year_Opened) DESC;
  • 43. Aisling Fallon Higher Diploma in Computing 42 12. Subqueries Question 1 Select the name of the gadgets with the highest cost price, where the resale value is between 450 and 600. Select Name From Gadget Where Cost_PriceIN (Select Max(Cost_Price) From Gadget Where Resale_ValueBETWEEN 450 AND 600);
  • 44. Aisling Fallon Higher Diploma in Computing 43 Question 2 Name the suppliers who live in Germany and have an annual turnover less than the highest annual turnover of a supplier in Canada and where the names do not end with an “l”. Select Name, Annual_Turnover From Supplier Where Name NOT LIKE ‘%l’ And Country=’Germany’ And Annual_Turnover< (Select Max(Annual_Turnover) From Supplier Where Country=’Canada’ And Name NOT LIKE ‘%l’);
  • 45. Aisling Fallon Higher Diploma in Computing 44 Question 3 Name the technicians with Degrees who have an hourly rate greater than the average hourly rate for technicians with no qualification. Select T.FName From Technician T Where T.Qualifications=’Degree’ And T.Hourly_Rate> (Select Avg(T.Hourly_Rate) From Technician T Where T.QualificationsIS NULL);
  • 46. Aisling Fallon Higher Diploma in Computing 45 Question 4 Name the café users with an id between 10 and 25, who are unemployed and have the same nationality as student café users. Select Firstname, Nationality From Cafe_User Where Type=’Unemployed’ And Cafe_User_Id BETWEEN 10 and 25 And Nationality IN (Select Nationality From Cafe_User Where Type=’Student’ And Cafe_User_Id BETWEEN 10 and 25);
  • 47. Aisling Fallon Higher Diploma in Computing 46 Question 5 Show the name, town and facilities of an internet café who have PC as their gadgets and their name contains a “u”. Select Name, Town, Facilities From Internet_Cafe Where Name LIKE ‘%u%’ And Internet_Cafe .Internet_Cafe_IdIN( Select Gadget.Internet_Cafe_Id From Gadget Where Type=’PC’);
  • 48. Aisling Fallon Higher Diploma in Computing 47 Question 6 Show the name, town and facilities of an internet café who do not have PC as their gadgets and contain the letter “u” in their name. Select Name, Town, Facilities From Internet_Cafe Where Name LIKE ‘%u%’ And Internet_Cafe .Internet_Cafe_Id NOT IN( Select Gadget.Internet_Cafe_Id From Gadget Where Type=’PC’);
  • 49. Aisling Fallon Higher Diploma in Computing 48 Question 7 List the names and year founded of the suppliers of gadgets with an annual turnover less than 65000 and where the length of the café user booking activity associated to the gadget is the same as the length of the payment method(in letters). Select Supplier.Name, Supplier.Year_Founded From Supplier Where Annual_Turnover< 65000 And Supplier.Supplier_IdIN( Select Gadget.Supplier_Id From Gadget Where Gadget.Gadget_IdIN( Select Cafe_User_Booking.Gadget_Id From Cafe_User_Booking Where Length(Cafe_User_Booking.Activity)=Length(Caf e_User_Booking.Payment_Method)));
  • 50. Aisling Fallon Higher Diploma in Computing 49 Question 8 List the café user activity where the length of the café user booking activity is the same as the length of the payment method(in letters)…..and where the annual turnover is less than 65000 for supplier…. Select Activity From Cafe_User_Booking Where Length(Cafe_User_Booking.Activity)=Length(Cafe_User_Booking.Payment_Method) And Cafe_User_Booking.Gadget_IdIN( Select Gadget.Gadget_Id From Gadget Where Gadget.Supplier_IdIN( Select Supplier.Supplier_Id From Supplier Where Annual_Turnover< 65000));
  • 51. Aisling Fallon Higher Diploma in Computing 50 Question 9 Show the name and year opened of internet cafes where the year opened is after 2003, the cost price of the gadget associated to the café is greater than 300, where the café user booking activity is email, internet or access, the nationality of the café user is French or Irish, the annual turnover is greater than 50000 for the supplier of the internet café, the tim e taken for the gadget repair is greater than 25 minutes and the technician from either Cavan, Clare or Roscommon. Select Internet_Cafe.Year_Opened, Internet_Cafe.Name From Internet_Cafe Where Internet_Cafe.Year_Opened>2003 And Internet_Cafe.Internet_Cafe_IdIN( Select Gadget.Internet_Cafe_Id From Gadget Where Gadget.Cost_Price>300 And Gadget.Gadget_IdIN( Select Cafe_User_Booking. Gadget_Id From Cafe_User_Booking Where Cafe_User_Booking. ActivityIN(‘Email’,’Internet’, ‘Access’) And Cafe_User_Booking.Cafe_User_IdIN( Select Cafe_User.Cafe_User_Id From Cafe_User Where Cafe_User.NationalityIn(‘Irish’, ‘French’) And Gadget.Supplier_IdIN( Select Supplier.Supplier_Id From Supplier Where Supplier.Annual_Turnover>50000 And Gadget.Gadget_IdIN( Select Gadget_Repair.Gadget_Id From Gadget_Repair Where Gadget_Repair.Time_Taken>15 AndGadget_Repair.Technician_IdIN( Select Technician.Technician_Id From Technician Where Technician.CountyIN(‘Cavan’, ‘Clare’, ‘Roscommon’)))))));
  • 52. Aisling Fallon Higher Diploma in Computing 51 Select DISTINCT Internet_Cafe.Year_Opened, Internet_Cafe.Name From Internet_Cafe, Gadget, Cafe_User_Booking, Cafe_User, Supplier, Gadget_Repair, Technician Where Internet_Cafe.Internet_Cafe_Id=Gadget.Internet_Cafe_Id And Gadget.Gadget_Id=Cafe_User_Booking. Gadget_Id And Cafe_User_Booking.Cafe_User_Id=Cafe_User.Cafe_User_Id And Gadget.Supplier_Id=Supplier.Supplier_Id And Gadget.Gadget_Id=Gadget_Repair.Gadget_Id And Gadget_Repair.Technician_Id=Technician.Technician_Id And Internet_Cafe.Year_Opened>2003 And Gadget.Cost_Price>300 And Cafe_User_Booking. Activity IN(‘Email’,’Internet’, ‘Access’) And Cafe_User.NationalityIn(‘Irish’, ‘French’) And Supplier.Annual_Turnover>50000 And Gadget_Repair.Time_Taken>15 And Technician.CountyIN(‘Cavan’,‘Clare’, ‘Roscommon’);
  • 53. Aisling Fallon Higher Diploma in Computing 52 Question 10 List the technician’s first name and surname where the cost of their gadget repair is not greater than €15. Select T.Fname, T.Sname From Technician T Where T.Technician_Id NOT IN( Select GR.Technician_Id From Gadget_Repair GR Where GR.Cost>15);
  • 54. Aisling Fallon Higher Diploma in Computing 53 Question 11 List the names of the suppliers(at least one) who supply laptops who have an annual turnover greater than the supplier of netbooks. Select S.Name, S.Annual_Turnover From Supplier S, Gadget G Where S.Supplier_Id=G.Supplier_Id And G.Type=’Laptop’ And S.Annual_Turnover>ANY (Select S.Annual_Turnover From Supplier S, Gadget G Where S.Supplier_Id=G.Supplier_Id And G.Type=’Netbook’);
  • 55. Aisling Fallon Higher Diploma in Computing 54 Question 12 Name all the technicians from Cavan that spend less time doing gadget repairs compared to all the technicians who come from Roscommon. Select T.Fname From Technician T, Gadget_Repair GR Where T.Technician_Id=GR.Technician_Id And T.County=’Cavan’ And Gr.Time_Taken<ALL (Select Gr.Time_Taken From Technician T, Gadget_Repair GR Where T.Technician_Id = GR.Technician_Id And T.County=’Roscommon’);
  • 56. Aisling Fallon Higher Diploma in Computing 55 13. Inserts, Updates and Deletes Question 1 Failed delete due to integrity constraint. Delete From Technician Where Technician_Id=2001;
  • 57. Aisling Fallon Higher Diploma in Computing 56 Question 2 Remove the cafe users who use credit card as a payment method Delete From Cafe_User Where Cafe_User.Cafe_User_IdIN( Select Cafe_User_Booking.Cafe_User_Id From Cafe_User_Booking Where Payment_Method=’Credit Card’); Remove the café users from Cavan as they no longer make a booking. Select Activity From Cafe_User_Booking Where Cafe_User_Booking.Cafe_User_IdIN( Select Cafe_User. Cafe_User_Id From Cafe_User Where County=’Cavan’); Delete From Cafe_User_Booking Where Cafe_User_Booking.Cafe_User_IdIN( Select Cafe_User. Cafe_User_Id From Cafe_User Where County=’Cavan’);
  • 58. Aisling Fallon Higher Diploma in Computing 57 Rollback;
  • 59. Aisling Fallon Higher Diploma in Computing 58 Question 3 Café Users who are assigned to gadgets where their suppliers have an annual turnover less than 58000 should be removed. Select Activity From Cafe_User_Booking Where Cafe_User_Booking.Gadget_IdIN( Select Gadget. Gadget_Id From Gadget Where Gadget.Supplier_IdIN( Select Supplier.Supplier_Id From Supplier Where Annual_Turnover< 58000)); Delete From Cafe_User_Booking Where Cafe_User_Booking.Gadget_IdIN( Select Gadget. Gadget_Id From Gadget Where Gadget.Supplier_IdIN( Select Supplier.Supplier_Id From Supplier Where Annual_Turnover< 58000)); Rollback;
  • 60. Aisling Fallon Higher Diploma in Computing 59 Question 4 Delete the internet cafes who do not have PCs as their gadget types and contain the letter “u” in their name (ON DELETE CASCADE). Select Name, Town, Facilities From Internet_Cafe Where Name LIKE ‘%u%’ And Internet_Cafe .Internet_Cafe_Id NOT IN (Select Gadget.Internet_Cafe_Id From Gadget Where Type=’PC’); Delete From Internet_Cafe Where Name LIKE ‘%u%’ And Internet_Cafe .Internet_Cafe_Id NOT IN (Select Gadget.Internet_Cafe_Id From Gadget Where Type=’PC’); Rollback;
  • 61. Aisling Fallon Higher Diploma in Computing 60 Question 5 Insert involving columns in random order. Insertinto Gadget_Repair(Repair_Date, Gadget_Id, Details,Time_Taken, Technician_Id,Cost)Values( ‘01-Dec- 11’, 2007, ‘Repair’, 112,2002,50); Question 6 Insert involving NULL. Insertinto Supplier(Annual_Turnover,Name, Country, Web_Site, Address, Year_Founded, Specialism, Supplier_Id)Values(60000,‘Techo’, ‘Ireland’,‘www.techo.com’, ‘Dublin’, NULL, ‘Servers’, 84);
  • 62. Aisling Fallon Higher Diploma in Computing 61 Question 7 Insert attempting to violate a foreign key. Insertinto Gadget(Gadget_Id, Hard_Disk_Size_Inches,RAM_Size, Screen_Size_Inches, Cost_Price, Expected_Life, Date_Purchased, Sound_Card, Video_Card, Name, Type, Operating_System, Supplier_Id, Internet_Cafe_Id, Resale_Value)Values (2500,3.5, 3, 17.5, 650,38, '13-Nov-10', 'Yes','No', 'Acer', ‘Laptop’, ‘Vista’, 53,200,650); Insertinto Gadget(Gadget_Id, Hard_Disk_Size_Inches,RAM_Size, Screen_Size_Inches, Cost_Price, Expected_Life, Date_Purchased, Sound_Card, Video_Card, Name, Type, Operating_System, Supplier_Id, Internet_Cafe_Id, Resale_Value )Values (2500,3.5, 3, 17.5, 650,38, '13-Nov-10', 'Yes', 'No', 'Acer', ‘Laptop’, ‘Vista’, 53,104,650); Rollback;
  • 63. Aisling Fallon Higher Diploma in Computing 62 Question 8 Show the details and costfor gadget repair for technician 2006 and then attempt to update to 2020,then successfully updateto 2007…. Select Details,Cost From Gadget_Repair Where Technician_Id=2006; Update Gadget_Repair Set Technician_Id=2020 Where Technician_Id=2006; Update Gadget_Repair Set Technician_Id=2007 Where Technician_Id=2006; Rollback;
  • 64. Aisling Fallon Higher Diploma in Computing 63 Question 9 Attempt to update a primary key for a parent that has children. Select Name, Address From Supplier Where Supplier_Id=55; Update Supplier Set Supplier_Id=56 Where Supplier_Id=55;
  • 65. Aisling Fallon Higher Diploma in Computing 64 Question 10 On Delete Cascade feature for all foreign keys Delete From Cafe_User_Booking Where Cafe_User_Booking.Gadget_IdIN( Select Gadget. Gadget_Id From Gadget Where Gadget.Supplier_IdIN( Select Supplier.Supplier_Id From Supplier Where Annual_Turnover< 58000 Select Count(*) From Cafe_User_Booking; Select Count(*) From Gadget;
  • 66. Aisling Fallon Higher Diploma in Computing 65 Select Count(*) From Supplier; Select Count(*) From Cafe_User_Booking Where Gadget_Id=1000; Select Count(*) From Gadget Where Gadget_Id=1000;
  • 67. Aisling Fallon Higher Diploma in Computing 66 Select Count(*) From Supplier Where Supplier.Supplier_IdIN( Select Gadget.Supplier_Id From Gadget Where Gadget_Id=1000); Delete From Cafe_User_Booking Where Gadget_Id=1000;
  • 68. Aisling Fallon Higher Diploma in Computing 67 Delete From Gadget Where Gadget_Id=1000; Delete From Supplier Where Supplier.Supplier_IdIN( Select Gadget.Supplier_Id From Gadget Where Gadget_Id=1000);
  • 69. Aisling Fallon Higher Diploma in Computing 68 Rollback;
  • 70. Aisling Fallon Higher Diploma in Computing 69 14. Views Question 1 Create a vertical view to show the name, address, country, specialism and annual turnover for the supplier of laptops. Drop View Supplier_Laptops; Create View Supplier_Laptops As Select Name, Address,Country, Specialism,Annual_Turnover From Supplier; Select Name, Country, Address, Specialism,Annual_Turnover From Supplier_Laptops;
  • 71. Aisling Fallon Higher Diploma in Computing 70 Question 2 Create a horizontal view using all columns in the supplier table. Drop View Supplier_Laptops; Create View Supplier_Laptops(Supplier_Id,Name, Address,Country, Web_Site, Year_Founded, Specialism,Annual_Turnover,Monthly_Wage)As Select Supplier_Id,Name, Address,Country, Web_Site, Year_Founded, Specialism,Annual_Turnover, Annual_Turnover/12 From Supplier Where Specialism=’Laptops’ And Year_Founded<2005; Select * From Supplier_Laptops;
  • 72. Aisling Fallon Higher Diploma in Computing 71 Question 3 Create a view based on a join of at least three tables. Drop View Supplier_Gadget_Cafe_User_Book; As Create View Supplier_Gadget_Cafe_User_Book As Select Supplier.Name, Supplier.Country,Gadget.Type, Gadget.Cost_Price, Cafe_User_Booking.Amount_Due, Cafe_User_Booking.Activity, Cafe_User_Booking.Payment_Method From Supplier,Gadget, Cafe_User_Booking Where Supplier.Supplier_Id=Gadget.Supplier_Id And Gadget.Gadget_Id=Cafe_User_Booking.Gadget_Id; Select * From Supplier_Gadget_Cafe_User_Book; Select Supplier.Name, Gadget.Type, Cafe_User_Booking.Activity From Supplier_Gadget_ Cafe_User_Booking;
  • 73. Aisling Fallon Higher Diploma in Computing 72 Question 4 Create a view based on a summary query. Drop View Gadget_Repair_Time_Cost; Create View Gadget_Repair_Time_Cost As Select Details,Max(Time_Taken) Max_Time, Min(Time_Taken)Min_Time, Avg(Cost) Avg_Cost From Gadget_Repair GR Group By Details; DescribeGadget_Repair_Time_Cost; Select * From Gadget_Repair_Time_Cost;
  • 74. Aisling Fallon Higher Diploma in Computing 73 Question 5 Create a view based on a singletablethat doesn’t have a WITH CHECK OPTION clause and attempt an insert and update. Drop View Internet_Cafe_Opened_County; Create View Internet_Cafe_Opened_County As Select Internet_Cafe_Id, Name,Year_Opened, County, Rate_Per_Hour, Facilities From Internet_Cafe Where Year_Opened >2005 And Name LIKE ‘%n%’ And County IN(’Roscommon’,’Clare’); Select Count(*) From Internet_Cafe_Opened_County; Select * From Internet_Cafe_Opened_County; Insertinto Internet_Cafe_Opened_County(Internet_Cafe_Id, Name,Year_Opened, County, Rate_Per_Hour, Facilities) Values(259,‘Techet’, 2003, ‘Sligo’,4, ‘Drinks’);
  • 75. Aisling Fallon Higher Diploma in Computing 74 Insertinto Internet_Cafe_Opened_County(Internet_Cafe_Id, Name,Year_Opened, County, Rate_Per_Hour, Facilities) Values(256,‘Cruising’,2007,‘Roscommon’, 4, ‘Drinks’); Select Count(*) From Internet_Cafe_Opened_County; Select * From Internet_Cafe_Opened_County; UPDATE Update Internet_Cafe_Opened_County Set County=’Galway’ Where County=’Roscommon’;
  • 76. Aisling Fallon Higher Diploma in Computing 75 Update Internet_Cafe_Opened_County Set Name=’Techno’ Where Name= ‘Gamestation Cafe’; In this view all the inserts and updates succeeded even though some of them did not meet the conditions outlined, this was because the view did not contain a with check option
  • 77. Aisling Fallon Higher Diploma in Computing 76 Question 6 Create the same view but include a WITH CHECK OPTION for an insert, update and delete. Drop View Internet_Cafe_Opened_County; Create View Internet_Cafe_Opened_County As Select Internet_Cafe_Id, Name,Year_Opened, County, Rate_Per_Hour, Facilities From Internet_Cafe Where Year_Opened >2005 And Name LIKE ‘%n%’ And County IN(’Roscommon’,’Clare’) With Check Option; Insertinto Internet_Cafe_Opened_County(Internet_Cafe_Id, Name,Year_Opened, County, Rate_Per_Hour, Facilities) Values(259,‘Techet’, 2003, ‘Sligo’,‘4’, ‘Drinks’); Insertinto Internet_Cafe_Opened_County(Internet_Cafe_Id, Name,Year_Opened, County, Rate_Per_Hour, Facilities) Values(256,‘Cruising’,2007,‘Roscommon’, 4, ‘Drinks’);
  • 78. Aisling Fallon Higher Diploma in Computing 77 Select Count(*) From Internet_Cafe_Opened_County; Select * From Internet_Cafe_Opened_County; UPDATE Update Internet_Cafe_Opened_County Set County=’Galway’ Where County=’Roscommon’; Update Internet_Cafe_Opened_County Set Name=’Techno’ Where Name= ‘Gamestation Cafe’;
  • 79. Aisling Fallon Higher Diploma in Computing 78 DELETE Delete From Internet_Cafe_Opened_County Where Internet_Cafe_Id=103; Delete From Internet_Cafe_Opened_County Where County=’Roscommon’; The insert that doesn’t comply with the where clause restriction will fail due to the with check option(where- clause violation) The insert which should comply will simply be inserted. The same can be said for the updates….the first one which did not meet the conditions failed due to the check option again, however the one which met the conditions in the view updated without any problem.
  • 80. Aisling Fallon Higher Diploma in Computing 79 Question 7 Attempt an invalid insert into a view containing a WITH CHECK OPTION clause, demonstrating when it succeeds and fails. Drop View Supplier_Canada; Create View Supplier_Canada As Select Supplier_Id,Annual_Turnover, Name, Country, Web_Site, Address, Year_Founded, Specialism From Supplier Where Country=’Canada’ With Check Option; Select * From Supplier_Canada; Insertinto Supplier_Canada(Supplier_Id,Annual_Turnover,Name, Country, Web_Site, Address, Year_Founded, Specialism)Values(84,60000,‘Techo’, ‘Canada’,‘www.techo.com’, ‘Dublin’, 2006,‘Servers’); Insertinto Supplier_Canada(Supplier_Id,Annual_Turnover,Name, Country, Web_Site, Address, Year_Founded, Specialism)Values(50,60000,‘Techo’, ‘Ireland’,‘www.techo.com’, ‘Dublin’, 2006,‘Servers’);
  • 81. Aisling Fallon Higher Diploma in Computing 80 Question 8 Attempt an invalid update into a view containing a WITH CHECK OPTION clause, also showing the update when it succeeds. Drop View Gadget_Repair_Details; Create View Gadget_Repair_Details As Select Details,Cost, Technician_Id From Gadget_Repair Where Cost<50 And Details LIKE’%n%’ WITH CHECK OPTION; Select * From Gadget_Repair_Details; Update Gadget_Repair_Details Set Details=’Repair’ Where Technician_Id=2003; Update Gadget_Repair_Details Set Details=’Re-install’ Where Technician_Id=2003;
  • 82. Aisling Fallon Higher Diploma in Computing 81 Alter Tables Question 1 (Adding a column to a table) Alter TableGadget Add Region Varchar2(12); Alter TableGadget DROP Column Region; Question 2 (Add a column with check constraint) Alter TableGadget Add ConstraintGadget_Region_CK Check (Region In(‘NORTH’, ‘SOUTH’,’EAST’));
  • 83. Aisling Fallon Higher Diploma in Computing 82 Question 3 (Increasewidth of existingcolumn) Alter TableGadget Modify Region Varchar2(12); Question 4 (Remove a column from a table) DROP Column Region;
  • 84. Aisling Fallon Higher Diploma in Computing 83 Question 5 (Drop a Pk constraintbut you need to drop Fk constraintfirst) Alter TableGadget Drop ConstraintGad_Supplier_Id_FK; Alter TableSupplier Drop ConstraintSupplier_Supplier_Id_PK; Question 6 (Add the pk constraintyou justdropped) Alter TableSupplier Add ConstraintSupplier_Supplier_Id_PK Primary Key(Supplier_Id); Alter TableGadget Add ConstraintGad_Supplier_Id_FK Foreign Key(Supplier_Id) References Supplier(Supplier_Id);
  • 85. Aisling Fallon Higher Diploma in Computing 84 Question 7 (Drop a Fk Constraint) Alter TableGadget Drop ConstraintGad_Supplier_Id_FK; Question 8 (Disableand enablea foreign key constraint) Alter TableGadget DisableConstraintGad_Supplier_Id_FK;
  • 86. Aisling Fallon Higher Diploma in Computing 85 14. Security Question 1 (Grant select, update and delete to two students). Grant select on Supplier to student145, student142; Grant inserton Supplier to student145, student142; Grant update on Supplier to student145, student142; Question 2 (Grant permission on select to public) Grant select on Gadget to Public;
  • 87. Aisling Fallon Higher Diploma in Computing 86 Question 3 (Grant two conditions to one student) Grant select, update on Gadget_Repair to student145; Question 4 (Grant select with permission for the privileges to be passed on) Grant select on Internet_Cafe to student142 with grantoption; Question 5 (Grant a student select and insert to a view) Grant select, inserton Supplier_Laptops to student142;
  • 88. Aisling Fallon Higher Diploma in Computing 87 Question 6 (Grant an update and delete on a view to two students) Grant update, delete on Supplier_Laptops to student142, student145; Question 7 (Revoke privileges from one of the students) Revoke select, update on Gadget_Repair from student145; Question 8 (Revoke privileges from the other students) Revoke select, inserton Supplier_Laptops from student142;
  • 89. Aisling Fallon Higher Diploma in Computing 88 14. Transaction Processing Time Session1 (client1) Session2 (client2) Observations T1 Select Sum(Cost) From Gadget_Repair; Select Sum(Cost) From Gadget_Repair; Both Client1 and Client2 can see the the result-Sum(Cost) T2 Update Gadget_Repair Set Cost=Cost +10 Where Technician_Id=2002; Client1 has updated rows in the Gadget Repair table, no other clientcan update these rows until client1 completes the transcation
  • 90. Aisling Fallon Higher Diploma in Computing 89 T3 Select Sum(Cost) From Gadget_Repair; Select Sum(Cost) From Gadget_Repair; Here you can see Client1 update rows on the Gadget Repair table. Client 2 has not yet been updated. T4 Update Gadget_Repair Set Cost=Cost +10 Where Technician_Id=2002; Here you can see Client2 is blocked as the rows arelocked by Client1 T5 Select Sum(Cost) From Gadget_Repair; Select Sum(Cost) From Gadget_Repair; T6 Rollback; Now client2 update will be processed as the transaction is completed by client1 due to the rollback.Now Client1 updates arereversed whileclient2 is now updated.
  • 91. Aisling Fallon Higher Diploma in Computing 90 T7 Select Sum(Cost) From Gadget_Repair; Select Sum(Cost) From Gadget_Repair; Client1 will nowsees the original while client2 will seethe updates. T8 Rollback; T9 Select Sum(Cost) From Gadget_Repair; Select Sum(Cost) From Gadget_Repair; Now client1 and client2 will both have the same amount for Sum(Cost)
  • 92. Aisling Fallon Higher Diploma in Computing 91 TIME SESSION1 (CLIENT1) SESSION2 (CLIENT2) SESSION3 (CLIENT3) OBSERVATIONS T1 Select Sum(Cost) From Gadget_Repair; Select Sum(Cost) From Gadget_Repair; Select Sum(Cost) From Gadget_Repair; All clients will seethis result T2 Update Gadget_Repair Set Cost=Cost +10 Where Technician_Id=200 2;
  • 93. Aisling Fallon Higher Diploma in Computing 92 T3 Select Sum(Cost) From Gadget_Repair; Select Sum(Cost) From Gadget_Repair; Select Sum(Cost) From Gadget_Repair; This will haveclientone with the new update figureand client2 and 3 with the original figure T4 Update Gadget_Repair Set Cost=Cost +10 Where Technician_Id=20 02; This will notupdate as client1 updates arenot processed this will stay in waitingmode until client1 rollbacksor commits.
  • 94. Aisling Fallon Higher Diploma in Computing 93 T5 Select Sum(Cost) From Gadget_Repair; Select Sum(Cost) From Gadget_Repair; Select Sum(Cost) From Gadget_Repair; T6 Update Gadget_Repair Set Cost=Cost +10 Where Technician_Id=20 02;
  • 95. Aisling Fallon Higher Diploma in Computing 94 T7 Select Sum(Cost) From Gadget_Repair; Select Sum(Cost) From Gadget_Repair; Client2 and Client3 will notupdate as Client1 has not been commited or rollback. T8 Rollback; Rollback; Rollback;
  • 96. Aisling Fallon Higher Diploma in Computing 95 T9 Select Sum(Cost) From Gadget_Repair; Select Sum(Cost) From Gadget_Repair; Select Sum(Cost) From Gadget_Repair; The updates have been rolled back so now the 3 clients havethe same figure. T10 Update Gadget_Repair Set Cost=Cost +10 Where Technician_Id=200 2;
  • 97. Aisling Fallon Higher Diploma in Computing 96 T11 Select Sum(Cost) From Gadget_Repair; Select Sum(Cost) From Gadget_Repair; Select Sum(Cost) From Gadget_Repair; T12 Update Gadget_Repair Set Cost=Cost +10 Where Technician_Id=20 02; T13 Select Sum(Cost) From Gadget_Repair; Select Sum(Cost) From Gadget_Repair; Select Sum(Cost) From Gadget_Repair;
  • 98. Aisling Fallon Higher Diploma in Computing 97 T14 Commit; T15 Select Sum(Cost) From Gadget_Repair; Select Sum(Cost) From Gadget_Repair; Select Sum(Cost) From Gadget_Repair; When itis commited atclient1 the update then runs for client2. T16 Commit;
  • 99. Aisling Fallon Higher Diploma in Computing 98 T17 Select Sum(Cost) From Gadget_Repair; Select Sum(Cost) From Gadget_Repair; Select Sum(Cost) From Gadget_Repair; Client1 and Client2 have commited so therefore updates will occur for all threeclients.
  • 100. Aisling Fallon Higher Diploma in Computing 99