Feri Pribadi webdevelopers AKU Belajar: Cara Membuat Database

27 Desember 2012

Cara Membuat Database



mysql>create database kontraktor;

mysql> use kontraktor;

Database changed



Membuat tabel proyek

mysql>create table proyek(kode_proyek varchar(10),waktu_proyek varchar(20), lokasi varchar(20));



Memasukkan data proyek

mysql>insert into proyek values(‘R01’,’3 bulan’,’Jakarta’);

mysql>insert into proyek values(‘R02’,’5 bulan’,’Depok’);

mysql>insert into proyek values(‘B01’,’10 bulan’,’Bogor’);

mysql>insert into proyek values(‘B02’,’10 bulan’,’Bekasi’);

mysql>insert into proyek values(‘B03’,’14 bulan’,’Depok’);



Menampilkan tabel proyek

mysql> select * from proyek;

+-------------+--------------+---------+

| kode_proyek | waktu_proyek | lokasi  |

+-------------+--------------+---------+

| R01         | 3 Bulan      | Jakarta |

| R02         | 5 Bulan      | Depok   |

| B01         | 10 Bulan     | Bogor   |

| B02         | 10 Bulan     | Bekasi  |

| B03         | 14 Bulan     | Depok   |

+-------------+--------------+---------+

5 rows in set (0.00 sec)



Membuat tabel pekerja

mysql>create table pekerja(Id_pekerja int(10),nama_pekerja varchar(20), lokasi varchar(20));



Memasukkan data pekerja

mysql>insert into pekerja values(‘1201’,’feri’,’Jakarta’);

mysql>insert into pekerja values(‘1202’,’Andi’,’Depok’);

mysql>insert into pekerja values(‘1204’,’Anto’,’Bekasi’);

mysql>insert into pekerja values(‘1205’,’Doni’,’depok’);



Menampilkan tabel pekerja

mysql> select * from pekerja;

+------------+--------------+---------+

| Id_pekerja | nama_pekerja | lokasi  |

+------------+--------------+---------+

| 1201       | feri         | jakarta |

| 1202       | Andi         | Depok   |

| 1203       | asep         | bogor   |

| 1204       | Anto         | bekasi  |

| 1205       | doni         | depok   |

+------------+--------------+---------+

5 rows in set (0.00 sec)



Membuat tabel biaya

mysql>create table biaya(kode_proyek varchar(10),biaya_proyek int(20), Id_pekerja int(10));



Memasukkan data biaya

mysql>insert into biaya values(‘R01’,’15000000’,’1201’);

mysql>insert into biaya values(‘R02’,’30000000’,’1202’);

mysql>insert into biaya values(‘B01’,’175000000’,’1203’);

mysql>insert into biaya values(‘B02’,’150000000’,’1204’);

mysql>insert into biaya values(‘B03’,’450000000’,’1205’);



Menampilkan tabel biaya

mysql> select * from biaya;

+-------------+--------------+------------+

| kode_proyek | biaya_proyek | Id_pekerja |

+-------------+--------------+------------+

| R01         | 15000000     |       1201 |

| R02         | 30000000     |       1202 |

| B01         | 175000000    |       1203 |

| B02         | 150000000    |       1204 |

| B03         | 450000000    |       1205 |

+-------------+--------------+------------+

5 rows in set (0.00 sec)



Membuat tabel laporan

mysql>create table laporan(kode_proyek varchar(10), pengeluaran int(20), keuntungan int(20));



Memasukkan data laporan

mysql>insert into laporan values(‘R01’,’8500000’,’6500000’);

mysql>insert into laporan values(‘R02’,’25000000’,’5000000’);

mysql>insert into laporan values(‘B01’, ’125000000’,’50000000’);

mysql>insert into laporan values(‘B02’, ’115000000’,’35000000’);

mysql>insert into laporan values(‘B03’,’375000000’,’75000000’);



Menampilkan tabel laporan

mysql> select * from laporan;

+-------------+-------------+------------+

| kode_proyek | pengeluaran | keuntungan |

+-------------+-------------+------------+

| R01         | 8500000     | 6500000    |

| R02         | 25000000    | 5000000    |

| B01         | 125000000   | 50000000   |

| B02         | 115000000   | 35000000   |

| B03         | 375000000   | 75000000   |

+-------------+-------------+------------+

5 rows in set (0.00 sec)



Relasi 2 Tabel

mysql> select proyek.kode_proyek, proyek.lokasi, biaya.biaya_proyek from proyek, biaya where proyek.kode_proyek = biaya.kode_proyek;

+-------------+---------+--------------+

| kode_proyek | lokasi  | biaya_proyek |

+-------------+---------+--------------+

| R01         | Jakarta | 15000000     |

| R02         | Depok   | 30000000     |

| B01         | Bogor   | 175000000    |

| B02         | Bekasi  | 150000000    |

| B03         | Depok   | 450000000    |

+-------------+---------+--------------+

5 rows in set (0.00 sec)



Relasi 3 Tabel

mysql> select proyek.kode_proyek, proyek.lokasi, biaya.biaya_proyek, pekerja.nama_pekerja from proyek, biaya, pekerja where proyek.kode_proyek = biaya.kode_proyek AND biaya.Id_pekerja = pekerja.Id_pekerja;



+-------------+---------+--------------+--------------+

| kode_proyek | lokasi  | biaya_proyek | nama_pekerja |

+-------------+---------+--------------+--------------+

| R01         | Jakarta | 15000000     | feri         |

| R02         | Depok   | 30000000     | Andi         |

| B01         | Bogor   | 175000000    | asep         |

| B02         | Bekasi  | 150000000    | Anto         |

| B03         | Depok   | 450000000    | doni         |

+-------------+---------+--------------+--------------+

5 rows in set (0.00 sec)



Relasi 4 Tabel

mysql> select proyek.kode_proyek, biaya.biaya_proyek, pekerja.nama_pekerja, laporan.keuntungan from proyek, biaya, pekerja, laporan where proyek.kode_proyek = biaya.kode_proyek AND biaya.Id_pekerja = pekerja.Id_pekerja AND biaya.kode_proyek = laporan.kode_proyek;



+-------------+--------------+--------------+------------+

| kode_proyek | biaya_proyek | nama_pekerja | keuntungan |

+-------------+--------------+--------------+------------+

| R01         | 15000000     | feri         | 6500000    |

| R02         | 30000000     | Andi         | 5000000    |

| B01         | 175000000    | asep         | 50000000   |

| B02         | 150000000    | Anto         | 35000000   |

| B03         | 450000000    | doni         | 75000000   |

+-------------+--------------+--------------+------------+

5 rows in set (0.00 sec)
http://pribadiferi.blogspot.com/ 

Tidak ada komentar:

Posting Komentar