Entri Populer

Selasa, 01 April 2014

Tugas SQL Functions

SQL FUNCTIONS
SQL AVG
SELECT AVG(sks_matkul) AS sksAverage FROM matkul;
Menampilkan jumlah rata rata pada colum
SQL COUNT


SQL FIRST
SELECT nama_mahasiswa FROM mahasiswa ORDER BY id_mhs ASC
LIMIT 2;
Menampilkan dan mengurutkan pada colum nama mahasiswa. Dari urutan abjad paling atas
SQL LAST
SELECT nama_mahasiswa FROM mahasiswa ORDER BY id_mhs desc
LIMIT 2;
Menampilkan dan mengurutkan pada colum nama mahasiswa. Dari urutan abjad paling bawah
SQL MAX
SELECT MAX(angka_matkul) AS Highestangka FROM detailipk;
Menampilkan angka paling besar pada colum yang di ambil dari table
SQL MIN
SELECT MIN(angka_matkul) AS Minangka FROM detailipk;
Menampilkan angka paling kecil pada colum yang di ambil dari table








Selasa, 15 Oktober 2013

Tugas Inventaris CDM,PDM,&Script

CONCEPTUAL DATA MODEL

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;