Program Basis data
Laporan Praktikum
Disusun Oleh:
Agni Radityo Zauhair 2170231065
Fakultas Teknik Prodi Informatika
2021
Laporan Akhir Praktikum Basis Data
Source code:
Mysql -u root -p (enter) Password: (enter)
Source code:
SELECT VERSION (), CURRENT_DATE;
Praktikum Modul 1
2.
3.
4. Ketik perintah di atas (no 3) Source code:
a. Dengan huruf kecil semua select version (), current_date;
Source code:
SELECT SIN (PI()/4), (4+1)*5;
Source code:
SELECT VERSION (); SELECT NOW ();
7.
Source code:
SELECT (enter)
b. Dengan huruf besar semua
5.
6.
SELECT VERSION(), CURRENT_DATE;
Source code:
SELECT -> USER () -> \c
Source code:
SELECT USER ()
b. Langkah kedua Source code:
SELECT USER() (enter) 8.
9.
a. Langkah pertama
-> USER (), CURRENT_DATE;
Source code:
SHOW DATABASES;
Source code:
USE TEST;
Source code:
USE COBA;
13.
Source code:
CREATE DATABASE coba;
USE coba;
10.
11.
12.
-> ;
Source code:
CREATE TABLE buku (
-> kodebuku CHAR(5) Primary Key NOT NULL, -> judul VARCHAR(25) NOT NULL,
-> pengarang VARCHAR(20), -> penerbit VARCHAR(15), -> kategori VARCHAR(15));
Source code:
DESC buku;
Source code:
CREATE TABLE mahasiswa ( nim int(8) Primary Key,
nama_mhs CHAR(50),
sex Enum (‘L’,’P’) DEFAULT ‘L’, 14.
15.
Praktikum Modul 2
B)
a. Tabel Mahasiswa SHOW TABLES;
Source code:
CREATE TABLE prodi (
Kode_prodi CHAR(6) Primary Key, Nama_prodi CHAR(30));
b. Tabel Prodi alamat VARCHAR(50),
kota VARCHAR(20) DEFAULT ‘Jakarta’, asal_sma CHAR(30),
nohp VARCHAR(12), Login CHAR(20), Pass CHAR(20), Umur Integer,
Kode_prodi CHAR(6), foreign key (kode_prodi) references prodi(kode_prodi));
Source code:
CREATE TABLE mata_kuliah ( mk_id CHAR(10) Primary Key, nama_mk CHAR(50),
Jumlah_jam Float (4,2), Sks Integer);
Source code:
CREATE TABLE ruang (
ruang_id CHAR(3) Primary Key, nama_ruang CHAR(20),
Kapasitas Integer);
e. Tabel Dosen Source code:
CREATE TABLE dosen (
Nik int(11) Primary Key AUTO_INCREMENT, Inisial CHAR(3) UNIQUE KEY,
nama_dosen CHAR(50),
Status Enum (‘T’,’LB’) DEFAULT ‘T’, c. Tabel Mata_kuliah
d. Tabel Ruang
Source code:
CREATE TABLE mengajar (
id_mengajar Int Primary Key AUTO_INCREMENT, jam_ke Integer,
Hari VARCHAR(10), mk_id CHAR(10),
foreign key fk1 (mk_id) references mata_kuliah (mk_id), Inisial CHAR(3),
foreign key fk2 (Inisial) references dosen (Inisial), Kode_prodi CHAR(6),
foreign key fk3 (Kode_prodi) references prodi (Kode_prodi), ruang_id CHAR(3),
f. Tabel Mengajar
Sex Enum (‘L’,’P’) DEFAULT ‘L’, Agama CHAR(20),
Login CHAR(20), Pass CHAR(20),
Alamat VARCHAR(50),
Kota VARCHAR(20) DEFAULT ‘Jakarta’, Email VARCHAR(50),
Nohp VARCHAR(12), Salary Int);
Source code:
CREATE TABLE nilai ( Nim Int,
foreign key fk5 (Nim) references mahasiswa (Nim), mk_id CHAR(10),
foreign key fk6 (mk_id) references mata_kuliah (mk_id), Kode_prodi CHAR(6),
foreign key fk7 (Kode_prodi) references prodi (Kode_prodi), Inisial CHAR(3),
foreign key fk8 (Inisial) references dosen (Inisial), Nilai_UTS Integer,
Nilai_UAS Integer, Nilai_akhir Integer);
g. Tabel Nilai
foreign key fk4 (ruang_id) references ruang (ruang_id));
Source code:
ALTER TABLE mahasiswa ADD Agama VARCHAR(10);
D) Tambahkan kolom Rid di awal kolom pada tabel ruang Source code:
C) Tambahkan kolom Agama di akhir kolom pada tabel mahasiswa
Source code:
ALTER TABLE nilai ADD grade CHAR AFTER Inisial;
F) Ubah nama tabel Mahasiswa menjadi Student Source code:
E) Sisipkan kolom Grade pada tabel nilai setelah kolom Inisial ALTER TABLE ruang ADD rid CHAR(10) FIRST;
G) Jadikan Nim sebagai primary key di tabel mahasiswa Source code:
CREATE TABLE mahasiswa ( nim int(8) Primary Key,
nama_mhs CHAR(50),
sex Enum (‘L’,’P’) DEFAULT ‘L’, alamat VARCHAR(50),
kota VARCHAR(20) DEFAULT ‘Jakarta’, asal_sma CHAR(30),
nohp VARCHAR(12), Login CHAR(20), Pass CHAR(20), Umur Integer,
Kode_prodi CHAR(6), foreign key (kode_prodi)
ALTER TABLE mahasiswa RENAME TO student;
Source code:
use db_universitas;
Praktikum Modul 3
1. Aktifkan database db_universitas references prodi (kode_prodi));
Source code:
INSERT into student VALUES ('13120001', 'Anton', 'L', 'Jl. Jenderal Sudirman No.12', 'Brebes', 'SMA 1 Brebes', '081574568921', 'anton', 'anton', '18', ‟S1 IF‟), ('13120002', 'Bany', 'L', 'Jl. Letnan Jenderal Sutoyo No.15', 'Tegal', 'SMA 1 Tegal', '081574568346', 'bany', 'bany', '18', ‟S1 IF‟), ('13120003', 'Cika', 'P', 'Jl. Jenderal Sudirman No.38', 'Purwokerto', 'SMA 4 Purwokerto', '081874568000', 'cika','cika', '17',‟S1 IF‟), ('13120004', 'Doni', 'L', 'Jl. Pahlawan No. 4', 'Brebes', 'SMK N 1 Adiwerna', '081674568900', 'doni', 'doni', '19', ‟S1 TT‟),
('13120005', 'Eka', 'P', 'Jl. Buntu No.01', 'Pekalongan', 'SMA 3 Pekalongan', '088874568945', 'eka', 'eka', '17', ‟S1 TT‟), ('13120006', 'Fendi', 'L', 'Jl. Kemerdekaan No.15', 'Pemalang', 'SMA 1 Pemalang', '081257456892', 'fendi', 'fendi', '18', ‟D3 TT‟), ('13120007', 'Galuh', 'P', 'Jl. Mawar Putih', 'Brebes', 'SMA 2 Brebes', '081273458921', 'galuh', 'galuh', '18', ‟D1 PR‟);
select*from student;
2. Insert records/data to table student.
3. Insert records/data to table dosen.
Source code:
INSERT into dosen VALUES ('1', 'DS', 'Didi Supriyadi', 'T', 'L', 'Islam', 'didi', 'didi', 'Jl.
Sunan Bonang RT 01/03 Banjaranyar', 'Brebes', '[email protected]',
'085743622236', '5000000'), ('2',' STS', 'Sisilia Thya Safitri', 'T', 'P', 'Kristen', 'sisil', 'sisil', 'Jl.
Antah berantah RT 001/005 Banjarbaru', 'Jambi', '[email protected]', '085875997546', '5000000'), ('3', 'TW', 'Tenia Wahyuningrum', 'T', 'P', 'Islam', 'tenia', 'tenia', 'Jl. Ledug RT 01/03 Banyumas', 'Purwokerto', '[email protected]', '085746795432', '5500000'), ('4', 'DJ', 'Dwi Januarita AK', 'T', 'P', 'Islam', 'ita', 'ita', 'Jl. Sunan Kudus RT 01/03 Jekulo', 'Kudus', '[email protected]', '085852829809', '4000000'), ('5', 'IS', 'Irwan Susanto', 'T', 'L', 'Islam', 'irwan', 'irwan', 'Jl. Tanjung RT 01/03 Banyumas', 'Purwokerto', '[email protected]', '081327593529', '5500000'), ('6', 'SL', 'Sarlan', 'LB', 'L', 'Islam', 'sarlan', 'sarlan', 'Jl. Jend.
SudirmanRT 01/03 Banyumas', 'Purwokerto', '[email protected]', '081634462738', '3500000'), ('7', 'DN', 'Daniel', 'LB', 'L', 'Kristen', 'daniel', 'daniel', 'Jl. Tanjung RT 04/07 Banyumas', 'Purwokerto', '[email protected]', '081365047309', '4500000');
Source code:
INSERT INTO prodi VALUES (‘S1 IF’, ‘informatika’), (‘S1 TT’, ‘sistem informasi’), (‘D3 TT’, ‘sipil’), (‘D1 PR’, ‘elektro’);
select * from prodi;
Source code:
INSERT INTO mata_kuliah VALUES (‘IT’, ‘Matriks’, ‘40’, ‘3’), (‘TS’, ‘Pembangunan’,
’26.66’, ‘2’), (‘TE’, ‘Fisika’, ’26.66’, ‘2’), (‘SI’, ‘Kalkulus’, ‘40’, ‘3’);
select * from mata_kuliah;
C. Insert records/data to table ruang.
Source code:
INSERT INTO ruang VALUES (‘01’, ‘IT’, ‘informatika’, ‘35’), (‘02’, ‘SPL’, ‘sipil’, ‘30’), (‘03’, ‘SI’, ‘sistem informasi’, ‘30’), (’04’, ‘TE’, ‘elektro’, ‘25’);
4. Lakukan insert data ke tabel – tabel lain sesuai dengan field, type data dan panjang datanya masing – masing tabel.
A. Insert records/data to table prodi.
B. Insert records/data to table mata_kuliah.
select * from dosen;
Source code:
INSERT INTO mengajar VALUES (‘8002’, ‘2’, ‘kamis’, ‘DS’, ‘D1 PR’, ‘TE’), (‘8003’, ‘1’,
‘selasa’, ‘DN’, ‘S1 TT’, ‘SI’), (‘8004’, ‘3’, ‘rabu’, ‘SL’, ‘D3 TT’, ‘SPL’), (‘8005’, ‘1’,
‘senin’, ‘DJ’, ‘S1 IF’, ‘IT’);
select*from mengajar;
E. Insert records/data to table nilai.
Source code:
INSERT INTO nilai VALUES (‘13120001’ ‘IT’, ‘S1 IF’, ‘DJ’, ‘A’, ‘85’, ‘90’, ‘92’), (‘13120002’ ‘IT’, ‘S1 IF’, ‘DJ’, ‘A’, ‘95’, ‘87’, ‘92’), (‘13120003’ ‘IT’, ‘S1 IF’, ‘DJ’, ‘B’,
‘75’, ‘80’, ‘82’), (‘13120004’ ‘SI’, ‘S1 TT’, ‘DN’, ‘A’, ‘85’, ‘95’, ‘98’), (‘13120005’ ‘SI’,
‘S1 TT’, ‘DN’, ‘A’, ‘88’, ‘90’, ‘95’), (‘13120006’ ‘TS’, ‘D3 TT’, ‘SL’, ‘B’, ‘75’, ‘80’, ‘82’), (‘13120007’ ‘TE’, ‘D1 PR’, ‘DS’, ‘A’, ‘90’, ‘90’, ‘95’);
D. Insert records/data to table mengajar.
select * from ruang;
Source code:
select * from student;
6. Ubah data nama mahasiswa Anton menjadi Dino Source code:
UPDATE student
SET nama_mhs = ‘Dino’
WHERE nim = 13120001;
5. Tampilkan semua isi record tabel Student select*from nilai;
Source code:
Select*from student WHERE nim = 13120001;
Source code:
UPDATE student
SET nama_mhs = ‘Anton’
WHERE nim = 13120001;
select*from student;
9. Tampilkan record/data mahasiswa yang usianya lebih dari atau sama dengan 17 tahun Source code:
7. Tampilkan satu baris data dengan nama Dino
8. Hapus data mahasiswa yang bernama Dino Select*from student;
Source code:
select*from dosen WHERE Nik = 1 or Nik = 5 or Nik =6;
10. Tampilkan semua data dosen yang berjenis kelamin Pria dan agama Islam
11. Tampilkan sebuah nama dosen yang berstatus Tetap dengan agamanya Islam atau dosen Luar Biasa (LB) dengan agama Kristen
Praktikum Modul 4
C.
Source code:
select*from dosen;
select*from dosen WHERE Nik = 1 or Nik = 3 or Nik = 4 or Nik = 5 or Nik = 7;
select*from student WHERE umur >= 17;
Tampilkan mahasiswa laki – laki yang berasal dari Purwokerto.
Source code:
D. Tampilkan mahasiswa wanita dari Purwokerto dan Jakarta.
E. Tampilkan mahasiswa yang bukan berasal dari Purwokerto.
F. Tampilkan seluruh mahasiswa menurut abjad dari Z – A.
G.
Source code:
select nama_mhs, nim, kota FROM student ORDER BY nama_mhs DESC;
Source code:
select nama_mhs, sex, kota FROM student WHERE kota NOT LIKE 'Purwokerto';
Source code:
select nama_mhs, sex, kota FROM student WHERE sex LIKE 'P' AND kota LIKE 'Purwokerto' OR 'Jakarta';
select nama_mhs, sex, kota FROM student WHERE sex LIKE'L' AND kota LIKE 'Purwokerto';
Berasal dari kota mana saja mahasiswa yang ada? (hilangkan data kota yang duplikasi).
Source code:
I. Tampilkan daftar nama mahasiswa, kode prodi dan umur yang usianya tidak diantara 18 dan 19.
J. Tampilkan nama dosen yang jumlah gajinya antara 4.500.000 sampai 5.500.000.
K. Cari nama mahasiswa yang tempat tinggalnya dimulai dengan ‘P’.
Source code:
Source code:
select nama_dosen, salary FROM dosen WHERE salary BETWEEN 4500000 and 5500000;
Source code:
select nama_mhs, kode_prodi, umur FROM student WHERE umur NOT BETWEEN 18 and 19;
select distinct kota FROM student;
L. Carilah nama mahasiswa yang tempat tinggalnya ditengahnya terdapat kata ‘kalong’
M. Carilah nama dosen, inisial yang inisial namanya diawali dengan huruf ‘S’.
Source code:
select nama_dosen, inisial FROM dosen WHERE inisial LIKE 'S_';
select nama_dosen, inisial FROM dosen WHERE inisial LIKE ' S ';
Source code:
select nama_mhs, kota FROM student WHERE kota like '%kalong%';
select nama_mhs, kota FROM student WHERE kota LIKE 'P%';
Tugas 1 – DATABASE Rumah Sakit
1. CREATE DATABASES DB_RS
Source Code : CREATE DATABASE db_rs;
Hasil :
2. CREATE TABLE Dokter
Source Code : create table dokter (id_dokter int(10), nama_dokter VARCHAR(50), spesialis VARCHAR(50));
Hasil :
3. CREATE TABLE Pasien Source Code :
CREATE TABLE pasien (id_pasien CHAR(10), nama_pasien VARCHAR(50), umur INT(10), keluhan_pasien VARCHAR(50), id_dokter CHAR(10), kode_obat
CHAR(10));
Hasil :
4. CREATE TABLE
Obat Source Code :
create table obat (kode_obat int(10), nama_obat varchar(50), jenis_obat varchar(50), masa_kadaluarsa date, harga int(10));
Hasil :
Tugas 2 – DATABASE Rumah Sakit
(Contoh Gambar : FOREIGN
KEY)
Menampilkan nama pasien, umur, dan keluhan pasien yang berumur 27 :
Source code : SELECT nama_pasien,keluhan_pasien, umur FROM pasien WHERE umur LIKE '27';
Hasil :
Tampilkan id dokter, nama dokter, poli spesialis dari tabel dokter dengan ketentuan yang ditampilkan hanya yang poli THT dan Penyakit Dalam :
Source code :
SELECT id_dokter, nama_dokter, spesialis FROM dokter WHERE spesialis IN ("THT","Penyakit Dalam");
Hasil :
Tampilkan nama obat, jenis obat, masa kadaluarsa dari tabel obat dengan ketentuan selain diare :
Source code :
SELECT nama_obat, jenis_obat, masa_kadaluarsa FROM obat WHERE jenis_obat NOT IN("Diare");
Hasil :
Menampikan lebih dari 3 tabel :
Source code : SELECT pasien.id_pasien, pasien.nama_pasien,
pasien.Keluhan_pasien, pasien.id_dokter, dokter.nama_dokter, dokter.spesialis, pasien.Kode_obat, obat.nama_obat, obat.jenis_obat, obat.harga FROM pasien, dokter, obat WHERE pasien.id_dokter=dokter.id_dokter AND
pasien.Kode_obat=obat.Kode_obat;
Hasil :
Tampilkan tabel obat dimana urutan harga dari tabel obat dimulai dari yang terkecil ke terbesar :
Source code : SELECT kode_obat, nama_obat,
jenis_obat, masa_kadaluarsa, harga, id_apoteker FROM obat ORDER BY harga;