You are on page 1of 3

CREATE DATABASE perpustakaan;

CREATE TABLE tanggota

id_anggota integer NOT NULL,

nama_anggota character(30),

alamat_anggota character(30),

no_hp_anggota numeric,

CONSTRAINT pk_id_anggota PRIMARY KEY (id_anggota )

);

CREATE TABLE tkatbuku

id_kat_buku integer NOT NULL,

nama_kat_buku character(30),

CONSTRAINT pk_id_jenisbuku PRIMARY KEY (id_kat_buku )

);

CREATE TABLE tpenerbit

id_penerbit integer NOT NULL,

nama_penerbit character(30),

CONSTRAINT pk_id_penerbit PRIMARY KEY (id_penerbit )

);

CREATE TABLE tpengarang

id_pengarang integer NOT NULL,

nama_pengarang character(30),

CONSTRAINT pk_id_pengaran PRIMARY KEY (id_pengarang )

);
CREATE TABLE tbuku

isbn character(17) NOT NULL,

judul_buku character(30),

id_kat_buku integer,

id_pengarang integer,

id_penerbit integer,

thn_terbit character(4),

CONSTRAINT pk_isbn PRIMARY KEY (isbn ),

CONSTRAINT fk_id_penerbit FOREIGN KEY (id_penerbit)

REFERENCES tpenerbit (id_penerbit) MATCH SIMPLE

ON UPDATE CASCADE ON DELETE CASCADE,

CONSTRAINT fk_id_pengarang FOREIGN KEY (id_pengarang)

REFERENCES tpengarang (id_pengarang)

ON UPDATE CASCADE ON DELETE CASCADE,

CONSTRAINT fk_kat_buku FOREIGN KEY (id_kat_buku)

REFERENCES tkatbuku (id_kat_buku) MATCH SIMPLE

ON UPDATE CASCADE ON DELETE CASCADE

);

CREATE TABLE tpeminjaman

id_peminjaman integer NOT NULL,

isbn character(17),

id_anggota integer,

tgl_peminjaman date,

tgl_hbs_peminjaman date,

tgl_pengembalian date,

CONSTRAINT pk_id_peminjaman PRIMARY KEY (id_peminjaman ),

CONSTRAINT fk_id_anggota FOREIGN KEY (id_anggota)


REFERENCES tanggota (id_anggota)

ON UPDATE CASCADE ON DELETE CASCADE,

CONSTRAINT fk_isbn FOREIGN KEY (isbn)

REFERENCES tbuku (isbn) MATCH SIMPLE

ON UPDATE CASCADE ON DELETE CASCADE

);