Friday, March 20, 2015

Contoh Pembuatan Table Barang Pada Oracle

Berikut adalah contoh pembuatan table barang pada oracle yang meruapakan catatan saya saat mendapatkan mata kuliah database dimana aplikasi yang digunakan adalah oracle 10g. Selain pembuatan table disini juga ada contoh memasukkan data ke dalam table dan ada juga contoh perintah select. Semoga membantu.

//Syntax pembuatan table barang

create table barang
(kd_bar char(6),
nm_bar varchar2(25),
satuan varchar2(20),
stok number(4),
harga number(9),
constraint pk_barang primary key(kd_bar));

create table suplier
(kd_supl char(5),
nm_supl varchar2(30),
alm_supl varchar2(30),
kota_supl varchar2(15),
telp_supl varchar2(15),
constraint pk_suplier primary key(kd_supl));

create table customer
(kd_cust char(6),
nm_cust varchar2(30),
alm_cust varchar2(30),
kota_cust varchar2(15),
telp_cust varchar2(15),
constraint pk_customer primary key(kd_cust));

create table pembelian
(no_nota char(7),
kd_cust char(6),
tgl_beli date,
total_beli number(9),
constraint pk_pembelian primary key(no_nota),
constraint fk_pembelian_customer foreign key(kd_cust) references customer(kd_cust));

create table pasok
(kd_bar char(6),
kd_supl char(5),
tgl_pas date,
jlm_pas number(4),
constraint fk_pasok_barang foreign key(kd_bar) references barang(kd_bar),
constraint fk_pasok_suplier foreign key(kd_supl) references suplier(kd_supl));

create table detil_beli
(no_nota char(7),
kd_bar char(6),
qty number(4),
harga number(9),
constraint fk_detil_beli_pembelian foreign key(no_nota) references pembelian(no_nota),
constraint fk_detil_beli_barang foreign key(kd_bar) references barang(kd_bar));

//Systax input data ke table barang

insert into barang values('ELK_01','RICE COOKER','BUAH','20','50000');
insert into barang values('ELK_02','LEMARI ES','UNIT','8','1500000');
insert into barang values('ELK_03','TELEVISI','UNIT','30','1200000');
insert into barang values('ELK_04','RADIO/TAPE','BUAH','35','35000');


insert into suplier values('EJ-01','PT. ACTRON','JL. THAMRIN 21','JAKARTA','(021)555222');
insert into suplier values('EJ-02','PT. MULYA ELEKTRONIK','JL. SUDIRMAN 45','JAKARTA','(021)821329');
insert into suplier values('EJ-03','PT. ULTRASOUND','JL. VETERAN 100X','DENPASAR','(0361)555222');
insert into suplier values('EJ-04','PT. CAHAYA','JL. GAJAH MADA 202','TABANAN','(0361)832178');

insert into customer values('J-0001','TOKO KARISMA','JL. CIMANGGIS 34','JAKARTA','(021)8564209');
insert into customer values('J-0002','TOKO AYU','JL. MAJAPAHIT 3','JAKARTA','(021)7651234');
insert into customer values('J-0003','TOKO WARNA','JL. COKROAMINOTO 334X','DENPASAR','(0361)224209');
insert into customer values('J-0004','TOKO SURYA','JL. HAYAM WURUK 14','TABANAN','(0361)811011');

insert into pembelian values('NT-001','J-0001',TO_DATE('10-08-2003','DD-MM-YYYY'),'500000');
insert into pembelian values('NT-002','J-0001',TO_DATE('20-10-2003','DD-MM-YYYY'),'200000');
insert into pembelian values('NT-003','J-0002',TO_DATE('02-11-2003','DD-MM-YYYY'),'60000');
insert into pembelian values('NT-004','J-0003',TO_DATE('15-08-2003','DD-MM-YYYY'),'250000');
insert into pembelian values('NT-005','J-0001',TO_DATE('19-12-2003','DD-MM-YYYY'),'300000');
insert into pembelian values('NT-006','J-0001',TO_DATE('01-12-2003','DD-MM-YYYY'),'35000');

insert into pasok values('ELK_01','EJ-01',TO_DATE('01-01-2002','DD-MM-YYYY'),'5');
insert into pasok values('ELK_01','EJ-02',TO_DATE('01-01-2002','DD-MM-YYYY'),'8');
insert into pasok values('ELK_02','EJ-01',TO_DATE('01-02-2002','DD-MM-YYYY'),'2');
insert into pasok values('ELK_02','EJ-02',TO_DATE('02-02-2002','DD-MM-YYYY'),'3');
insert into pasok values('ELK_02','EJ-04',TO_DATE('01-01-2002','DD-MM-YYYY'),'2');
insert into pasok values('ELK_03','EJ-01',TO_DATE('03-03-2002','DD-MM-YYYY'),'5');
insert into pasok values('ELK_03','EJ-01',TO_DATE('04-03-2002','DD-MM-YYYY'),'2');
insert into pasok values('ELK_03','EJ-01',TO_DATE('03-03-2002','DD-MM-YYYY'),'3');
insert into pasok values('ELK_03','EJ-03',TO_DATE('13-03-2002','DD-MM-YYYY'),'4');
insert into pasok values('ELK_03','EJ-03',TO_DATE('13-03-2002','DD-MM-YYYY'),'3');
insert into pasok values('ELK_04','EJ-03',TO_DATE('22-04-2002','DD-MM-YYYY'),'12');
insert into pasok values('ELK_04','EJ-04',TO_DATE('30-04-2002','DD-MM-YYYY'),'9');

insert into detil_beli values('NT-001','ELK_01','4','50000');
insert into detil_beli values('NT-001','ELK_02','1','1500000');
insert into detil_beli values('NT-002','ELK_01','4','50000');
insert into detil_beli values('NT-003','ELK_03','1','1200000');
insert into detil_beli values('NT-003','ELK_04','2','35000');
insert into detil_beli values('NT-003','ELK_01','2','50000');
insert into detil_beli values('NT-004','ELK_04','10','350000');
insert into detil_beli values('NT-005','ELK_01','1','50000');
insert into detil_beli values('NT-005','ELK_04','1','35000');
insert into detil_beli values('NT-006','ELK_02','1','1500000');


No comments:

Post a Comment