1. MEMBUAT TABEL
Membuat Table Staff:
SQL> create table tb_staff(id_staff char(6) not null constraint tb_staff_pk primary key, nm_staff varchar2(30), jns_kelamin char(1), ttl varchar2(30), alamat varchar2(30), angkatan varchar2(4), jabatan varchar2(25), gaji varchar2(8));
Membuat Table Obat:
SQL> create table tb_obat(id_obat char(6) not null constraint tb_obat_pk primary key, nm_obat varchar2(30), tgl_masuk varchar2(25), tgl_kadaluarsa varchar2(25), fungsi varchar2(10), stok number(3), hrg_beli number(5), hrg_jual number(5));
Membuat Table Transaksi:
SQL> create table tb_transaksi(id_transaksi char(6) not null constraint tb_transaksi_pk primary key, tgl_transaksi varchar2(25), id_staff char(6), id_obat char(6), jml_item number(3), jml_harga number(7));
2. MENDEFINISIKAN CONSTRAINT
Foreign Key pada tb_transaksi
Memberi Foreign Key pada coloumn id_staff:
SQL> alter table tb_transaksi
> add constraint tb_transaksi_con_staff foreign key (id_staff)
> references tb_staff(id_staff);
Memberi Foreign Key pada coloumn id_obat:
SQL> alter table tb_transaksi
> add constraint tb_transaksi_con_obat foreign key(id_obat)
> references tb_obat(id_obat);
Dari Blog Sini Ngambilnya