Nama : Yohana Febriyanti Manik
Npm : 219530011
Kelas : 2 IPTI
Mata kuliah : Praktek sistem basis data
Microsoft Windows [Version 10.0.10240]
(c) 2015 Microsoft Corporation. All rights reserved.
C:\Users\WI>Cd /xampp/mysql/bin
C:\xampp\mysql\bin>Mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.4.11-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 db_ud_serbaguna;
Query OK, 1 row affected (0.002 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| db_ud_serbaguna |
| information_schema |
| mysql |
| performance_schema |
| phpmyadmin |
| test |
+--------------------+
6 rows in set (0.003 sec)
MariaDB [db_ud_serbaguna]> use db_ud_serbaguna;
Database changed
Latihan 1 :
create table tbl_barang
(id_barang char(10) not null primary key,
nama_barang varchar(50) not null,
harga int not null,
id_suplier char(10) not null);
create table tbl_supplier
(id_suplier char(10) not null primary key,
nama_suplier varchar(50) not null,
alamat varchar(50) not null,
no_telp varchar(12) not null);
create table tbl_pembeli
(id_pembeli char(10) not null primary key,
nama_pembeli varchar(50) not null,
jenkel varchar(20) not null,
alamat varchar(50) not null,
no_telp varchar(12) not null);
create table tbl_pembayaran
(id_bayar char(10) not null primary key,
tgl_bayar date not null,
total_bayar double(50) not null,
id_transaksi char(10) not null,
Alter table tbl_pembayaran add foreign key (id_transaksi) references tbl_pembayaran (id_transaksi) );
create table tbl_transaksi
(id_transaksi char(10) not null primary key,
Id_barang char(10) not null,
Alter table tbl_transaksi add foreign key (id_barang) references tbl_barang (id_barang),
Id_pembeli char(10) not null,
Alter table tbl_transaksi add foreign key (id_pembeli) references tbl_pembeli (id_pembeli),
tgl date not null,
keterangan varchar(20) not null);
Latihan 2
perintah 1 :
menambahkan query foreign key pada tiap relasi tabel latihan 1, serta penentuan child dan parent :
qurery foreign 1 :
id_transaksi char(10) not null,
Alter table tbl_pembayaran add foreign key (id_transaksi) references tbl_pembayaran
(id_transaksi) );
Query foreign 2 :
Id_barang char(10) not null,
Alter table tbl_transaksi add foreign key (id_barang) references tbl_barang (id_barang),
Qurery foreign 3 :
Id_pembeli char(10) not null,
Alter table tbl_transaksi add foreign key (id_pembeli) references tbl_pembeli (id_pembeli),