PERINTAH-PERINTAH QUERY DATABASE_PENJUALAN
KUMPULAN PERINTAH QUERY DATABASE_PENJUALAN
PERINTAH MENJALANKAN Command Prompt ATAU CMD
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\EDI SANTOSO> cd/xampp/mysql/bin
C:\xampp\mysql\bin> mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.8 MySQL Community Server (GPL)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
PERINTAH QUERY MENAMPILKAN SEMUA DATABASE YANG SUDAH DI BUAT
mysql> show databases;
+--------------------------+
| Database |
+--------------------------+
| information_schema |
| akademik |
| akademik1 |
| cdcol |
| edi |
| mysql |
| newspaper |
| performance_schema |
| perpustakaan_smart |
| phpmyadmin |
| souvenir |
| webauth |
+--------------------------+
12 rows in set (0.00 sec)
PERINTAH QUERY MEMBUAT DATABASE BARU
mysql> create database database_penjualan;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+-------------------------+
| Database |
+-------------------------+
| information_schema |
| akademik |
| akademik1 |
| cdcol |
| database_penjualan |
| edi |
| mysql |
| newspaper |
| performance_schema |
| perpustakaan_smart |
| phpmyadmin |
| souvenir |
| webauth |
+-------------------------+
13 rows in set (0.01 sec)
PERINTAH QUERY MEMBUAT TABEL-TABEL YANG ADA DI DATABASE_PENJUALAN
mysql> use database_penjualan;
Database changed
mysql> create table barang (
-> kode_barang char (12),
-> nama_barang varchar (20),
-> kode_supplier char (6),
-> kode_jenis int (11),
-> stock int (4),
-> kode_satuan char (5),
-> kode_lokasi char (5),
-> harga int (8)
-> );
Query OK, 0 rows affected (0.13 sec)
mysql> desc barang;
+------------------+--------------+-------+-----+-----------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+-------+-----+-----------+-------+
| kode_barang | char(12) | YES | | NULL | |
| nama_barang | varchar(20) | YES | | NULL | |
| kode_supplier | char(6) | YES | | NULL | |
| kode_jenis | int(11) | YES | | NULL | |
| stock | int(4) | YES | | NULL | |
| kode_satuan | char(5) | YES | | NULL | |
| kode_lokasi | char(5) | YES | | NULL | |
| harga | int(8) | YES | | NULL | |
+-----------------+---------------+-------+------+-----------+-------+
8 rows in set (0.00 sec)
mysql> create table supplier (
-> kode_supplier char (6),
-> nama_supplier varchar (20),
-> alamat varchar (50),
-> email varchar (20),
-> no_telp varchar (15)
-> );
Query OK, 0 rows affected (0.20 sec)
mysql> desc supplier;
+------------------+--------------+--------+------+----------+--------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+--------+------+----------+--------+
| kode_supplier | char(6) | YES | | NULL | |
| nama_supplier | varchar(20) | YES | | NULL | |
| alamat | varchar(50) | YES | | NULL | |
| email | varchar(20) | YES | | NULL | |
| no_telp | varchar(15) | YES | | NULL | |
+------------------+--------------+---------+-----+-----------+-------+
5 rows in set (0.00 sec)
mysql> create table customer (
-> kode_customer char (6),
-> nama_customer varchar (20),
-> alamat varchar (50),
-> no_telp varchar (15),
-> email varchar (30)
-> );
Query OK, 0 rows affected (0.13 sec)
mysql> desc customer;
+-------------------+--------------+-------+------+-----------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+--------------+-------+------+-----------+-------+
| kode_customer | char(6) | YES | | NULL | |
| nama_customer | varchar(20) | YES | | NULL | |
| alamat | varchar(50) | YES | | NULL | |
| no_telp | varchar(15) | YES | | NULL | |
| email | varchar(30) | YES | | NULL | |
+-------------------+---------------+------+-------+----------+---------+
5 rows in set (0.00 sec)
mysql> create table petugas (
-> kode_petugas char (10),
-> nama_petugas varchar (20),
-> alamat varchar (50),
-> no_telp varchar (15),
-> password varchar (9)
-> );
Query OK, 0 rows affected (0.06 sec)
mysql> desc petugas;
+-----------------+--------------+-------+-----+-----------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+-------+-----+-----------+-------+
| kode_petugas | char(10) | YES | | NULL | |
| nama_petugas | varchar(20) | YES | | NULL | |
| alamat | varchar(50) | YES | | NULL | |
| no_telp | varchar(15) | YES | | NULL | |
| password | varchar(9) | YES | | NULL | |
+-----------------+--------------+-------+-----+----------+---------+
5 rows in set (0.02 sec)
PERINTAH UNTUK MEMBUAT TABEL LANGSUNG DI TENTUKAN PRIMARY KEY AUTO NYA
mysql> create table jenis (
-> kode_jenis int null auto_increment key,
-> nama_jenis varchar (10)
-> );
Query OK, 0 rows affected (0.06 sec)
mysql> desc jenis;
+--------------+---------------+------+------+-----------+-------------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+-------+------+-----------+-------------------+
| kode_jenis | int(11) | NO | PRI | NULL | auto_increment |
| nama_jenis | varchar(10) | YES | | NULL | |
+-------------+---------------+-------+------+-----------+-------------------+
2 rows in set (0.00 sec)
PERINTAH UNTUK MEMBUAT TABEL LANGSUNG DI TENTUKAN PRIMARY KEY NYA
mysql> create table satuan (
-> kode_satuan char (5) primary key,
-> nama_satuan varchar (10)
-> );
Query OK, 0 rows affected (0.11 sec)
mysql> desc satuan;
+----------------+---------------+-------+-------+----------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+---------------+-------+-------+----------+-------+
| kode_satuan | char(5) | NO | PRI | NULL | |
| nama_satuan | varchar(10) | YES | | NULL | |
+----------------+---------------+-------+------ +----------+-------+
2 rows in set (0.00 sec)
PERINTAH UNTUK MEMBUAT TABEL LANGSUNG DI TENTUKAN PRIMARY KEY NYA
mysql> create table lokasi (
-> kode_lokasi char (5) primary key,
-> nama_lokasi varchar (10)
-> );
Query OK, 0 rows affected (0.06 sec)
mysql> desc lokasi;
+----------------+--------------+-------+------+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+-------+------+---------+-------+
| kode_lokasi | char(5) | NO | PRI | NULL | |
| nama_lokasi | varchar(10) | YES | | NULL | |
+----------------+--------------+-------+------+---------+-------+
2 rows in set (0.00 sec)
PERINTAH UNTUK MEMBUAT TABEL LANGSUNG DI TENTUKAN PRIMARY KEY NYA
mysql> create table transaksi (
-> kode_transaksi char (15) primary key,
-> tanggal date,
-> jam time,
-> kode_customer char (6),
-> total int (10),
-> kode_petugas char (10)
-> );
Query OK, 0 rows affected (0.06 sec)
mysql> desc transaksi;
+-------------------+-----------+------+------+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+-----------+------+------+---------+-------+
| kode_transaksi | char(15) | NO | PRI | NULL | |
| tanggal | date | YES | | NULL | |
| jam | time | YES | | NULL | |
| kode_customer | char(6) | YES | | NULL | |
| total | int(10) | YES | | NULL | |
| kode_petugas | char(10) | YES | | NULL | |
+-------------------+----------+-------+------+---------+-------+
6 rows in set (0.00 sec)
mysql> create table detail_transaksi (
-> kode_detail int null auto_increment key,
-> kode_transaksi char (15),
-> kode_barang char (12),
-> harga int (10),
-> qty int (4),
-> sub_total int (10)
-> );
Query OK, 0 rows affected (0.06 sec)
mysql> desc detail_transaksi;
+------------------+----------+------+-----+---------+--------------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+----------+------+------+---------+-------------------+
| kode_detail | int(11) | NO | PRI | NULL | auto_increment |
| kode_transaksi | char(15) | YES | | NULL | |
| kode_barang | char(12) | YES | | NULL | |
| harga | int(10) | YES | | NULL | |
| qty | int(4) | YES | | NULL | |
| sub_total | int(10) | YES | | NULL | |
+-------------------+----------+-------+-----+---------+-------------------+
6 rows in set (0.00 sec)
PERINTAH UNTUK MENAMPILKAN SEMUA TABEL YANG SUDAH DI BUAT
mysql> show tables;
+-------------------------------------+
| Tables_in_database_penjualan |
+-------------------------------------+
| barang |
| customer |
| detail_transaksi |
| jenis |
| lokasi |
| petugas |
| satuan |
| supplier |
| transaksi |
+--------------------------------------+
9 rows in set (0.01 sec)
PERINTAH QUERY UNTUK MEMBUAT PRIMARY KEY DARI SETIAP TABEL
9 rows in set (0.00 sec)
mysql> desc barang;
+------------------+--------------+-------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+-------+-----+----------+-------+
| kode_barang | char(12) | YES | | NULL | |
| nama_barang | varchar(20) | YES | | NULL | |
| kode_supplier | char(6) | YES | | NULL | |
| kode_jenis | int(11) | YES | | NULL | |
| stock | int(4) | YES | | NULL | |
| kode_satuan | char(5) | YES | | NULL | |
| kode_lokasi | char(5) | YES | | NULL | |
| harga | int(8) | YES | | NULL | |
+--------------------+-------------+------+------+----------+-------+
8 rows in set (0.00 sec)
mysql> alter table barang
-> add constraint
-> pkb1 primary key (kode_barang);
Query OK, 0 rows affected (0.24 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc barang;
+------------------+--------------+-------+-----+----------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+-------+-----+----------+-------+
| kode_barang | char(12) | NO | PRI | | |
| nama_barang | varchar(20) | YES | | NULL | |
| kode_supplier | char(6) | YES | | NULL | |
| kode_jenis | int(11) | YES | | NULL | |
| stock | int(4) | YES | | NULL | |
| kode_satuan | char(5) | YES | | NULL | |
| kode_lokasi | char(5) | YES | | NULL | |
| harga | int(8) | YES | | NULL | |
+------------------+--------------+-------+-----+-----------+-------+
8 rows in set (0.00 sec)
mysql> desc supplier;
+------------------+--------------+-------+-----+----------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+-------+-----+----------+-------+
| kode_supplier | char(6) | YES | | NULL | |
| nama_supplier | varchar(20) | YES | | NULL | |
| alamat | varchar(50) | YES | | NULL | |
| email | varchar(20) | YES | | NULL | |
| no_telp | varchar(15) | YES | | NULL | |
+------------------+--------------+-------+------+---------+-------+
5 rows in set (0.00 sec)
mysql> alter table supplier
-> add constraint
-> pkc1 primary key (kode_supplier);
Query OK, 0 rows affected (0.20 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc supplier;
+------------------+--------------+-------+------+----------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+-------+------+----------+-------+
| kode_supplier | char(6) | NO | PRI | | |
| nama_supplier | varchar(20) | YES | | NULL | |
| alamat | varchar(50) | YES | | NULL | |
| email | varchar(20) | YES | | NULL | |
| no_telp | varchar(15) | YES | | NULL | |
+-----------------+---------------+-------+-------+---------+-------+
5 rows in set (0.01 sec)
mysql> desc customer;
+--------------------+--------------+-------+-----+-----------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+--------------+-------+-----+-----------+-------+
| kode_customer | char(6) | YES | | NULL | |
| nama_customer | varchar(20) | YES | | NULL | |
| alamat | varchar(50) | YES | | NULL | |
| no_telp | varchar(15) | YES | | NULL | |
| email | varchar(30) | YES | | NULL | |
+-------------------+---------------+-------+------+----------+--------+
5 rows in set (0.02 sec)
mysql> alter table customer
-> add constraint
-> pkc1 primary key (kode_customer);
Query OK, 0 rows affected (0.20 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc customer;
+-------------------+--------------+------+------+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+--------------+------+------+---------+-------+
| kode_customer | char(6) | NO | PRI | | |
| nama_customer | varchar(20) | YES | | NULL | |
| alamat | varchar(50) | YES | | NULL | |
| no_telp | varchar(15) | YES | | NULL | |
| email | varchar(30) | YES | | NULL | |
+-------------------+---------------+------+-----+---------+-------+
5 rows in set (0.02 sec)
mysql> desc petugas;
+-----------------+---------------+-------+-----+---------+-------+
| Field | Type | Null Key | Default | Extra |
+-----------------+---------------+-------+-----+----------+-------+
| kode_petugas | char(10) | YES | | NULL | |
| nama_petugas | varchar(20) | YES | | NULL | |
| alamat | varchar(50) | YES | | NULL | |
| no_telp | varchar(15) | YES | | NULL | |
| password | varchar(9) | YES | | NULL | |
+-----------------+----------------+------+-----+-----------+-------+
5 rows in set (0.00 sec)
mysql> alter table petugas
-> add constraint
-> pkpt1 primary key (kode_petugas);
Query OK, 0 rows affected (0.30 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc petugas;
+-----------------+--------------+------+-----+----------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+-------+-----+---------+-------+
| kode_petugas | char(10) | NO | PRI | | |
| nama_petugas | varchar(20) | YES | | NULL | |
| alamat | varchar(50) | YES | | NULL | |
| no_telp | varchar(15) | YES | | NULL | |
| password | varchar(9) | YES | | NULL | |
+-----------------+---------------+-------+-----+---------+-------+
5 rows in set (0.00 sec)
mysql> desc jenis;
+-------------+--------------+------+------+----------+--------------------+
| Field | Type |Null | Key | Default | Extra |
+-------------+---------------+------+-----+----------+--------------------+
| kode_jenis |int(11) | NO | PRI | NULL | auto_increment |
| nama_jenis | varchar(10) | YES | | NULL | |
+--------------+--------------+-------+-----+-----------+-------------------+
2 rows in set (0.02 sec)
mysql> desc satuan;
+----------------+--------------+-------+------+-----------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+-------+------+-----------+-------+
| kode_satuan | char(5) | NO | PRI | NULL | |
| nama_satuan | varchar(10) | YES | | NULL | |
+----------------+--------------+-------+-------+-----------+------+
2 rows in set (0.01 sec)
mysql> desc lokasi;
+---------------+--------------+-------+------+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+-------+------+---------+-------+
| kode_lokasi | char(5) | NO | PRI | NULL | |
| nama_lokasi | varchar(10) | YES | | NULL | |
+---------------+--------------+-------+-------+--------+-------+
2 rows in set (0.00 sec)
mysql> desc transaksi;
+--------------------+----------+------+-----+-----------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+----------+------+-----+-----------+-------+
| kode_transaksi | char(15) | NO | PRI | NULL | |
| tanggal | date | YES | | NULL | |
| jam | time | YES | | NULL | |
| kode_customer | char(6) | YES | | NULL | |
| total | int(10) | YES | | NULL | |
| kode_petugas | char(10) | YES | | NULL | |
+------------------+-----------+-------+-----+-----------+-------+
6 rows in set (0.00 sec)
mysql> desc detail_transaksi;
+------------------+-----------+------+------+-----------+-------------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+-----------+------+------+-----------+-------------------+
| kode_detail | int(11) | NO | PRI | NULL | auto_increment |
| kode_transaksi | char(15) | YES | | NULL | |
| kode_barang | char(12) | YES | | NULL | |
| harga | int(10) | YES | | NULL | |
| qty | int(4) | YES | | NULL | |
| sub_total | int(10) | YES | | NULL | |
+------------------+-----------+-------+------+----------+-------------------+
6 rows in set (0.00 sec)
PERINTAH QUERY UNTUK MEMBUAT FOREIGN KEY,UNTUK SETIAP TABEL YANG ADA FOREIGN KEY NYA
mysql> desc barang;
+------------------+--------------+-------+------+----------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+-------+------+----------+-------+
| kode_barang | char(12) | NO | PRI | | |
| nama_barang | varchar(20) | YES | | NULL | |
| kode_supplier | char(6) | YES | | NULL | |
| kode_jenis | int(11) | YES | | NULL | |
| stock | int(4) | YES | | NULL | |
| kode_satuan | char(5) | YES | | NULL | |
| kode_lokasi | char(5) | YES | | NULL | |
| harga | int(8) | YES | | NULL | |
+----------------+---------------+-------+------+-----------+-------+
8 rows in set (0.00 sec)
mysql> alter table barang
-> add constraint
-> fkb1 foreign key (kode_supplier)
-> references supplier (kode_supplier);
Query OK, 0 rows affected (0.16 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table barang
-> add constraint
-> fkb2 foreign key (kode_jenis)
-> references jenis (kode_jenis);
Query OK, 0 rows affected (0.20 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table barang
-> add constraint
-> fkb3 foreign key (kode_satuan)
-> references satuan (kode_satuan);
Query OK, 0 rows affected (0.22 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table barang
-> add constraint
-> fkb4 foreign key (kode_lokasi)
-> references lokasi (kode_lokasi);
Query OK, 0 rows affected (0.22 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc barang;
+------------------+--------------+-------+-------+----------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+-------+-------+----------+-------+
| kode_barang | char(12) | NO | PRI | | |
| nama_barang | varchar(20) | YES | | NULL | |
| kode_supplier | char(6) | YES | MUL | NULL | |
| kode_jenis | int(11) | YES | MUL | NULL | |
| stock | int(4) | YES | | NULL | |
| kode_satuan | char(5) | YES | MUL | NULL | |
| kode_lokasi | char(5) | YES | MUL | NULL | |
| harga | int(8) | YES | | NULL | |
+-----------------+---------------+-------+-------+-----------+-------+
8 rows in set (0.00 sec)
mysql> desc transaksi;
+-------------------+-----------+------+------+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+-----------+------+------+---------+-------+
| kode_transaksi | char(15) | NO | PRI | NULL | |
| tanggal | date | YES | | NULL | |
| jam | time | YES | | NULL | |
| kode_customer | char(6) | YES | | NULL | |
| total | int(10) | YES | | NULL | |
| kode_petugas | char(10) | YES | | NULL | |
+------------------+-----------+-------+-----+-----------+-------+
6 rows in set (0.00 sec)
mysql> alter table transaksi
-> add constraint
-> fktr1 foreign key (kode_customer)
-> references customer (kode_customer);
Query OK, 0 rows affected (0.22 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table transaksi
-> add constraint
-> fktr2 foreign key (kode_petugas)
-> references petugas (kode_petugas);
Query OK, 0 rows affected (0.22 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc transaksi;
+--------------------+----------+-------+------+-----------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+----------+-------+------+-----------+-------+
| kode_transaksi | char(15) | NO | PRI | NULL | |
| tanggal | date | YES | | NULL | |
| jam | time | YES | | NULL | |
| kode_customer | char(6) | YES | MUL | NULL | |
| total | int(10) | YES | | NULL | |
| kode_petugas | char(10) | YES | MUL | NULL | |
+-------------------+----------+-------+--------+----------+-------+
6 rows in set (0.00 sec)
mysql> desc detail_transaksi;
+------------------+-----------+------+------+----------+-------------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+-----------+------+------+----------+-------------------+
| kode_detail | int(11) | NO | PRI | NULL | auto_increment |
| kode_transaksi | char(15) | YES | | NULL | |
| kode_barang | char(12) | YES | | NULL | |
| harga | int(10) | YES | | NULL | |
| qty | int(4) | YES | | NULL | |
| sub_total | int(10) | YES | | NULL | |
+------------------+----------+------+------+-----------+-------------------+
6 rows in set (0.00 sec)
mysql> alter table detail_transaksi
-> add constraint
-> fkdt1 foreign key (kode_transaksi)
-> references transaksi (kode_transaksi);
Query OK, 0 rows affected (0.20 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table detail_transaksi
-> add constraint
-> fkdt2 foreign key (kode_barang)
-> references barang (kode_barang);
Query OK, 0 rows affected (0.19 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc detail_transaksi;
+------------------+----------+-------+--------+---------+-------------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+----------+-------+--------+---------+-------------------+
| kode_detail | int(11) | NO | PRI | NULL | auto_increment |
| kode_transaksi | char(15) | YES | MUL | NULL | |
| kode_barang | char(12) | YES | MUL | NULL | |
| harga | int(10) | YES | | NULL | |
| qty | int(4) | YES | | NULL | |
| sub_total | int(10) | YES | | NULL | |
+------------------+----------+-------+--------+---------+-------------------+
6 rows in set (0.02 sec)
INI DESIGN TABEL-TABEL DATABASE_PENJUALAN YANG SUDAH BERELASI
PERINTAH MENJALANKAN Command Prompt ATAU CMD
YANG SOFTWARE XAMPP NYA SUDAH AKTIF.
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\EDI SANTOSO> cd/xampp/mysql/bin
C:\xampp\mysql\bin> mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.8 MySQL Community Server (GPL)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
PERINTAH QUERY MENAMPILKAN SEMUA DATABASE YANG SUDAH DI BUAT
mysql> show databases;
+--------------------------+
| Database |
+--------------------------+
| information_schema |
| akademik |
| akademik1 |
| cdcol |
| edi |
| mysql |
| newspaper |
| performance_schema |
| perpustakaan_smart |
| phpmyadmin |
| souvenir |
| webauth |
+--------------------------+
12 rows in set (0.00 sec)
PERINTAH QUERY MEMBUAT DATABASE BARU
mysql> create database database_penjualan;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+-------------------------+
| Database |
+-------------------------+
| information_schema |
| akademik |
| akademik1 |
| cdcol |
| database_penjualan |
| edi |
| mysql |
| newspaper |
| performance_schema |
| perpustakaan_smart |
| phpmyadmin |
| souvenir |
| webauth |
+-------------------------+
13 rows in set (0.01 sec)
PERINTAH QUERY MEMBUAT TABEL-TABEL YANG ADA DI DATABASE_PENJUALAN
mysql> use database_penjualan;
Database changed
mysql> create table barang (
-> kode_barang char (12),
-> nama_barang varchar (20),
-> kode_supplier char (6),
-> kode_jenis int (11),
-> stock int (4),
-> kode_satuan char (5),
-> kode_lokasi char (5),
-> harga int (8)
-> );
Query OK, 0 rows affected (0.13 sec)
mysql> desc barang;
+------------------+--------------+-------+-----+-----------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+-------+-----+-----------+-------+
| kode_barang | char(12) | YES | | NULL | |
| nama_barang | varchar(20) | YES | | NULL | |
| kode_supplier | char(6) | YES | | NULL | |
| kode_jenis | int(11) | YES | | NULL | |
| stock | int(4) | YES | | NULL | |
| kode_satuan | char(5) | YES | | NULL | |
| kode_lokasi | char(5) | YES | | NULL | |
| harga | int(8) | YES | | NULL | |
+-----------------+---------------+-------+------+-----------+-------+
8 rows in set (0.00 sec)
mysql> create table supplier (
-> kode_supplier char (6),
-> nama_supplier varchar (20),
-> alamat varchar (50),
-> email varchar (20),
-> no_telp varchar (15)
-> );
Query OK, 0 rows affected (0.20 sec)
mysql> desc supplier;
+------------------+--------------+--------+------+----------+--------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+--------+------+----------+--------+
| kode_supplier | char(6) | YES | | NULL | |
| nama_supplier | varchar(20) | YES | | NULL | |
| alamat | varchar(50) | YES | | NULL | |
| email | varchar(20) | YES | | NULL | |
| no_telp | varchar(15) | YES | | NULL | |
+------------------+--------------+---------+-----+-----------+-------+
5 rows in set (0.00 sec)
mysql> create table customer (
-> kode_customer char (6),
-> nama_customer varchar (20),
-> alamat varchar (50),
-> no_telp varchar (15),
-> email varchar (30)
-> );
Query OK, 0 rows affected (0.13 sec)
mysql> desc customer;
+-------------------+--------------+-------+------+-----------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+--------------+-------+------+-----------+-------+
| kode_customer | char(6) | YES | | NULL | |
| nama_customer | varchar(20) | YES | | NULL | |
| alamat | varchar(50) | YES | | NULL | |
| no_telp | varchar(15) | YES | | NULL | |
| email | varchar(30) | YES | | NULL | |
+-------------------+---------------+------+-------+----------+---------+
5 rows in set (0.00 sec)
mysql> create table petugas (
-> kode_petugas char (10),
-> nama_petugas varchar (20),
-> alamat varchar (50),
-> no_telp varchar (15),
-> password varchar (9)
-> );
Query OK, 0 rows affected (0.06 sec)
mysql> desc petugas;
+-----------------+--------------+-------+-----+-----------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+-------+-----+-----------+-------+
| kode_petugas | char(10) | YES | | NULL | |
| nama_petugas | varchar(20) | YES | | NULL | |
| alamat | varchar(50) | YES | | NULL | |
| no_telp | varchar(15) | YES | | NULL | |
| password | varchar(9) | YES | | NULL | |
+-----------------+--------------+-------+-----+----------+---------+
5 rows in set (0.02 sec)
PERINTAH UNTUK MEMBUAT TABEL LANGSUNG DI TENTUKAN PRIMARY KEY AUTO NYA
mysql> create table jenis (
-> kode_jenis int null auto_increment key,
-> nama_jenis varchar (10)
-> );
Query OK, 0 rows affected (0.06 sec)
mysql> desc jenis;
+--------------+---------------+------+------+-----------+-------------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+-------+------+-----------+-------------------+
| kode_jenis | int(11) | NO | PRI | NULL | auto_increment |
| nama_jenis | varchar(10) | YES | | NULL | |
+-------------+---------------+-------+------+-----------+-------------------+
2 rows in set (0.00 sec)
PERINTAH UNTUK MEMBUAT TABEL LANGSUNG DI TENTUKAN PRIMARY KEY NYA
mysql> create table satuan (
-> kode_satuan char (5) primary key,
-> nama_satuan varchar (10)
-> );
Query OK, 0 rows affected (0.11 sec)
mysql> desc satuan;
+----------------+---------------+-------+-------+----------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+---------------+-------+-------+----------+-------+
| kode_satuan | char(5) | NO | PRI | NULL | |
| nama_satuan | varchar(10) | YES | | NULL | |
+----------------+---------------+-------+------ +----------+-------+
2 rows in set (0.00 sec)
PERINTAH UNTUK MEMBUAT TABEL LANGSUNG DI TENTUKAN PRIMARY KEY NYA
mysql> create table lokasi (
-> kode_lokasi char (5) primary key,
-> nama_lokasi varchar (10)
-> );
Query OK, 0 rows affected (0.06 sec)
mysql> desc lokasi;
+----------------+--------------+-------+------+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+-------+------+---------+-------+
| kode_lokasi | char(5) | NO | PRI | NULL | |
| nama_lokasi | varchar(10) | YES | | NULL | |
+----------------+--------------+-------+------+---------+-------+
2 rows in set (0.00 sec)
PERINTAH UNTUK MEMBUAT TABEL LANGSUNG DI TENTUKAN PRIMARY KEY NYA
mysql> create table transaksi (
-> kode_transaksi char (15) primary key,
-> tanggal date,
-> jam time,
-> kode_customer char (6),
-> total int (10),
-> kode_petugas char (10)
-> );
Query OK, 0 rows affected (0.06 sec)
mysql> desc transaksi;
+-------------------+-----------+------+------+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+-----------+------+------+---------+-------+
| kode_transaksi | char(15) | NO | PRI | NULL | |
| tanggal | date | YES | | NULL | |
| jam | time | YES | | NULL | |
| kode_customer | char(6) | YES | | NULL | |
| total | int(10) | YES | | NULL | |
| kode_petugas | char(10) | YES | | NULL | |
+-------------------+----------+-------+------+---------+-------+
6 rows in set (0.00 sec)
mysql> create table detail_transaksi (
-> kode_detail int null auto_increment key,
-> kode_transaksi char (15),
-> kode_barang char (12),
-> harga int (10),
-> qty int (4),
-> sub_total int (10)
-> );
Query OK, 0 rows affected (0.06 sec)
mysql> desc detail_transaksi;
+------------------+----------+------+-----+---------+--------------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+----------+------+------+---------+-------------------+
| kode_detail | int(11) | NO | PRI | NULL | auto_increment |
| kode_transaksi | char(15) | YES | | NULL | |
| kode_barang | char(12) | YES | | NULL | |
| harga | int(10) | YES | | NULL | |
| qty | int(4) | YES | | NULL | |
| sub_total | int(10) | YES | | NULL | |
+-------------------+----------+-------+-----+---------+-------------------+
6 rows in set (0.00 sec)
PERINTAH UNTUK MENAMPILKAN SEMUA TABEL YANG SUDAH DI BUAT
mysql> show tables;
+-------------------------------------+
| Tables_in_database_penjualan |
+-------------------------------------+
| barang |
| customer |
| detail_transaksi |
| jenis |
| lokasi |
| petugas |
| satuan |
| supplier |
| transaksi |
+--------------------------------------+
9 rows in set (0.01 sec)
PERINTAH QUERY UNTUK MEMBUAT PRIMARY KEY DARI SETIAP TABEL
9 rows in set (0.00 sec)
mysql> desc barang;
+------------------+--------------+-------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+-------+-----+----------+-------+
| kode_barang | char(12) | YES | | NULL | |
| nama_barang | varchar(20) | YES | | NULL | |
| kode_supplier | char(6) | YES | | NULL | |
| kode_jenis | int(11) | YES | | NULL | |
| stock | int(4) | YES | | NULL | |
| kode_satuan | char(5) | YES | | NULL | |
| kode_lokasi | char(5) | YES | | NULL | |
| harga | int(8) | YES | | NULL | |
+--------------------+-------------+------+------+----------+-------+
8 rows in set (0.00 sec)
mysql> alter table barang
-> add constraint
-> pkb1 primary key (kode_barang);
Query OK, 0 rows affected (0.24 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc barang;
+------------------+--------------+-------+-----+----------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+-------+-----+----------+-------+
| kode_barang | char(12) | NO | PRI | | |
| nama_barang | varchar(20) | YES | | NULL | |
| kode_supplier | char(6) | YES | | NULL | |
| kode_jenis | int(11) | YES | | NULL | |
| stock | int(4) | YES | | NULL | |
| kode_satuan | char(5) | YES | | NULL | |
| kode_lokasi | char(5) | YES | | NULL | |
| harga | int(8) | YES | | NULL | |
+------------------+--------------+-------+-----+-----------+-------+
8 rows in set (0.00 sec)
mysql> desc supplier;
+------------------+--------------+-------+-----+----------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+-------+-----+----------+-------+
| kode_supplier | char(6) | YES | | NULL | |
| nama_supplier | varchar(20) | YES | | NULL | |
| alamat | varchar(50) | YES | | NULL | |
| email | varchar(20) | YES | | NULL | |
| no_telp | varchar(15) | YES | | NULL | |
+------------------+--------------+-------+------+---------+-------+
5 rows in set (0.00 sec)
mysql> alter table supplier
-> add constraint
-> pkc1 primary key (kode_supplier);
Query OK, 0 rows affected (0.20 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc supplier;
+------------------+--------------+-------+------+----------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+-------+------+----------+-------+
| kode_supplier | char(6) | NO | PRI | | |
| nama_supplier | varchar(20) | YES | | NULL | |
| alamat | varchar(50) | YES | | NULL | |
| email | varchar(20) | YES | | NULL | |
| no_telp | varchar(15) | YES | | NULL | |
+-----------------+---------------+-------+-------+---------+-------+
5 rows in set (0.01 sec)
mysql> desc customer;
+--------------------+--------------+-------+-----+-----------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+--------------+-------+-----+-----------+-------+
| kode_customer | char(6) | YES | | NULL | |
| nama_customer | varchar(20) | YES | | NULL | |
| alamat | varchar(50) | YES | | NULL | |
| no_telp | varchar(15) | YES | | NULL | |
| email | varchar(30) | YES | | NULL | |
+-------------------+---------------+-------+------+----------+--------+
5 rows in set (0.02 sec)
mysql> alter table customer
-> add constraint
-> pkc1 primary key (kode_customer);
Query OK, 0 rows affected (0.20 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc customer;
+-------------------+--------------+------+------+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+--------------+------+------+---------+-------+
| kode_customer | char(6) | NO | PRI | | |
| nama_customer | varchar(20) | YES | | NULL | |
| alamat | varchar(50) | YES | | NULL | |
| no_telp | varchar(15) | YES | | NULL | |
| email | varchar(30) | YES | | NULL | |
+-------------------+---------------+------+-----+---------+-------+
5 rows in set (0.02 sec)
mysql> desc petugas;
+-----------------+---------------+-------+-----+---------+-------+
| Field | Type | Null Key | Default | Extra |
+-----------------+---------------+-------+-----+----------+-------+
| kode_petugas | char(10) | YES | | NULL | |
| nama_petugas | varchar(20) | YES | | NULL | |
| alamat | varchar(50) | YES | | NULL | |
| no_telp | varchar(15) | YES | | NULL | |
| password | varchar(9) | YES | | NULL | |
+-----------------+----------------+------+-----+-----------+-------+
5 rows in set (0.00 sec)
mysql> alter table petugas
-> add constraint
-> pkpt1 primary key (kode_petugas);
Query OK, 0 rows affected (0.30 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc petugas;
+-----------------+--------------+------+-----+----------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+-------+-----+---------+-------+
| kode_petugas | char(10) | NO | PRI | | |
| nama_petugas | varchar(20) | YES | | NULL | |
| alamat | varchar(50) | YES | | NULL | |
| no_telp | varchar(15) | YES | | NULL | |
| password | varchar(9) | YES | | NULL | |
+-----------------+---------------+-------+-----+---------+-------+
5 rows in set (0.00 sec)
mysql> desc jenis;
+-------------+--------------+------+------+----------+--------------------+
| Field | Type |Null | Key | Default | Extra |
+-------------+---------------+------+-----+----------+--------------------+
| kode_jenis |int(11) | NO | PRI | NULL | auto_increment |
| nama_jenis | varchar(10) | YES | | NULL | |
+--------------+--------------+-------+-----+-----------+-------------------+
2 rows in set (0.02 sec)
mysql> desc satuan;
+----------------+--------------+-------+------+-----------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+-------+------+-----------+-------+
| kode_satuan | char(5) | NO | PRI | NULL | |
| nama_satuan | varchar(10) | YES | | NULL | |
+----------------+--------------+-------+-------+-----------+------+
2 rows in set (0.01 sec)
mysql> desc lokasi;
+---------------+--------------+-------+------+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+-------+------+---------+-------+
| kode_lokasi | char(5) | NO | PRI | NULL | |
| nama_lokasi | varchar(10) | YES | | NULL | |
+---------------+--------------+-------+-------+--------+-------+
2 rows in set (0.00 sec)
mysql> desc transaksi;
+--------------------+----------+------+-----+-----------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+----------+------+-----+-----------+-------+
| kode_transaksi | char(15) | NO | PRI | NULL | |
| tanggal | date | YES | | NULL | |
| jam | time | YES | | NULL | |
| kode_customer | char(6) | YES | | NULL | |
| total | int(10) | YES | | NULL | |
| kode_petugas | char(10) | YES | | NULL | |
+------------------+-----------+-------+-----+-----------+-------+
6 rows in set (0.00 sec)
mysql> desc detail_transaksi;
+------------------+-----------+------+------+-----------+-------------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+-----------+------+------+-----------+-------------------+
| kode_detail | int(11) | NO | PRI | NULL | auto_increment |
| kode_transaksi | char(15) | YES | | NULL | |
| kode_barang | char(12) | YES | | NULL | |
| harga | int(10) | YES | | NULL | |
| qty | int(4) | YES | | NULL | |
| sub_total | int(10) | YES | | NULL | |
+------------------+-----------+-------+------+----------+-------------------+
6 rows in set (0.00 sec)
PERINTAH QUERY UNTUK MEMBUAT FOREIGN KEY,UNTUK SETIAP TABEL YANG ADA FOREIGN KEY NYA
mysql> desc barang;
+------------------+--------------+-------+------+----------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+-------+------+----------+-------+
| kode_barang | char(12) | NO | PRI | | |
| nama_barang | varchar(20) | YES | | NULL | |
| kode_supplier | char(6) | YES | | NULL | |
| kode_jenis | int(11) | YES | | NULL | |
| stock | int(4) | YES | | NULL | |
| kode_satuan | char(5) | YES | | NULL | |
| kode_lokasi | char(5) | YES | | NULL | |
| harga | int(8) | YES | | NULL | |
+----------------+---------------+-------+------+-----------+-------+
8 rows in set (0.00 sec)
mysql> alter table barang
-> add constraint
-> fkb1 foreign key (kode_supplier)
-> references supplier (kode_supplier);
Query OK, 0 rows affected (0.16 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table barang
-> add constraint
-> fkb2 foreign key (kode_jenis)
-> references jenis (kode_jenis);
Query OK, 0 rows affected (0.20 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table barang
-> add constraint
-> fkb3 foreign key (kode_satuan)
-> references satuan (kode_satuan);
Query OK, 0 rows affected (0.22 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table barang
-> add constraint
-> fkb4 foreign key (kode_lokasi)
-> references lokasi (kode_lokasi);
Query OK, 0 rows affected (0.22 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc barang;
+------------------+--------------+-------+-------+----------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+-------+-------+----------+-------+
| kode_barang | char(12) | NO | PRI | | |
| nama_barang | varchar(20) | YES | | NULL | |
| kode_supplier | char(6) | YES | MUL | NULL | |
| kode_jenis | int(11) | YES | MUL | NULL | |
| stock | int(4) | YES | | NULL | |
| kode_satuan | char(5) | YES | MUL | NULL | |
| kode_lokasi | char(5) | YES | MUL | NULL | |
| harga | int(8) | YES | | NULL | |
+-----------------+---------------+-------+-------+-----------+-------+
8 rows in set (0.00 sec)
mysql> desc transaksi;
+-------------------+-----------+------+------+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+-----------+------+------+---------+-------+
| kode_transaksi | char(15) | NO | PRI | NULL | |
| tanggal | date | YES | | NULL | |
| jam | time | YES | | NULL | |
| kode_customer | char(6) | YES | | NULL | |
| total | int(10) | YES | | NULL | |
| kode_petugas | char(10) | YES | | NULL | |
+------------------+-----------+-------+-----+-----------+-------+
6 rows in set (0.00 sec)
mysql> alter table transaksi
-> add constraint
-> fktr1 foreign key (kode_customer)
-> references customer (kode_customer);
Query OK, 0 rows affected (0.22 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table transaksi
-> add constraint
-> fktr2 foreign key (kode_petugas)
-> references petugas (kode_petugas);
Query OK, 0 rows affected (0.22 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc transaksi;
+--------------------+----------+-------+------+-----------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+----------+-------+------+-----------+-------+
| kode_transaksi | char(15) | NO | PRI | NULL | |
| tanggal | date | YES | | NULL | |
| jam | time | YES | | NULL | |
| kode_customer | char(6) | YES | MUL | NULL | |
| total | int(10) | YES | | NULL | |
| kode_petugas | char(10) | YES | MUL | NULL | |
+-------------------+----------+-------+--------+----------+-------+
6 rows in set (0.00 sec)
mysql> desc detail_transaksi;
+------------------+-----------+------+------+----------+-------------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+-----------+------+------+----------+-------------------+
| kode_detail | int(11) | NO | PRI | NULL | auto_increment |
| kode_transaksi | char(15) | YES | | NULL | |
| kode_barang | char(12) | YES | | NULL | |
| harga | int(10) | YES | | NULL | |
| qty | int(4) | YES | | NULL | |
| sub_total | int(10) | YES | | NULL | |
+------------------+----------+------+------+-----------+-------------------+
6 rows in set (0.00 sec)
mysql> alter table detail_transaksi
-> add constraint
-> fkdt1 foreign key (kode_transaksi)
-> references transaksi (kode_transaksi);
Query OK, 0 rows affected (0.20 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table detail_transaksi
-> add constraint
-> fkdt2 foreign key (kode_barang)
-> references barang (kode_barang);
Query OK, 0 rows affected (0.19 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc detail_transaksi;
+------------------+----------+-------+--------+---------+-------------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+----------+-------+--------+---------+-------------------+
| kode_detail | int(11) | NO | PRI | NULL | auto_increment |
| kode_transaksi | char(15) | YES | MUL | NULL | |
| kode_barang | char(12) | YES | MUL | NULL | |
| harga | int(10) | YES | | NULL | |
| qty | int(4) | YES | | NULL | |
| sub_total | int(10) | YES | | NULL | |
+------------------+----------+-------+--------+---------+-------------------+
6 rows in set (0.02 sec)
INI DESIGN TABEL-TABEL DATABASE_PENJUALAN YANG SUDAH BERELASI
Komentar
Posting Komentar