You are on page 1of 4

mysql> create database belajar_prosedur1_sispan;

Query OK, 1 row affected (0.09 sec)


mysql> use belajar_prosedur1_sispan;
Database changed
mysql> create table karyawan_sispan(
-> nik char(10) not null primary key default" ",
-> nama varchar(30) not null default" ",
-> jabatan varchar(30) not null default" ");
Query OK, 0 rows affected (0.38 sec)
mysql> desc karyawan_sispan;
+---------+-------------+------+-----+---------+-------+
| Field | Type
| Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| nik
| char(10)
| NO | PRI |
|
|
| nama
| varchar(30) | NO |
|
|
|
| jabatan | varchar(30) | NO |
|
|
|
+---------+-------------+------+-----+---------+-------+
3 rows in set (0.17 sec)
mysql> insert into karyawan_sispan values
-> ('01','Mira','Programmer'),
-> ('02','Mizan','Engineer'),
-> ('03','Lastari','DBA');
Query OK, 3 rows affected (0.13 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from karyawan_sispan;
+-----+---------+------------+
| nik | nama
| jabatan
|
+-----+---------+------------+
| 01 | Mira
| Programmer |
| 02 | Mizan | Engineer |
| 03 | Lastari | DBA
|
+-----+---------+------------+
3 rows in set (0.00 sec)
mysql> create table produk_sispan(
-> kode varchar(10) not null primary key default" ",
-> nama varchar(20),
-> stok int(10),
-> harga int(10));
Query OK, 0 rows affected (0.45 sec)
ysql> desc produk_sispan;
+-------+-------------+------+-----+---------+-------+
| Field | Type
| Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| kode | varchar(10) | NO | PRI |
|
|
| nama | varchar(20) | YES |
| NULL
|
|
| stok | int(10)
| YES |
| NULL
|
|
| harga | int(10)
| YES |
| NULL
|
|
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.34 sec)
mysql> insert into produk_sispan values
-> ('P001','CDR-BLANK','10','2500'),
-> ('P002','Pensil','25','1300');
Query OK, 2 rows affected (0.11 sec)

Records: 2 Duplicates: 0 Warnings: 0


mysql> select * from produk_sispan;
+------+-----------+------+-------+
| kode | nama
| stok | harga |
+------+-----------+------+-------+
| P001 | CDR-BLANK | 10 | 2500 |
| P002 | Pensil
| 25 | 1300 |
+------+-----------+------+-------+
2 rows in set (0.00 sec)
mysql> delimiter //
mysql> create procedure sp_karyawan(IN jb varchar(30))
-> begin
-> select * from karyawan_sispan where jabatan like jb;
-> end //
Query OK, 0 rows affected (0.00 sec)
mysql> call sp_karyawan('Engineer');
-> //
+-----+-------+----------+
| nik | nama | jabatan |
+-----+-------+----------+
| 02 | Mizan | Engineer |
+-----+-------+----------+
1 row in set (0.08 sec)
Query OK, 0 rows affected (0.08 sec)
mysql> delimiter ;
mysql> delimiter //
mysql> create procedure simpan_data_karyawan (IN nik int(10), IN nm varchar(30),
IN jb varchar(30))
-> begin
-> insert into karyawan_sispan (nik,nama,jabatan) values (nik,nama,jb);
-> end//
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ;
mysql> call simpan_data_karyawan('04','Tes','Dokter');
Query OK, 1 row affected (0.34 sec)
mysql> select * from karyawan_sispan;
+-----+---------+------------+
| nik | nama
| jabatan
|
+-----+---------+------------+
| 01 | Mira
| Programmer |
| 02 | Mizan | Engineer |
| 03 | Lastari | DBA
|
| 4 | Tes
| Dokter
|
+-----+---------+------------+
4 rows in set (0.00 sec)
mysql> delimiter //
mysql> create procedure hpss_data_karyawan (IN nik_parameter char(10))
-> begin
-> delete from karyawan_sispan where nik = nik_parameter;
-> end //
Query OK, 0 rows affected (0.00 sec)

mysql> delimiter ;
mysql> call hpss_data_karyawan('02');
Query OK, 1 row affected (0.14 sec)
mysql> select * from karyawan_sispan;
+-----+---------+------------+
| nik | nama
| jabatan
|
+-----+---------+------------+
| 01 | Mira
| Programmer |
| 03 | Lastari | DBA
|
| 4 | Tes
| Dokter
|
+-----+---------+------------+
3 rows in set (0.00 sec)
mysql> create table produk_baru(
-> ID int(10) AUTO_INCREMENT primary key,
-> kode varchar(10),
-> nama varchar(20),
-> stok int(10),
-> harga int(10));
Query OK, 0 rows affected (0.47 sec)
mysql> desc produk_baru;
+-------+-------------+------+-----+---------+----------------+
| Field | Type
| Null | Key | Default | Extra
|
+-------+-------------+------+-----+---------+----------------+
| ID
| int(10)
| NO | PRI | NULL
| auto_increment |
| kode | varchar(10) | YES |
| NULL
|
|
| nama | varchar(20) | YES |
| NULL
|
|
| stok | int(10)
| YES |
| NULL
|
|
| harga | int(10)
| YES |
| NULL
|
|
+-------+-------------+------+-----+---------+----------------+
5 rows in set (0.11 sec)
mysql> INSERT into produk_baru values
-> ('','P001','CDR-BLANK','10','2500'),
-> ('','P002','PENSIL','25','1300');
Query OK, 2 rows affected, 2 warnings (0.81 sec)
Records: 2 Duplicates: 0 Warnings: 2
mysql> select * from produk_baru;
+----+------+-----------+------+-------+
| ID | kode | nama
| stok | harga |
+----+------+-----------+------+-------+
| 1 | P001 | CDR-BLANK | 10 | 2500 |
| 2 | P002 | PENSIL
| 25 | 1300 |
+----+------+-----------+------+-------+
2 rows in set (0.19 sec)
mysql> delimiter //
mysql> create procedure prod_tambah_stok (IN kd int(10), IN jml int(10))
-> begin
-> update produk_baru set stok = stok + jml where kode=kd;
-> end //
Query OK, 0 rows affected (0.39 sec)
mysql> delimiter ;
mysql> call prod_tambah_stok('P001','30');
Query OK, 2 rows affected, 3 warnings (0.30 sec)

mysql> select * from produk_baru;


+----+------+-----------+------+-------+
| ID | kode | nama
| stok | harga |
+----+------+-----------+------+-------+
| 1 | P001 | CDR-BLANK | 40 | 2500 |
| 2 | P002 | PENSIL
| 55 | 1300 |
+----+------+-----------+------+-------+
2 rows in set (0.00 sec)