Minggu, 19 Oktober 2014

Sistem Manajemen BAsis Data

Enter password: ****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.5.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, 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.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

1.Membuat DataBase Tugas1
mysql> create database tugas1;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| tugas1             |
+--------------------+
4 rows in set (0.00 sec)

2.Membuat Tabel T_BARANG Di dalam Tugas1
mysql> use tugas1;
Database changed
mysql> create table t_barang(id_barang varchar(8) primary key,
    -> nama_barang varchar(50),harga_barang bigint(11));
Query OK, 0 rows affected (0.15 sec)





3. Desc t_barang
mysql> desc t_barang;
+--------------+-------------+------+-----+---------+-------+
| Field        | Type        | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| id_barang    | varchar(8)  | NO   | PRI | NULL    |       |
| nama_barang  | varchar(50) | YES  |     | NULL    |       |
| harga_barang | bigint(11)  | YES  |     | NULL    |       |
+--------------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)

2.Membuat Tabel T_STOCK Di Dalam Tugas1
mysql> create table t_stock(id_stock varchar (8) primary key,
    -> id_barang varchar(8),foreign key(id_barang)references t_barang(id_barang)
,stock int (4));
Query OK, 0 rows affected (0.15 sec)
4.DESC T_STOCK
mysql> desc t_stock;
+-----------+------------+------+-----+---------+-------+
| Field     | Type       | Null | Key | Default | Extra |
+-----------+------------+------+-----+---------+-------+
| id_stock  | varchar(8) | NO   | PRI | NULL    |       |
| id_barang | varchar(8) | YES  | MUL | NULL    |       |
| stock     | int(4)     | YES  |     | NULL    |       |
+-----------+------------+------+-----+---------+-------+
3 rows in set (0.01 sec)



mysql> show tables;
+------------------+
| Tables_in_tugas1 |
+------------------+
| t_barang         |
| t_stock          |
+------------------+
2 rows in set (0.00 sec)
5. ISI TABEL T_BARANG
mysql> insert into t_barang values ('111', 'DJI SAM SOE', '15000');
Query OK, 1 row affected (0.82 sec)

mysql> insert into t_barang values ('112', 'SAM PO ERNA', '16000');
Query OK, 1 row affected (0.07 sec)

mysql> insert into t_barang values ('113', 'SA LI TI', '10000');
Query OK, 1 row affected (0.81 sec)

mysql> insert into t_barang values ('114', 'UMILD', '11000');
Query OK, 1 row affected (0.09 sec)

mysql> insert into t_barang values ('115', 'DJAROEM BLACK', '13000');
Query OK, 1 row affected (0.10 sec)

mysql> select * from t_barang;
+-----------+---------------+--------------+
| id_barang | nama_barang   | harga_barang |
+-----------+---------------+--------------+
| 111       | DJI SAM SOE   |        15000 |
| 112       | SAM PO ERNA   |        16000 |
| 113       | SA LI TI      |        10000 |
| 114       | UMILD         |        11000 |
| 115       | DJAROEM BLACK |        13000 |
+-----------+---------------+--------------+
5 rows in set (0.00 sec)
5.ISI TABEL T_STOCK
mysql> insert into t_stock values ('WX21', '111', '250');
Query OK, 1 row affected (0.04 sec)

mysql> insert into t_stock values ('WX61', '112', '200');
Query OK, 1 row affected (0.07 sec)

mysql> insert into t_stock values ('WX781', '113', '2600');
Query OK, 1 row affected (0.05 sec)

mysql> insert into t_stock values ('WX111', '114', '2220');
Query OK, 1 row affected (0.06 sec)

mysql> insert into t_stock values ('WX431', '115', '9999');
Query OK, 1 row affected (0.06 sec)


mysql> select * from t_stock;
+----------+-----------+-------+
| id_stock | id_barang | stock |
+----------+-----------+-------+
| WX111    | 114       |  2220 |
| WX21     | 111       |   250 |
| WX431    | 115       |  9999 |
| WX61     | 112       |   200 |
| WX781    | 113       |  2600 |
+----------+-----------+-------+
5 rows in set (0.00 sec)

6.MENGGANTI NAMA KOLOM STOCK T_STOCK MENJADI JUMLAH STOCK
mysql> alter table t_stock change stock jumlah_stock int(4);
Query OK, 5 rows affected (0.47 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> desc t_stock;
+--------------+------------+------+-----+---------+-------+
| Field        | Type       | Null | Key | Default | Extra |
+--------------+------------+------+-----+---------+-------+
| id_stock     | varchar(8) | NO   | PRI | NULL    |       |
| id_barang    | varchar(8) | YES  | MUL | NULL    |       |
| jumlah_stock | int(4)     | YES  |     | NULL    |       |
+--------------+------------+------+-----+---------+-------+
3 rows in set (0.01 sec)


7.TEMPORARY DAN MENGKOPY SELURUH DATA DARI T_BARANG
mysql> create temporary table t_temp_barang (id_barang varchar(8),
' at line 2
mysql> create temporary table t_temp_barang (id_barang varchar(8),
    -> nama_barang varchar(50),harga_barang bigint (11));
Query OK, 0 rows affected (0.13 sec)

mysql> desc t_temp_barang;
+--------------+-------------+------+-----+---------+-------+
| Field        | Type        | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| id_barang    | varchar(8)  | YES  |     | NULL    |       |
| nama_barang  | varchar(50) | YES  |     | NULL    |       |
| harga_barang | bigint(11)  | YES  |     | NULL    |       |
+--------------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)



0 komentar:

Posting Komentar

Popular Posts

 
Copyright © . peace love unity respect - Posts · Comments
Theme Template by BTDesigner · Powered by Blogger