1. Check original table Barang
2. Add Column table Barang (add KETERANGAN)
3. update row table ( update/fill column keterangan)
4. delete row table (example delete KODE_BARANG='ELK-99')
5. Modify Column table ( example change ELK02-ket to ELK02-ketvv2)
6. drop column on table (example delete/drop column KETERANGAN)
1. Check original table Barang
syntax
mysql -u root -p
show tables;
desc barang;
select * from barang;
log
C:\windows\system32>mysql -u root -p
Enter password: ****
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 28
Server version: 10.1.14-MariaDB mariadb.org binary distribution
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> drop database mariadb;
Query OK, 30 rows affected (5.73 sec)
MariaDB [(none)]> create database mariadb;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> use mariadb;
Database changed
MariaDB [mariadb]> show tables;
+-------------------+
| Tables_in_mariadb |
+-------------------+
| barang |
| customer |
| pasok |
| pembelian |
| suplier |
+-------------------+
5 rows in set (6.73 sec)
MariaDB [mariadb]> desc barang;
+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| KODE_BARANG | char(6) | NO | | NULL | |
| NAMA_BARANG | varchar(25) | YES | | NULL | |
| SATUAN_BARANG | varchar(20) | YES | | NULL | |
| STOK_BARANG | int(11) | YES | | NULL | |
+---------------+-------------+------+-----+---------+-------+
4 rows in set (0.07 sec)
MariaDB [mariadb]> select * from barang;
+-------------+--------------------------+---------------+-------------+
| KODE_BARANG | NAMA_BARANG | SATUAN_BARANG | STOK_BARANG |
+-------------+--------------------------+---------------+-------------+
| ELK-02 | LEMARI ES | UNIT | 8 |
| ELK-03 | TELEVISI | UNIT | 30 |
| ELK-04 | RADIO/TAPE | BUAH | 35 |
| ELK-05 | KOMPUTER | UNIT | 28 |
| ELK-06 | KIPAS ANGIN | BUAH | 38 |
| ELK-99 | barang - After Migration | BUAH | 20 |
+-------------+--------------------------+---------------+-------------+
6 rows in set (0.03 sec)
MariaDB [mariadb]>
2. Add Column table Barang (add KETERANGAN)
Syntax
alter table barang add keterangan varchar(15);
desc barang;
select * from barang;
log
MariaDB [mariadb]> alter table barang add keterangan varchar(15);
Query OK, 0 rows affected (0.67 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [mariadb]> desc barang;
+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| KODE_BARANG | char(6) | NO | | NULL | |
| NAMA_BARANG | varchar(25) | YES | | NULL | |
| SATUAN_BARANG | varchar(20) | YES | | NULL | |
| STOK_BARANG | int(11) | YES | | NULL | |
| keterangan | varchar(15) | YES | | NULL | |
+---------------+-------------+------+-----+---------+-------+
5 rows in set (0.01 sec)
MariaDB [mariadb]> select * from barang;
+-------------+-------------+---------------+-------------+------------+
| KODE_BARANG | NAMA_BARANG | SATUAN_BARANG | STOK_BARANG | keterangan |
+-------------+-------------+---------------+-------------+------------+
| ELK-02 | LEMARI ES | UNIT | 8 | NULL |
| ELK-03 | TELEVISI | UNIT | 30 | NULL |
| ELK-04 | RADIO/TAPE | BUAH | 35 | NULL |
| ELK-05 | KOMPUTER | UNIT | 28 | NULL |
| ELK-06 | KIPAS ANGIN | BUAH | 38 | NULL |
+-------------+-------------+---------------+-------------+------------+
5 rows in set (0.00 sec)
MariaDB [mariadb]>
3. update row table ( update/fill column keterangan)
Syntax
update barang set keterangan='ELK02-ket' where Kode_barang='ELK-02';
select * from barang;
log
MariaDB [mariadb]> update barang set keterangan='ELK02-ket' where Kode_barang='ELK-02';
Query OK, 1 row affected (0.12 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [mariadb]> select * from barang;
+-------------+--------------------------+---------------+-------------+------------+
| KODE_BARANG | NAMA_BARANG | SATUAN_BARANG | STOK_BARANG | keterangan |
+-------------+--------------------------+---------------+-------------+------------+
| ELK-02 | LEMARI ES | UNIT | 8 | ELK02-ket |
| ELK-03 | TELEVISI | UNIT | 30 | NULL |
| ELK-04 | RADIO/TAPE | BUAH | 35 | NULL |
| ELK-05 | KOMPUTER | UNIT | 28 | NULL |
| ELK-06 | KIPAS ANGIN | BUAH | 38 | NULL |
| ELK-99 | barang - After Migration | BUAH | 20 | NULL |
+-------------+--------------------------+---------------+-------------+------------+
6 rows in set (0.00 sec)
4. delete row table (example delete KODE_BARANG='ELK-99')
Syntax
delete from BARANG where KODE_BARANG='ELK-99';
select * from barang;
log
MariaDB [mariadb]> delete from BARANG where KODE_BARANG='ELK-99';
Query OK, 1 row affected (0.10 sec)
MariaDB [mariadb]> select * from barang;
+-------------+-------------+---------------+-------------+------------+
| KODE_BARANG | NAMA_BARANG | SATUAN_BARANG | STOK_BARANG | keterangan |
+-------------+-------------+---------------+-------------+------------+
| ELK-02 | LEMARI ES | UNIT | 8 | ELK02-ket |
| ELK-03 | TELEVISI | UNIT | 30 | NULL |
| ELK-04 | RADIO/TAPE | BUAH | 35 | NULL |
| ELK-05 | KOMPUTER | UNIT | 28 | NULL |
| ELK-06 | KIPAS ANGIN | BUAH | 38 | NULL |
+-------------+-------------+---------------+-------------+------------+
5 rows in set (0.00 sec)
MariaDB [mariadb]>
5. Modify Column table ( example change ELK02-ket to ELK02-ketvv2)
Syntax
select * from barang;
update barang set KETERANGAN='ELK02-ketvv2' where KODE_BARANG='ELK-02';
select * from barang;
Log
MariaDB [mariadb]> select * from barang;
+-------------+-------------+---------------+-------------+--------------+
| KODE_BARANG | NAMA_BARANG | SATUAN_BARANG | STOK_BARANG | keterangan |
+-------------+-------------+---------------+-------------+--------------+
| ELK-02 | LEMARI ES | UNIT | 8 | ELK02-ket |
| ELK-03 | TELEVISI | UNIT | 30 | NULL |
| ELK-04 | RADIO/TAPE | BUAH | 35 | NULL |
| ELK-05 | KOMPUTER | UNIT | 28 | NULL |
| ELK-06 | KIPAS ANGIN | BUAH | 38 | NULL |
+-------------+-------------+---------------+-------------+--------------+
5 rows in set (0.00 sec)
MariaDB [mariadb]> update barang set KETERANGAN='ELK02-ketvv2' where KODE_BARANG='ELK-02';
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [mariadb]> select * from barang;
+-------------+-------------+---------------+-------------+--------------+
| KODE_BARANG | NAMA_BARANG | SATUAN_BARANG | STOK_BARANG | KETERANGAN |
+-------------+-------------+---------------+-------------+--------------+
| ELK-02 | LEMARI ES | UNIT | 8 | ELK02-ketvv2 |
| ELK-03 | TELEVISI | UNIT | 30 | NULL |
| ELK-04 | RADIO/TAPE | BUAH | 35 | NULL |
| ELK-05 | KOMPUTER | UNIT | 28 | NULL |
| ELK-06 | KIPAS ANGIN | BUAH | 38 | NULL |
+-------------+-------------+---------------+-------------+--------------+
5 rows in set (0.00 sec)
MariaDB [mariadb]>
MariaDB [mariadb]> update barang set KETERANGAN='mariadblab';
Query OK, 6 rows affected (0.11 sec)
Rows matched: 6 Changed: 6 Warnings: 0
MariaDB [mariadb]> select * from barang;
+-------------+--------------------------+---------------+-------------+------------+
| KODE_BARANG | NAMA_BARANG | SATUAN_BARANG | STOK_BARANG | keterangan |
+-------------+--------------------------+---------------+-------------+------------+
| ELK-02 | LEMARI ES | UNIT | 8 | mariadblab |
| ELK-03 | TELEVISI | UNIT | 30 | mariadblab |
| ELK-04 | RADIO/TAPE | BUAH | 35 | mariadblab |
| ELK-05 | KOMPUTER | UNIT | 28 | mariadblab |
| ELK-06 | KIPAS ANGIN | BUAH | 38 | mariadblab |
| ELK-99 | Barang - After Migration | BUAH | 20 | mariadblab |
+-------------+--------------------------+---------------+-------------+------------+
6 rows in set (0.00 sec)
MariaDB [mariadb]>
MariaDB [mariadb]> update barang set KETERANGAN='ELK02-TTT' where KODE_BARANG='ELK-02';
Query OK, 1 row affected (0.10 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [mariadb]> select * from barang;
+-------------+--------------------------+---------------+-------------+------------+
| KODE_BARANG | NAMA_BARANG | SATUAN_BARANG | STOK_BARANG | keterangan |
+-------------+--------------------------+---------------+-------------+------------+
| ELK-02 | LEMARI ES | UNIT | 8 | ELK02-TTT |
| ELK-03 | TELEVISI | UNIT | 30 | mariadblab |
| ELK-04 | RADIO/TAPE | BUAH | 35 | mariadblab |
| ELK-05 | KOMPUTER | UNIT | 28 | mariadblab |
| ELK-06 | KIPAS ANGIN | BUAH | 38 | mariadblab |
| ELK-99 | Barang - After Migration | BUAH | 20 | mariadblab |
+-------------+--------------------------+---------------+-------------+------------+
6 rows in set (0.00 sec)
MariaDB [mariadb]> update barang set KETERANGAN=null where KODE_BARANG='ELK-02';
Query OK, 1 row affected (0.08 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [mariadb]> select * from barang;
+-------------+--------------------------+---------------+-------------+------------+
| KODE_BARANG | NAMA_BARANG | SATUAN_BARANG | STOK_BARANG | keterangan |
+-------------+--------------------------+---------------+-------------+------------+
| ELK-02 | LEMARI ES | UNIT | 8 | NULL |
| ELK-03 | TELEVISI | UNIT | 30 | mariadblab |
| ELK-04 | RADIO/TAPE | BUAH | 35 | mariadblab |
| ELK-05 | KOMPUTER | UNIT | 28 | mariadblab |
| ELK-06 | KIPAS ANGIN | BUAH | 38 | mariadblab |
| ELK-99 | Barang - After Migration | BUAH | 20 | mariadblab |
+-------------+--------------------------+---------------+-------------+------------+
6 rows in set (0.00 sec)
MariaDB [mariadb]> update barang set KETERANGAN=null;
Query OK, 5 rows affected (0.05 sec)
Rows matched: 6 Changed: 5 Warnings: 0
MariaDB [mariadb]> select * from barang;
+-------------+--------------------------+---------------+-------------+------------+
| KODE_BARANG | NAMA_BARANG | SATUAN_BARANG | STOK_BARANG | keterangan |
+-------------+--------------------------+---------------+-------------+------------+
| ELK-02 | LEMARI ES | UNIT | 8 | NULL |
| ELK-03 | TELEVISI | UNIT | 30 | NULL |
| ELK-04 | RADIO/TAPE | BUAH | 35 | NULL |
| ELK-05 | KOMPUTER | UNIT | 28 | NULL |
| ELK-06 | KIPAS ANGIN | BUAH | 38 | NULL |
| ELK-99 | Barang - After Migration | BUAH | 20 | NULL |
+-------------+--------------------------+---------------+-------------+------------+
6 rows in set (0.00 sec)
MariaDB [mariadb]>
6. drop column on table (example delete/drop column KETERANGAN)
Syntax
desc barang;
select * from barang;
alter table BARANG DROP COLUMN KETERANGAN;
desc barang;
select * from barang;
log
MariaDB [mariadb]> select * from barang;
+-------------+-------------+---------------+-------------+--------------+
| KODE_BARANG | NAMA_BARANG | SATUAN_BARANG | STOK_BARANG | KETERANGAN |
+-------------+-------------+---------------+-------------+--------------+
| ELK-02 | LEMARI ES | UNIT | 8 | ELK02-ketvv2 |
| ELK-03 | TELEVISI | UNIT | 30 | NULL |
| ELK-04 | RADIO/TAPE | BUAH | 35 | NULL |
| ELK-05 | KOMPUTER | UNIT | 28 | NULL |
| ELK-06 | KIPAS ANGIN | BUAH | 38 | NULL |
+-------------+-------------+---------------+-------------+--------------+
5 rows in set (0.00 sec)
MariaDB [mariadb]> desc barang;
+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| KODE_BARANG | char(6) | NO | | NULL | |
| NAMA_BARANG | varchar(25) | YES | | NULL | |
| SATUAN_BARANG | varchar(20) | YES | | NULL | |
| STOK_BARANG | int(11) | YES | | NULL | |
| KETERANGAN | varchar(15) | YES | | NULL | |
+---------------+-------------+------+-----+---------+-------+
5 rows in set (0.01 sec)
MariaDB [mariadb]>
MariaDB [mariadb]> alter table BARANG DROP COLUMN KETERANGAN;
Query OK, 0 rows affected (0.41 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [mariadb]> desc barang;
+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| KODE_BARANG | char(6) | NO | | NULL | |
| NAMA_BARANG | varchar(25) | YES | | NULL | |
| SATUAN_BARANG | varchar(20) | YES | | NULL | |
| STOK_BARANG | int(11) | YES | | NULL | |
+---------------+-------------+------+-----+---------+-------+
4 rows in set (0.02 sec)
MariaDB [mariadb]> select * from barang;
+-------------+-------------+---------------+-------------+
| KODE_BARANG | NAMA_BARANG | SATUAN_BARANG | STOK_BARANG |
+-------------+-------------+---------------+-------------+
| ELK-02 | LEMARI ES | UNIT | 8 |
| ELK-03 | TELEVISI | UNIT | 30 |
| ELK-04 | RADIO/TAPE | BUAH | 35 |
| ELK-05 | KOMPUTER | UNIT | 28 |
| ELK-06 | KIPAS ANGIN | BUAH | 38 |
+-------------+-------------+---------------+-------------+
5 rows in set (0.00 sec)
MariaDB [mariadb]>
7. Insert row table barang
Syntax
select * from barang where KODE_BARANG ='ELK-99';
insert into barang(KODE_BARANG,NAMA_BARANG,SATUAN_BARANG,STOK_BARANG) values('ELK-99','Barang - After Migration','BUAH',20);
select * from barang where KODE_BARANG ='ELK-99';
select * from barang;
Log
MariaDB [mariadb]> select * from barang where KODE_BARANG ='ELK-99';
Empty set (0.06 sec)
MariaDB [mariadb]> insert into barang(KODE_BARANG,NAMA_BARANG,SATUAN_BARANG,STOK_BARANG) values('ELK-99','Barang - After Migration','BUAH',20);
Query OK, 1 row affected (0.07 sec)
MariaDB [mariadb]> select * from barang where KODE_BARANG ='ELK-99';
+-------------+--------------------------+---------------+-------------+------------+
| KODE_BARANG | NAMA_BARANG | SATUAN_BARANG | STOK_BARANG | keterangan |
+-------------+--------------------------+---------------+-------------+------------+
| ELK-99 | Barang - After Migration | BUAH | 20 | NULL |
+-------------+--------------------------+---------------+-------------+------------+
1 row in set (0.00 sec)
MariaDB [mariadb]> select * from barang;
+-------------+--------------------------+---------------+-------------+------------+
| KODE_BARANG | NAMA_BARANG | SATUAN_BARANG | STOK_BARANG | keterangan |
+-------------+--------------------------+---------------+-------------+------------+
| ELK-02 | LEMARI ES | UNIT | 8 | NULL |
| ELK-03 | TELEVISI | UNIT | 30 | NULL |
| ELK-04 | RADIO/TAPE | BUAH | 35 | NULL |
| ELK-05 | KOMPUTER | UNIT | 28 | NULL |
| ELK-06 | KIPAS ANGIN | BUAH | 38 | NULL |
| ELK-99 | Barang - After Migration | BUAH | 20 | NULL |
+-------------+--------------------------+---------------+-------------+------------+
6 rows in set (0.00 sec)
MariaDB [mariadb]>
No comments:
Post a Comment