Anda di halaman 1dari 10

TUGAS AKHIR

SISTEM MANAGEMEN BASIS DATA

Disusun oleh:
Nama
: Dika Priska Prastika
No. MHS : 131051016
Kelompok : RB4

JURUSAN TEKNIK INFORMATIKA


INSTITUT SAINS DAN TEKNOLOGI AKPRIND
YOGYAKARTA 2014

Buat Database
mysql> create database responsi_131051016;
Query OK, 1 row affected (0.12 sec)
mysql> use responsi_131051016;
Database changed

1. Buat Table DVD, Pelanggan, Pegawai, dan Transaksi


a. Table DVD
mysql> create table DVD(id_dvd varchar(10) primary key, judul_dvd varchar(50),
genre_dvd varchar(20), harga_dvd varchar(10));
Query OK, 0 rows affected (0.08 sec)
mysql> desc DVD;
+-----------+-------------+------+-----+---------+-------+
| Field | Type
| Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| id_dvd | varchar(10) | NO | PRI | NULL |
|
| judul_dvd | varchar(50) | YES | | NULL |
|
| genre_dvd | varchar(20) | YES | | NULL |
|
| harga_dvd | varchar(10) | YES | | NULL |
|
+-----------+-------------+------+-----+---------+-------+
4 rows in set (0.03 sec)
b. Table Pelanggan
mysql> create table Pelanggan(id_user varchar(8) primary key, nama_user varchar(50),
alamat_user varchar(50), no_identitas varchar(20), jenis_identitas varchar(10),
no_telp_user varchar(12));
Query OK, 0 rows affected (0.03 sec)
mysql> desc Pelanggan;
+-------------------+---------------+-------+------+----------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+-------------------+---------------+-------+------+----------+-------+
| id_user
| varchar(8) | NO | PRI | NULL |
|
| nama_user
| varchar(50) | YES |
| NULL |
|
| alamat_user
| varchar(50) | YES |
| NULL |
|
| no_identitas | varchar(20) | YES |
| NULL |
|
| jenis_identitas | varchar(10) | YES |
| NULL |
|
| no_telp_user | varchar(12) | YES |
| NULL |
|
+-------------------+---------------+-------+------+----------+-------+
6 rows in set (0.09 sec)

c. Table Pegawai
mysql> create table pegawai(id_peg varchar(8) primary key, nama_peg varchar(50),
alamat_peg varchar(50), no_telp_peg varchar(12));
Query OK, 0 rows affected (0.09 sec)
mysql> desc pegawai;
+-------------+-------------+------+-----+---------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| id_peg
| varchar(8) | NO | PRI | NULL |
|
| nama_peg | varchar(50) | YES | | NULL |
|
| alamat_peg | varchar(50) | YES | | NULL |
|
| no_telp_peg | varchar(12) | YES | | NULL |
|
+-------------+-------------+------+-----+---------+-------+
4 rows in set (0.08 sec)
d. Table Transaksi
mysql> create table transaksi(no_transaksi varchar(10) primary key, id_user varchar(8),
id_dvd varchar(10), id_pegawai varchar(8), foreign key(id_user) references
Pelanggan(id_user), foreign key(id_dvd) references DVD(id_dvd), foreign
key(id_pegawai) references pegawai(id_peg) on delete cascade on update cascade);
Query OK, 0 rows affected (0.11 sec)
mysql> desc transaksi;
+--------------+-------------+------+-----+---------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| no_transaksi | varchar(10) | NO | PRI | NULL |
|
| id_user
| varchar(8) | YES | MUL | NULL |
|
| id_dvd
| varchar(10) | YES | MUL | NULL |
|
| id_pegawai | varchar(8) | YES | MUL | NULL |
|
+--------------+-------------+------+-----+---------+-------+
4 rows in set (0.03 sec)
2. Input Data Seluruh Table Menggunakan PROCEDURE
a. Procedure DVD
mysql> create procedure isi( in id_dvd varchar(10), judul_dvd varchar(50), genre_dvd
varchar(20), harga_dvd varchar(20))
-> begin
-> insert into DVD values(id_dvd, judul_dvd, genre_dvd, harga_dvd);
-> end //
Query OK, 0 rows affected (0.19 sec)
mysql> delimiter ;

mysql> call isi("M-101-AC","Expendables 2","Action","80000");


Query OK, 1 row affected (0.08 sec)
mysql> call isi("M-201-CM","Ted","Comedy","80000");
Query OK, 1 row affected (0.04 sec)
mysql> call isi("I-301-HR","Pocong Ngesot","Horror","50000");
Query OK, 1 row affected (0.00 sec)
mysql> call isi("I-401-DR","Cinta Kimcil","Drama","50000");
Query OK, 1 row affected (0.02 sec)
mysql> call isi("K-501-DR","Dream High","Drama","250000");
Query OK, 1 row affected (0.00 sec)
mysql> select *from DVD;
+----------+---------------+-----------+-----------+
| id_dvd | judul_dvd | genre_dvd | harga_dvd |
+----------+---------------+-----------+-----------+
|
| NULL
| NULL | NULL |
| I-301-HR | Pocong Ngesot | Horror | 50000 |
| I-401-DR | Cinta Kimcil | Drama | 50000 |
| K-501-DR | Dream High | Drama | 250000 |
| M-101-AC | Expendables 2 | Action | 80000 |
| M-201-CM | Ted
| Comedy | 80000 |
+----------+---------------+-----------+-----------+
6 rows in set (0.00 sec)
b. Procedure Pelanggan
mysql> delimiter //
mysql> create procedure isipelanggan(in id_user varchar(8), nama_user varchar(50),
alamat_user varchar(50), no_identitas varchar(20),jenis_identitas varchar(10),
no_telp_user varchar(12))
-> begin
-> insert into Pelanggan values(id_user, nama_user, alamat_user,
no_identitas,jenis_identitas, no_telp_user);
-> end //
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ;
mysql> call isipelanggan("PEL-0000","No Name","No Add","No Numb","No","No");
Query OK, 1 row affected (0.03 sec)
mysql>
call
isipelanggan("PEL-0001","Ayu
Dewi","Jl.
Mantingan
No
89","109023004,"KTM","081233455488");
Query OK, 1 row affected (0.03 sec)

mysql>

call
isipelanggan("PEL-0002","Budi
Drajat","Jl.
Tirtangga
30
B","101002190589","KTP","081767894784");
Query OK, 1 row affected (0.05 sec)
mysql>
call
isipelanggan("PEL-0003","Pudji
Utami","Jl.
Malang
No
56","787832823","SIM","087854679274");
Query OK, 1 row affected (0.03 sec)
mysql> call isipelanggan("PEL-0004","Faesol Puspito","Jl. Kol. Sugiono No
4","091052879","KTM","085767894435");
Query OK, 1 row affected (0.01 sec)
mysql>
call
isipelanggan("PEL-0005","Suryo
Suyitno","Jl.
Matos
No
9","101045566445","KTP","0811234455");
Query OK, 1 row affected (0.01 sec)
mysql> select *from Pelanggan;
+----------+----------------+-----------------------+--------------+-----------------+-------------+
| id_user | nama_user
| alamat_user
| no_identitas | jenis_identitas | no_telp_user |
+----------+----------------+-----------------------+--------------+-----------------+--------------+
| PEL-0000 | No Name
| No Add
| No Numb
| No | No
|
| PEL-0001 | Ayu Dewi
| Jl. Mantingan No 89 | 109023004 | KTM | 081233455488 |
| PEL-0002 | Budi Drajat | Jl. Tirtangga 30 B | 101002190589 | KTP | 081767894784 |
| PEL-0003 | Pudji Utami | Jl. Malang No 56
| 787832823 | SIM | 087854679274 |
| PEL-0004 | Faesol Puspito | Jl. Kol. Sugiono No 4 | 091052879 | KTM | 085767894435 |
| PEL-0005 | Suryo Suyitno | Jl. Matos No 9
| 101045566445 | KTP | 0811234455 |
+----------+----------------+-----------------------+--------------+-----------------+--------------+
6 rows in set (0.00 sec)
c. Procedure Pegawai
mysql> delimiter //
mysql>
create
procedure
isipegawai(in
id_peg
varchar(8),
nama_peg
varchar(50),alamat_peg varchar(50), no_telp_peg varchar(12))
-> begin
-> insert into pegawai values(id_peg, nama_peg, alamat_peg, no_telp_peg);
-> end //
Query OK, 0 rows affected (0.02 sec)
mysql> delimiter ;
mysql>

call
isipegawai("PEG-1001","Eka
Putra","Jl.Sudirman
No
A","085643578999");
Query OK, 1 row affected (0.01 sec)
mysql>
call
isipegawai("PEG-1002","Mradipta
Lintang","Jl.Soleh
6","085755678876");
Query OK, 1 row affected (0.01 sec)

14

No

mysql>

call
isipegawai("PEG-1003","Citra
Kirana","Jl.Buntu
10
10","08123556788");
Query OK, 1 row affected (0.01 sec)
mysql>
call
isipegawai("PEG-1004","Niko
Dwi","Jl.Macet
100","081890904445");
Query OK, 1 row affected (0.01 sec)

No

KM

mysql> select *from pegawai;


+----------+------------------+---------------------+--------------+
| id_peg | nama_peg
| alamat_peg
| no_telp_peg |
+----------+------------------+---------------------+--------------+
| PEG-1001 | Eka Putra
| Jl.Sudirman No 14 A | 085643578999 |
| PEG-1002 | Mradipta Lintang | Jl.Soleh No 6
| 085755678876 |
| PEG-1003 | Citra Kirana | Jl.Buntu 10 No 10 | 08123556788 |
| PEG-1004 | Niko Dwi
| Jl.Macet KM 100 | 081890904445 |
+----------+------------------+---------------------+--------------+
4 rows in set (0.00 sec)
d. Procedure Transaksi
mysql> delimiter //
mysql> create procedure isitransaksi(in no_transakti varchar(10),
varchar(8),id_dvd varchar(10), id_peg varchar(8))
-> begin
-> insert into transaksi values(no_transakti,id_user,id_dvd,id_peg);
-> end //
Query OK, 0 rows affected (0.01 sec)
mysql> delimiter ;
mysql> call isitransaksi("TRAN-001","PEL-0000","M-101-AC","PEG-1001");
Query OK, 1 row affected (0.32 sec)
mysql> call isitransaksi("TRAN-002","PEL-0002","M-201-CM","PEG-1002");
Query OK, 1 row affected (0.33 sec)
mysql> call isitransaksi("TRAN-003","PEL-0003","I-301-HR","PEG-1003");
Query OK, 1 row affected (0.09 sec)
mysql> call isitransaksi("TRAN-004","PEL-0004","K-501-DR","PEG-1004");
Query OK, 1 row affected (0.33 sec)

id_user

mysql> select *from transaksi;


+--------------+----------+----------+------------+
| no_transaksi | id_user | id_dvd | id_pegawai |
+--------------+----------+----------+------------+
| TRAN-001 | PEL-0000 | M-101-AC | PEG-1001 |
| TRAN-002 | PEL-0002 | M-201-CM | PEG-1002 |
| TRAN-003 | PEL-0003 | I-301-HR | PEG-1003 |
| TRAN-004 | PEL-0004 | K-501-DR | PEG-1004 |
+--------------+----------+----------+------------+
4 rows in set (0.00 sec)
3. Mengubah Data Menggunakan TRIGGER Dalam Table DVD (Cinta Kimcil Menjadi
Mabuk Janda)
mysql> delimiter #
mysql> create trigger before_update before update on DVD for each row
-> begin
-> update DVD set judul_dvd="Mabuk Janda" where judul_dvd="Cinta
Kimcil";
-> end #
+----------+---------------+-----------+-----------+
| id_dvd | judul_dvd | genre_dvd | harga_dvd |
+----------+---------------+-----------+-----------+
| I-301-HR | Pocong Ngesot | Horror | 50000 |
| I-401-DR | Mabuk Janda | Drama | 50000 |
| K-501-DR | Dream High | Drama | 250000 |
| M-101-AC | Expendables 2 | Action | 80000 |
| M-201-CM | Ted
| Comedy | 80000 |
+----------+---------------+-----------+-----------+
6 rows in set (0.00 sec)

4. Menampilkan Table Menggunakan VIEW


mysql> CREATE VIEW view_1 AS SELECT * FROM DVD;
Query OK, 0 rows affected (0.02 sec)
mysql> select *from view_1;
+----------+---------------+-----------+-----------+
| id_dvd | judul_dvd | genre_dvd | harga_dvd |
+----------+---------------+-----------+-----------+
|
| NULL
| NULL | NULL |
| I-301-HR | Pocong Ngesot | Horror | 50000 |
| I-401-DR | Cinta Kimcil | Drama | 50000 |
| K-501-DR | Dream High | Drama | 250000 |
| M-101-AC | Expendables 2 | Action | 80000 |
| M-201-CM | Ted
| Comedy | 80000 |
+----------+---------------+-----------+-----------+
6 rows in set (0.04 sec)
mysql> CREATE VIEW view_2 AS SELECT * FROM Pelanggan;
Query OK, 0 rows affected (0.01 sec)
mysql> select *from view_2;
+----------+----------------+-----------------------+--------------+-----------------+--------------+
| id_user | nama_user
| alamat_user
| no_identitas | jenis_identitas | no_telp_user |
+----------+----------------+-----------------------+--------------+-----------------+--------------+
| PEL-0000 | No Name
| No Add
| No Numb
| No
| No
|
| PEL-0001 | Ayu Dewi
| Jl. Mantingan No 89 | 109023004 | KTM
| 081233455488 |
| PEL-0002 | Budi Drajat | Jl. Tirtangga 30 B | 101002190589 | KTP
| 081767894784 |
| PEL-0003 | Pudji Utami | Jl. Malang No 56
| 787832823 | SIM
| 087854679274 |
| PEL-0004 | Faesol Puspito | Jl. Kol. Sugiono No 4 | 091052879 | KTM
| 085767894435 |
| PEL-0005 | Suryo Suyitno | Jl. Matos No 9
| 101045566445 | KTP
| 0811234455 |
+----------+----------------+-----------------------+--------------+-----------------+--------------+
6 rows in set (0.05 sec)

mysql> CREATE VIEW view_3 AS SELECT * FROM pegawai;


Query OK, 0 rows affected (0.01 sec)
mysql> select *from view_3;
+----------+------------------+---------------------+--------------+
| id_peg | nama_peg
| alamat_peg
| no_telp_peg |
+----------+------------------+---------------------+--------------+
| PEG-1001 | Eka Putra
| Jl.Sudirman No 14 A | 085643578999 |
| PEG-1002 | Mradipta Lintang | Jl.Soleh No 6
| 085755678876 |
| PEG-1003 | Citra Kirana | Jl.Buntu 10 No 10 | 08123556788 |
| PEG-1004 | Niko Dwi
| Jl.Macet KM 100 | 081890904445 |
+----------+------------------+---------------------+--------------+
4 rows in set (0.05 sec)
mysql> CREATE VIEW view_4 AS SELECT * FROM transaksi;
Query OK, 0 rows affected (0.02 sec)
mysql> select *from view_4;
+--------------+----------+----------+------------+
| no_transaksi | id_user | id_dvd | id_pegawai |
+--------------+----------+----------+------------+
| TRAN-001 | PEL-0000 | M-101-AC | PEG-1001 |
| TRAN-002 | PEL-0002 | M-201-CM | PEG-1002 |
| TRAN-003 | PEL-0003 | I-301-HR | PEG-1003 |
| TRAN-004 | PEL-0004 | K-501-DR | PEG-1004 |
+--------------+----------+----------+------------+
4 rows in set (0.00 sec)
5. Menampilkan Mabuk Janda Di Table Pelanggan
Mabuk Janda Belum ada yang pinjam
6. Menampilkan ID user PEL-0002 PEL-0005
mysql> select *from pelanggan where id_user='PEL-0002' OR id_user='PEL-0005';
+----------+---------------+--------------------+--------------+-----------------+--------------+
| id_user | nama_user | alamat_user
| no_identitas | jenis_identitas | no_telp_user |
+----------+---------------+--------------------+--------------+-----------------+--------------+
| PEL-0002 | Budi Drajat | Jl. Tirtangga 30 B | 101002190589 | KTP
|
081767894784 |
| PEL-0005 | Suryo Suyitno | Jl. Matos No 9
| 101045566445 | KTP
|
0811234455 |
+----------+---------------+--------------------+--------------+-----------------+--------------+
2 rows in set (0.00 sec)

7. Menampilkan ID DVD dan Judul DVD Yang Mempunyai Harga Diatas 50000
mysql> select id_dvd,judul_dvd from DVD where harga_dvd>50000;
+----------+---------------+
| id_dvd | judul_dvd |
+----------+---------------+
| K-501-DR | Dream High |
| M-101-AC | Expendables 2 |
| M-201-CM | Ted
|
+----------+---------------+
3 rows in set (0.00 sec)