Lab-5 fp304 Jun-2013
Lab-5 fp304 Jun-2013
Lab-5 fp304 Jun-2013
F3038DATABASE SYSTEM
2010
LEARNING OUTCOMES
This Lab sheet encompasses activity 4B & 4C.
ACTIVITY 4B
DEPARTMENT
DEPT_NO DEPT_NAME DEPT_LOCATION
D01 JTMK CAMPUS A
D02 JKE CAMPUS A
D03 JPA CAMPUS B
D04 JP CAMPUS B
D05 JKM CAMPUS A
D06 JKA CAMPUS A
D07 JKP CAMPUS A
EMPLOYEE
EMP_ EMP_ EMP_ EMP_ EMP_ SALARY DEPT_ EMP_
NO FIRSTNAME LASTNAME PHONE HIREDATE NO ADDRESS
EMP10 AHMAD HAKIMI 01267470 01/01/20 20000 D01 TAMAN
00001 87 11 0.00 SRI
PUTRA,
BANTING
EMP10 JULIA JOHAN 01254323 01/04/20 50000 D01 TAMAN
00002 13 11 .00 KEMUNING
,IPOH
EMP10 SETH COHAN 01987678 09/02/20 20000 D03 TAMAN
00003 98 12 .00 BUDIMAN,
KANGAR
EMP10 RAYMOND LIM 01478394 03/06/20 40000 D05 TAMAN
00004 77 12 .00 ANGGERIK
,CHERAS
EMP10 HANITH EMELIO 01234576 03/06/20 20000 D05 TAMAN
00005 89 12 0.00 HILLCRES
T,KL
EMP10 SATHINI RAJU 01879928 03/06/20 70000 D02 TAMAN
00006 73 12 0.00 JAYA,
IPOH
DECEMBER
F3038DATABASE SYSTEM
2010
The first form doesn't specify the column names where the data will be inserted,
only their values:
The second form specifies both the column names and the values to be inserted:
Insert all the data below by using the pervious exercise on Lab 4
STUDENT
StudID StudName StudAddress StudBirthDate CourseID
IT101 Aminah Perak 19/10/1990 C1000
IT102 Joe Selangor 13/08/1990 C1000
IT103 Mona Perak 23/07/1991 C1000
IT104 Husna Melaka 09/05/1990 C1002
IT105 Lingling Melaka 07/07/1989 C1004
IT106 Maniam Penang 01/12/1989 C1003
COURSE
CourseID CourseName LectID
C1000 Software Development L1001
C1001 Artificial Intelegence L1003
C1002 Database L1002
C1003 Interactive Multimedia L1010
C1004 Networking L1005
DEPARTMENT
DepartID DepartName
D1000 Software Engineering
D1001 Industrial Computing
D1002 Comp System & Comm
D1003 Interactive Multimedia
D1004 Management
DECEMBER
F3038DATABASE SYSTEM
2010
LECTURER
LectID LectName LectTelNo DepartID
L1001 Mokhsin 0178908767 D1000
L1002 Sheima 0192299090 D1000
L1003 Raju 0101989909 D1001
L1004 Zulkifli 0123984902 D1000
L1005 Rahmad 0145667389 D1002
L1006 Naina 0143662738 D1001
L1007 Junaida 0135557728
L1008 Hamid D1004
L1009 Chong
L1010 Sam D1003
SUBJECT
SubID SubName
SC100 Programming Technique
SC101 System Development
SC102 Database
SC103 Object Oriented
SC104 Multimedia System
SC105 Logic Programming
STUD_SUB
StudSubID StudID SubID Mark Grade
SS100 IT101 SC100 60 B
SS101 IT102 SC100 85 A
SS102 IT103 SC100 90 A
SS103 IT104 SC103 76 B
SS104 IT105 SC103 56 C
SS105 IT106 SC104 65 B
SS106 IT101 SC104 45 D
SS107 IT102 SC104 98 A
SS108 IT103 SC101 67 B
SS109 IT104 SC101 54 C
SS110 IT105 SC101 87 A
SS111 IT106 SC101 83 A
b) UPDATE Statement
UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value
UPDATE EMPLOYEE
SET EMP_ADDRESS='TAMAN SRI PUTRA,BANTING'
WHERE EMP_NO='EMP1000001';
DECEMBER
F3038DATABASE SYSTEM
2010
c) DELETE Statement
SELECT column_name(s)
FROM table_name
SELECT DEPT_NO,DEPT_NAME
FROM DEPARTMENT;
SELECT *
FROM DEPARTMENT;
e) SELECT-FROM-WHERE Statement
SELECT column_name(s)
FROM table_name
WHERE column_name operator value
SELECT DEPT_NO,DEPT_NAME
FROM DEPARTMENT
WHERE DEPT_NO = 'D01';
DECEMBER
F3038DATABASE SYSTEM
2010
Comparison Operators:
f) LIKE
SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern
SELECT DEPT_NO,DEPT_NAME
FROM DEPARTMENT
WHERE DEPT_NAME LIKE 'J%';
This SQL statement will match any department name that start with 'J'. Strings must be in single
quotes. Or you can specify,
SELECT DEPT_NO,DEPT_NAME
FROM DEPARTMENT
WHERE DEPT_NAME LIKE '%K';
This statement will match any last names that end in a 'K'.
vii) ORDER BY
SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC|DESC
SELECT DEPT_NO,DEPT_NAME
FROM DEPARTMENT
ORDER BY DEPT_NO ASC
(OR)
SELECT DEPT_NO,DEPT_NAME
FROM DEPARTMENT
ORDER BY DEPT_NO DESC
viii) IN
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1,value2,...)
SELECT DEPT_NO,DEPT_NAME
FROM DEPARTMENT
WHERE DEPT_NAME IN ('JTMK');
DECEMBER
F3038DATABASE SYSTEM
2010
ix) DISTINCT
x) AND Operator
The AND operator displays a record if both the first condition and the second condition are true.
xi) OR Operator
The OR operator displays a record if either the first condition or the second condition is true.
xii) JOIN
JOIN: Return rows when there is at least one match in both tables
SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.column_name=table_name2.column_name
LEFT JOIN: Return all rows from the left table, even if there are no matches in the
right table
SELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2
ON table_name1.column_name=table_name2.column_name
RIGHT JOIN: Return all rows from the right table, even if there are no matches in the
left table
SELECT column_name(s)
FROM table_name1
RIGHT JOIN table_name2
ON table_name1.column_name=table_name2.column_name
FULL JOIN: Return rows when there is a match in one of the tables
SELECT column_name(s)
FROM table_name1
FULL JOIN table_name2
ON table_name1.column_name=table_name2.column_name
NESTED QUERIES: Return rows when there is a match in one of the tables
EXERCISES (CLO3)
iv. Select the Lecturer who phone num start with “014”. (2m)
Select S.StudName,C.CourseName
From Student S, Course C
Where S.CourseID=C.CourseID;
Select S.StudName,C.CourseName,L.LectName
From Student S, Course C ,Lecturer
Where S.CourseID=C.CourseID and
C.LectID=L.LectID
vii. Select student name, subject name, gred and mark ,which mark >=55
(5m)
viii. Write SQL syntax to show a sum of student mark for each subject . (3m)
ix. Write SQL syntax to show lecturer name, department name where the lecturer
are from Software Engineering department. (3m)
DECEMBER
F3038DATABASE SYSTEM
2010
NOTES
DECEMBER
F3038DATABASE SYSTEM
2010
1.