Rancangan Basis Data 1. Context Data Model (CDM) Berisikan pemodelan data yang tertuang dalam analisa data beserta relasi yang ada dalam bentuk ERD yang diusulkan Peter P.Chen, CDM hanya memperlihatkan item-item sebagai berikut : - Entiti - Relasi - Kardinalitas Mahaiswa
4/20/2007
M
N Isi
KRS
M
Fathur'2011
N Pilih
Matakuliah
Pemodelan Data : Entity Relationship Diagram (ERD)/Diagram Hubungan Entitas (DHE) Fungsi : - memodelkan data - melihat data yang akan disimpan Simbol-simbol : : - Entity Set/objek data - Kata benda Contoh : mahasiswa, pelanggan, barang, dan lain-lain
: - Relationship/hubungan - Menghubungan entity set - Kata kerja contoh : kerja, ambil, isi, dan lain-lain Atribut
: Ciri dari sebuah entity
Cardinality : - tingkat hubungan - melihat tingkat hubungan suatu relationship 1 : M (hubungan satu ke banyak) M : N (hubungan banyak ke banyak) 1 : 1 (hubungan satu ke satu) Tidak boleh ada hubungan antar relationship 4/20/2007
Fathur'2011
The Entity Relationship (ER) Model • ER Modeling is a top-down approach to database design. • Entity Relationship (ER) Diagram – A detailed, logical representation of the entities, associations and data elements for an organization or business
• ERD represents the conceptual database as viewed by end user • ERDs depict the ER model’s three main components: – Entities – Attributes
Entity-Relationship (ER) Modeling. • ER Modeling is a top-down approach to database design. • Entity Relationship (ER) Diagram – A detailed, logical representation of the entities, associations and data elements for an organization or business
• Notation uses three main constructs – Data entities – Relationships – Attributes
Chen Model & Crow’s Foot Model
Chen Notation
Association between the instances of one or more entity types EntityName
Person, place, object, event or concept about which data is to be maintained Represents a set or collection of objects in the real world that share the same properties
Verb Phrase
AttributeName
named property or characteristic of an entity
Entities • Refers to the entity set and not to a single entity occurrence • Corresponds to a table and not to a row in the relational environment
• In both the Chen and Crow’s Foot models, an entity is represented by a rectangle containing the entity’s name • Entity name, a noun, is usually written in capital letters
Entity vs. Entity Set (Entities) Entity Set (Entities) --- Student John Smith
entity
(999-21-3415, jsmith@, John Smith, 18, 3.5)
Students in ITCS3160 999-21-3415, jsmith@, John Smith, 18, 3.5 999-31-2356, jzhang@, Jie Zhang, 20, 3.0 999-32-1234, ajain@, Anil Jain, 21, 3.8
Is it an entity? Rules: 1. An entity must be important to the organisation. 2. An entity must have at least one attribute. 3. An entity must occur more than once (there must be more than one customer) 4. Each entity occurrence (record) must be uniquely identifiable (customer id)
Entities • Examples of entities: – – – – –
Person: EMPLOYEE, STUDENT, PATIENT Place: STORE, WAREHOUSE Object: MACHINE, PRODUCT, CAR Event: SALE,REGISTRATION, RENEWAL Concept: ACCOUNT, COURSE
• Guidelines for naming and defining entity types: – – – –
An entity type name is a singular noun An entity type should be descriptive and specific An entity name should be concise Event entity types should be named for the result of the event, not the activity or process of the event.
Attributes • Characteristics of entities • In Chen model, attributes are represented by ovals and are connected to the entity rectangle with a line • Each oval contains the name of the attribute it represents • In the Crow’s Foot model, the attributes are simply written in the attribute box below the entity rectangle
Jenis Attribute • Composite vs Simple(atomic) Attributes • Single-valued vs Multivalued Attributes • Stored vs Derived Attributes • Null values • Complex Attributes • Key Attribute
4/20/2007
Fathur'2011
Composite vs Simple (Atomic) • Composite attributes dapat dibagi ke subbagian yang lebih kecil dan merepresentasikan attribute yang lebih dasar • Simple attributes tidak dapat dibagi • Contoh: Alamat -> Jalan, Kota, Propinsi,KodePos, Negara; Jalan -> NoRumah, NamaJalan Single-valued vs Multivalued Attributes • umur -> single-valued • noTelpon -> multivalued Store vs Derived Attributes • umur -> derived attribute dari tglLahir • tglLahir -> stored attribute Null values • noTelpon -> null (jika tidak punya telpon) 4/20/2007
Fathur'2011
Relationship • Manager yang mengelola suatu Department -> hubungan antara Employee dengan Department; manages • Department yang mengontrol suatu Project -> hubungan antara entity Department dengan Project; controls • Employee yang bekerja pada Department tertentu -> hubungan antara entity Employee dengan Department; works_for • Cardinality Ratios untuk relationship biner menggambarkan jumlah instances suatu entity dapat berpartisipasi Contoh: works_for; DEPARTMENT:EMPLOYEE = 1:N Kemungkinan cardinality ratios: 1:1, 1:N, N:1, M:N
4/20/2007
Fathur'2011
A
M
Id_A(pk) - dt_A
A
1
Id_A(pk) - dt_A
4/20/2007
1
C Id_A(fk) Id_B(fk)
1
B Id_B(pk) - dt_B
Id_A(fk) Id_B(fk) - Dt_C
Id_A(pk) - dt_A
A
N
C
B Id_B(pk) -dt_B -id_A(FK )
C Id_A(fk) Id_B(fk)
Fathur'2011
M
B Id_B(pk) dt_B -Id_B(fk)
contoh : 1. Dalam sistem perkuliahan, seorang mahasiswa dapat mengambil lebih dari satu mata kuliah, dan 1 mata kuliah dapat diambil oleh lebih 1 mahasiswa. ERD-nya adalah : Mahaiswa
NIM (PK) Nama Alamat
M
ambil NIM (FK) KdKul (FK) Nilai
N
Mata kuliah
KdKul (PK) NamaKul sks
2. Dalam sistem kepegawaian, jika asumsi seorang pegawai dapat memegang lebih dari satu jabatan dan satu jabatan hanya dapat dipegang oleh satu pegawai, maka ERD-nya adalah ?
4/20/2007
Fathur'2011
Jenis-Jenis Entitas : 1. Weak Entity (Entitas lemah) Terjadi bila sebuah entity tidak memiliki primary key bergantung pada strong key Contoh : Pegawai
1
M
Isi
* NIP - Nama - Alamat
Pinjaman
* NoPinj - tgl - jum - ferk
4/20/2007
Absensi - tanggal - jum_masuk - jum_keluar
M
angsu r * NoPinj
Fathur'2011
N
Angsuran
- tglBayar - Jum_Angsur
Jenis-Jenis Entitas : 2. Agregation (Agregasi) Terjadi bila dua buah entiti yang berlesai akan direlasikan ke entiti lain. Contoh ; Anggota
M
pinja m * Noang * NoBuku
* Noang - Nama - Alamat
N
Buku * NoBuku - Judul
M
* Noang * NoBuku * Kd_Denda - Jumlah
Kembal i N Denda
4/20/2007
* Kd_Denda - Jenis
Fathur'2011
Jenis-Jenis Entitas : 3. Spesialisasi dan Generalisasi (Is A) Terjadi bila terdapat beberpa atribut pada beberapa entiti dengan Primary Key (PK) yang sama. Contoh : Koleksi * No_Koleksi - Tgl_Beli Is A Buku - Judul - Pengarang - Harga
Skripsi - Judul - NRP
Pegawai
Majalah - Nama - Edisi - Harga * NIP - Nama
Is A
4/20/2007
Tetap - GajiPokok - t_anak - t_sehat
Honorer - Upah_Hari - UpahLembur Fathur'2011
2. Logical Data Model (LDM) Berisikan ERD yang didasarkan pada CDM yang ada. LDM menggunakan notasi ERD yang diusulkan oleh James Martin atau dikenal dengan notasi Informastion Engineering. Bentuk LDM ini sudah menyertakan item-item berikut : - Entiti - Kardinalitas - Atribut-atribut key dan non key - Transformasi kardinalitas Many-to-Many dalam CDM ke dalam bentuk Associative Entity MHS NIM (PK) Nama Alamat TmpLahir TglLahir KdJurusan ThnMasuk Status
4/20/2007
KRS NoKrs (PK1) (FK) NIM (PK2) (FK) ThAkad Semester StatusStudi
Fathur'2011
PilihMK NoKRS (PK1)(FK) KodeMK (PK2)(FK) StatusUlang HMutu
Notasi LDM • Chen Model – 1 to represent one. – M to represent many
1
M
• Crow’s Foot One
One or one
many One or many
Zero
4/20/2007
Zero or many
Fathur'2011
handles
Lecturer (1,1)
(0,N) M
1
Lecturer
Class
handles (0,N)
Class (1,1)
A Lecturer may handle zero or many classes.
A class is handled by one and only one Lecturer.
4/20/2007
Fathur'2011