PHYSICAL DATA MODEL
SCRIPT
/*==============================================================*/
/* DBMS name: Sybase SQL Anywhere 11 */
/* Created on: 10/16/2013 11:50:43 */
/*==============================================================*/
if exists(select 1 from sys.sysforeignkey where role='FK_BARANG_RELATIONS_RUANGAN') then
alter table BARANG
delete foreign key FK_BARANG_RELATIONS_RUANGAN
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_RUANGAN_RELATIONS_KARYAWAN') then
alter table RUANGAN
delete foreign key FK_RUANGAN_RELATIONS_KARYAWAN
end if;
if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='RELATIONSHIP_2_FK'
and t.table_name='BARANG'
) then
drop index BARANG.RELATIONSHIP_2_FK
end if;
if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='BARANG_PK'
and t.table_name='BARANG'
) then
drop index BARANG.BARANG_PK
end if;
if exists(
select 1 from sys.systable
where table_name='BARANG'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table BARANG
end if;
if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='KARYAWAN_PK'
and t.table_name='KARYAWAN'
) then
drop index KARYAWAN.KARYAWAN_PK
end if;
if exists(
select 1 from sys.systable
where table_name='KARYAWAN'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table KARYAWAN
end if;
if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='RELATIONSHIP_1_FK'
and t.table_name='RUANGAN'
) then
drop index RUANGAN.RELATIONSHIP_1_FK
end if;
if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='RUANGAN_PK'
and t.table_name='RUANGAN'
) then
drop index RUANGAN.RUANGAN_PK
end if;
if exists(
select 1 from sys.systable
where table_name='RUANGAN'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table RUANGAN
end if;
/*==============================================================*/
/* Table: BARANG */
/*==============================================================*/
create table BARANG
(
KODE_BARANT integer not null,
NOMOR_RUANGAN integer null,
NAMA_BARANG char(20) null,
JENIS_BARANG char(20) null,
JUMLAH_BARANG integer null,
constraint PK_BARANG primary key (KODE_BARANT)
);
/*==============================================================*/
/* Index: BARANG_PK */
/*==============================================================*/
create unique index BARANG_PK on BARANG (
KODE_BARANT ASC
);
/*==============================================================*/
/* Index: RELATIONSHIP_2_FK */
/*==============================================================*/
create index RELATIONSHIP_2_FK on BARANG (
NOMOR_RUANGAN ASC
);
/*==============================================================*/
/* Table: KARYAWAN */
/*==============================================================*/
create table KARYAWAN
(
ID_KARYAWAN integer not null,
NAMA_KARYAWAN char(30) null,
JABATAN char(20) null,
ALAMAT varchar(40) null,
JENIS_KELAMIN char(10) null,
constraint PK_KARYAWAN primary key (ID_KARYAWAN)
);
/*==============================================================*/
/* Index: KARYAWAN_PK */
/*==============================================================*/
create unique index KARYAWAN_PK on KARYAWAN (
ID_KARYAWAN ASC
);
/*==============================================================*/
/* Table: RUANGAN */
/*==============================================================*/
create table RUANGAN
(
NOMOR_RUANGAN integer not null,
ID_KARYAWAN integer null,
NAMA_RUANGAN char(20) null,
JENIS_RUANGAN char(20) null,
constraint PK_RUANGAN primary key (NOMOR_RUANGAN)
);
/*==============================================================*/
/* Index: RUANGAN_PK */
/*==============================================================*/
create unique index RUANGAN_PK on RUANGAN (
NOMOR_RUANGAN ASC
);
/*==============================================================*/
/* Index: RELATIONSHIP_1_FK */
/*==============================================================*/
create index RELATIONSHIP_1_FK on RUANGAN (
ID_KARYAWAN ASC
);
alter table BARANG
add constraint FK_BARANG_RELATIONS_RUANGAN foreign key (NOMOR_RUANGAN)
references RUANGAN (NOMOR_RUANGAN)
on update restrict
on delete restrict;
alter table RUANGAN
add constraint FK_RUANGAN_RELATIONS_KARYAWAN foreign key (ID_KARYAWAN)
references KARYAWAN (ID_KARYAWAN)
on update restrict
on delete restrict;

