0% found this document useful (0 votes)
14 views14 pages

Praktikum 1 Manajemen Basis Data - SQL Basic

untuk memenuhi tugas matakuliah Manajemen Basis Data Universitas Negeri Surabaya

Uploaded by

Gerin Azharani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views14 pages

Praktikum 1 Manajemen Basis Data - SQL Basic

untuk memenuhi tugas matakuliah Manajemen Basis Data Universitas Negeri Surabaya

Uploaded by

Gerin Azharani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

MANAJEMEN BASIS DATA

PRAKTIKUM 1 : SQL BASIC

DOSEN PENGAMPU : WIYLI YUSTANTI, S.Si., M.KOM.

DISUSUN OLEH:
22051214155
GERIN AZHARANI

PROGRAM STUDI S1 SISTEM INFORMASI


FAKULTAS TEKNIK
UNIVERSITAS NEGERI SURABAYA
2023
A. Tugas
Exercise
8.16. Specify the following queries on the COMPANY relational database schema shown in
Figure 5.5 using the relational operators discussed in this chapter. Also show the result of
each query as it would apply to the database state in Figure 5.6.
a. Retrieve the names of all employees in department 5 who work more
than 10 hours per week on the ProductX project.
b. List the names of all employees who have a dependent with the same first
name as themselves.
c. Find the names of all employees who are directly supervised by ‘Franklin
Wong’.
d. For each project, list the project name and the total hours per week (by all
employees) spent on that project.
e. Retrieve the names of all employees who work on every project.
f. Retrieve the names of all employees who do not work on any project.
g. For each department, retrieve the department name and the average sal-
ary of all employees working in that department.
h. Retrieve the average salary of all female employees.
i. Find the names and addresses of all employees who work on at least one project located
in Houston but whose department has no location in Houston.
j. List the last names of all department managers who have no dependents.

8.18. Consider the LIBRARY relational database schema shown in Figure 8.14, which is used
to keep track of books, borrowers, and book loans. Referential integrity constraints are shown
as directed arcs in Figure 8.14, as in the notation of Fig- ure 5.7. Write down relational
expressions for the following queries:
a. How many copies of the book titled The Lost Tribe are owned by the library branch
whose name is ‘Sharpstown’?
b. How many copies of the book titled The Lost Tribe are owned by each library branch?
c. Retrieve the names of all borrowers who do not have any books checked out.
d. For each book that is loaned out from the Sharpstown branch and whose Due_date is
today, retrieve the book title, the borrower’s name, and the borrower’s address.
e. For each library branch, retrieve the branch name and the total number of books loaned
out from that branch.
f. Retrieve the names, addresses, and number of books checked out for all borrowers who
have more than five books checked out.
g. For each book authored (or coauthored) by Stephen King, retrieve the title and the
number of copies owned by the library branch whose name is Central.
B. Hasil
1. Exercise 8.16
Scema database

Sintak SQL dan Output


a. Sintak SQL
SELECT E.*
FROM EMPLOYEE E
INNER JOIN WORKS_ON W ON E.Ssn = W.Essn
INNER JOIN PROJECT P ON W.Pno = P.Pnumber
WHERE P.Pname = 'ProductX' AND E.Dno = 5 AND W.Hours > 10;
Output

b. Sintak SQL
SELECT DISTINCT E1.Fname, E1.Lname
FROM EMPLOYEE E1
INNER JOIN DEPENDENT D1 ON E1.Ssn = D1.Essn
WHERE CONCAT(E1.Fname, ' ', E1.Lname) = D1.Dependent_name;

Output

c. Sintak SQL
SELECT E.Fname, E.Lname
FROM EMPLOYEE E
WHERE E.Super_ssn = '333445555';

Output

d. Sintak SQL
SELECT P.Pname, SUM(W.Hours) AS Total_Jam_Perkiraan
FROM PROJECT P
LEFT JOIN WORKS_ON W ON P.Pnumber = W.Pno
GROUP BY P.Pname
ORDER BY P.Pname;
Output

e. Sintak SQL
SELECT DISTINCT E.Fname, E.Lname
FROM EMPLOYEE E
WHERE E.Ssn IN (
SELECT DISTINCT W.Essn
FROM WORKS_ON W
WHERE W.Pno IN (
SELECT DISTINCT P.Pnumber
FROM PROJECT P
)
);

Output
f. Sintak SQL
SELECT Fname, Lname
FROM EMPLOYEE
WHERE Ssn NOT IN (
SELECT Essn
FROM WORKS_ON
);

Output

g. Sintak SQL
SELECT D.Dname AS Nama_Departemen, AVG(E.Salary) AS Gaji_Rata_Rata
FROM DEPARTMENT D
INNER JOIN EMPLOYEE E ON D.Dnumber = E.Dno
GROUP BY D.Dname
ORDER BY D.Dname;

Output

h. Sintak SQL
SELECT AVG(SALARY)
FROM EMPLOYEE
WHERE SEX='F';
Output

i. Sintak SQL
select fname, lname, address
from employee, project, dept_locations
where plocation = 'Houston' and dlocation <> 'Houston' ;

Output
j. Sintak SQL
SELECT Lname
FROM EMPLOYEE
WHERE NOT EXISTS (SELECT * FROM DEPENDENT WHERE Ssn=Essn)
AND
EXISTS (SELECT * FROM DEPARTMENT WHERE Ssn=Mgr_ssn);

Output

2. Exercise 8.18
Scema
Sintak SQL dan Output
a. Sintak SQL
SELECT bc.No_Of_Copies
FROM BOOK b, BOOK_COPIES bc, LIBRARY_BRANCH bl
WHERE b.Book_id = bc.Book_id AND bc.Branch_id = bl.Branch_id AND
Title='The Lost Tribe' AND Branch_name='Sharpstown';

SELECT No_Of_Copies
FROM ((BOOK NATURAL JOIN BOOK_COPIES ) NATURAL JOIN
LIBRARY_BRANCH )
WHERE Title='The Lost Tribe' AND Branch_name='Sharpstown';

Output

b. Sintak SQL
SELECT Branch_name, No_Of_Copies
FROM ((BOOK NATURAL JOIN BOOK_COPIES ) NATURAL JOIN
LIBRARY_BRANCH )
WHERE Title='The Lost Tribe';

Output

c. Sintak SQL
SELECT Name
FROM BORROWER B
WHERE Card_no NOT IN (SELECT Card_no FROM BOOK_LOANS );

Output

d. Sintak SQL
SELECT B.Title, R.Name, R.Address
FROM BOOK B, BORROWER R, BOOK_LOANS BL, LIBRARY_BRANCH LB
WHERE LB.Branch_name='Sharpstown' AND LB.Branch_id=BL.Branch_id AND
BL.Due_date='today' AND BL.Card_no=R.Card_No AND BL.Book_id=B.Book_id

Output
e. Sintak SQL
SELECT L.Branch_name, COUNT(*)
FROM LIBRARY_BRANCH L, BOOK_LOANS BL
WHERE BL.Branch_id = L.Branch_id
GROUP BY L.Branch_name;

Output

f. Sintak SQL
SELECT B.Name, B.Address, COUNT(*)
FROM BORROWER B, BOOK_LOANS L
WHERE B.Card_no = L.Card_no
GROUP BY B.Card_no, B.Name, B.Address
HAVING COUNT(*) > 5;

Output

g. Sintak SQL
SELECT Title, No_Of_Copies
FROM (((BOOK_AUTHORS NATURAL JOIN BOOK) NATURAL JOIN
BOOK_COPIES) NATURAL JOIN LIBRARY_BRANCH)WHERE
Author_Name='Stephen King' AND Branch_name='Central';

Output

C. Kesimpulan
SQL (Structured Query Language) merupakan bahasa pemograman khusus yang
digunakan untuk manjemen data. SQL berupa perintah sederharana yang biasa disebut
dengan query. Query memegang peranan penting sebagai instruksi-intruksi yang
berguna dalam pengelolaan database. Berikut merupakan beberapa perintah SQL yang
sering digunakan
Perintah/Fungsi Fungsi
SELECT Menampilkan data dari tabel
INSERT Menyisipkan atau memasukan data baru
ke dalam tabel
UPDATE Memperbaharui data lama menjadi data
baru
DELETE Menghapus data dari tabel
WHERE Menentukan kriteria data yang akan di
tampilkan
ORDER BY Mengurutkan data
AVG Memperoleh nilai rata rata
MAX Memperoleh nilai terbesar
MIN Memperoleh nilai terkecil
AND, OR, NOT Memfilter nilai berdasarkan suatu kondisi
GRUP BY Mengelompokan data
HAVING Memfilter data yang sudah dikelompokan
INER JOIN Menggabungkan beberapa tabel dan
mengambil nilai yang sama diantara kedua
tabel
LEFT JOIN Menggabungkan tabel dan menampilkan
semua data (kiri) pada tabel yang tidak
berhubungan sedangkan data yang kosong
akan bernilai NULL
CONCAT Menggabungkan beberapa nilai string
yang ditentukan
EXISTS Penghubung operator kondisional
Referensi

Aristo Ari Kuncoro S.Kom, M. (2022, Mei 20). Retrieved September 12, 2023, from https://teknik-
informatika-s1.stekom.ac.id: https://teknik-informatika-
s1.stekom.ac.id/informasi/baca/Panduan-SQL-Fungsi-Cara-Kerja-serta-Perintah-
Dasarnya/f66c453172e736ab3686c4f9281914e1ea702511

Eri Mardiani, N. R. (2016). Kumpulan Latihan SQL. Jakarta: PT Elex Media Komputindo.

Rahimi Fitri, S. M. (2020). Pemograman Basis Data Menggunakan MySQL. Yogyakarta: POLIBAN
PRESS Anggota APPTI (Asosiasi Penerbit Perguruan Tinggi Indonesia).

You might also like