Anda di halaman 1dari 3

Bentuk relasi table nya :

Membuat databasesnya :
C:\xampp\mysql\bin>mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 10.1.36-MariaDB mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and


others.

Type 'help;' or '\h' for help. Type '\c' to clear the current
input statement.

MariaDB [(none)]> create database warung;


Query OK, 1 row affected (0.19 sec)

Menggunakan database, melihat tavel di dalam data bases


MariaDB [(none)]> use warung;
Database changed
MariaDB [warung]> show tables;
Empty set (0.09 sec)

MariaDB [warung]>

Membuat table ;
MariaDB [warung]> create table jenis_barang(
-> kd_jenis char (2),
-> nm_jenis varchar (8),
-> primary key (kd_jenis));
Query OK, 0 rows affected (0.85 sec)

MariaDB [warung]>

MariaDB [warung]> create table barang (


-> kd_barang varchar (5),
-> kd_jenis char (2),
-> nm_barang varchar (20),
-> harga varchar (7),
-> primary key (kd_barang),
-> foreign key (kd_jenis) references jenis_barang (kd_jenis));
Query OK, 0 rows affected (0.25 sec)
MariaDB [warung]>create table pelanggan (
-> id_pel varchar (16),
-> nama varchar (30),
-> alamat text,
-> no_telp varchar (13),
-> primary key (id_pel));
Query OK, 0 rows affected (0.26 sec)

MariaDB [warung]>
MariaDB [warung]> create table pembelian(
-> no_transaksi varchar(4),
-> kd_barang varchar (5),
-> id_pel varchar (16),
-> tgl date,
-> jumlah varchar (10),
-> primary key (no_transaksi));
Query OK, 0 rows affected (0.24 sec)
MariaDB [warung]> alter table pembelian add foreign key
(kd_barang) references barang(kd_barang);
Query OK, 0 rows affected (0.79 sec)
Records: 0 Duplicates: 0 Warnings: 0

MariaDB [warung]> alter table pembelian add foreign key (id_pel)


references pelanggan(id_pel);
Query OK, 0 rows affected (0.77 sec)
Records: 0 Duplicates: 0 Warnings: 0

Berikut adalah describe tabelnya :

MariaDB [warung_pepak]> desc barang;


+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| kd_barang | varchar(5) | NO | PRI | NULL | |
| kd_jenis | char(2) | NO | MUL | NULL | |
| nm_barang | varchar(20) | NO | | NULL | |
| harga | varchar(7) | NO | | NULL | |
+-----------+-------------+------+-----+---------+-------+
4 rows in set (0.01 sec)

MariaDB [warung_pepak]> desc jenis_barang


-> ;
+----------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+------------+------+-----+---------+-------+
| kd_jenis | char(2) | NO | PRI | NULL | |
| nm_jenis | varchar(8) | NO | | NULL | |
+----------+------------+------+-----+---------+-------+
2 rows in set (0.01 sec)
MariaDB [warung_pepak]> desc pelanggan;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| id_pel | varchar(16) | NO | PRI | NULL | |
| nama | varchar(30) | NO | | NULL | |
| alamat | text | NO | | NULL | |
| no_telp | varchar(13) | NO | | NULL | |
+---------+-------------+------+-----+---------+-------+
4 rows in set (0.01 sec)
MariaDB [warung_pepak]> desc pembelian;
+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| no_transaksi | varchar(4) | NO | PRI | NULL | |
| kd_barang | varchar(5) | NO | MUL | NULL | |
| id_pel | varchar(16) | NO | MUL | NULL | |
| tgl | date | NO | | NULL | |
| jumlah | varchar(10) | NO | | NULL | |
+--------------+-------------+------+-----+---------+-------+
5 rows in set (0.01 sec)

Mengisi table nya :

menggun