Upload presentasi
Presentasi sedang didownload. Silahkan tunggu
1
Aljabar Relasi SBD
2
Aljabar Relasi Merupakan Procedural language Operator-operator dasar
select: project: union: set difference: – Cartesian product: x rename: Operator menggunakan 1 atau 2 relasi sebagai masukan dan menghasilkan relasi baru
3
Operasi Select A=B ^ D > 5 (r) relasi r A B C D 1 5 12 23
7 3 10 A=B ^ D > 5 (r) A B C D 1 23 7 10
4
Select Notasi: p(r) p : predikat seleksi
Definisikan sebagai: p(r) = {t | t r and p(t)} dimana p merupakan suatu formula dalam kalkulus proposional yang terdiri dari atribut/konstanta yg dihubungkan dengan : (and), (or), (not) <attribute> op <attribute> or <constant> op : =, , >, . <. Contoh selection: tmp_lahir=“Pekalongan”(mahasiswa)
5
Mohammad Arief Fatkhuriza
Contoh Selection tmp_lahir=“Pekalongan” v jurusan=“Syariah” (mahasiswa) m_nim m_nama tmp_lahir jurusan Syamsul Arifin Pekalongan Syariah Mohammad Arief Fatkhuriza Yuli Wahyuiningrum Siti Zuhrotun Nisa Sri Mulyani Mohamad Noor Faiz Nunung Kurniawati Aminatul Azkiyah Sugiyanto.H.S.
6
Project Relation r: A,C (r) A B C 10 20 30 40 1 2 A C A C 1 2
=
7
Project Notasi: A1, A2 : nama atribut r : suatu nama relasi.
Hasil merupakan relasi dari sejumlah k kolom yg disebutkan dengan menghilangkan kolom yang tidak ada dalam daftar. Baris Kembar dihilangkan Contoh : m_nim, m_nama,tmp_lahir (mahasiswa)
8
Mohammad Arief Fatkhuriza
Contoh Project m_nim, m_nama,tmp_lahir (mahasiswa) m_nim m_nama tmp_lahir Syamsul Arifin Pekalongan Mohammad Arief Fatkhuriza Yuli Wahyuiningrum Siti Zuhrotun Nisa Sri Mulyani Mohamad Noor Faiz Nunung Kurniawati Aminatul Azkiyah Sugiyanto.H.S.
9
Union Relasi r, s: A B A B 1 2 2 3 s r A B 1 2 3 r s:
10
Union Notasi: r s Didefinisikan sbg: r s = {t | t r or t s}
untuk r s menjadi valid. 1. r, s harus memiliki jumlah atribut yg sama (memiliki aritas yg sama ) 2. Domain/tipe attribute harus sesuai Contoh: mendapatkan seluruh kota tempat lahir dari mahasiswa ataupun dosen tmp_lahir (mahasiswa) tmp_lahir (dosen)
11
Contoh Union tmp_lahir (mahasiswa) tmp_lahir (dosen) tmp_lahir
Tasikmalaya Tangerang Solo Pemalang Pekalongan tmp_lahir Bumiayu Kudus Banyumas Pekalongan Tegal Sumedang Pemalang Batang tmp_lahir Bumiayu Kudus Banyumas Pekalongan Tegal Sumedang Pemalang Batang Brebes Jakarta Solo Tasikmalaya Tangerang
12
Set Difference Relasi r, s:
Merupakan operasi pengurangan data di tabel pertama oleh data di tabel ke dua Relasi r, s: A B A B 1 2 2 3 s r r – s: A B 1
13
Set Difference Notasi r – s Defined as: r – s = {t | t r and t s}
r dan s harus memiliki kesamaan aritas domains attribute(tipe data) r dan s harus sama
14
Contoh set difference Mendapatkan kota lahir yang ada di tabel mahasiswa tapi tidak ada di tabel dosen tmp_lahir (mahasiswa) - tmp_lahir (dosen) Mahasiswa tmp_lahir Solo Pekalongan Batang Pemalang Tasikmalaya Tanggerang Jakarta Banyumas Dosen tmp_lahir Bumiayu Kudus Banyumas Pekalongan Tegal Sumedang Pemalang Batang Brebes Jakarta Mahasiswa tmp_lahir Solo Batang Tasikmalaya Tanggerang Jakarta
15
Cartesian-Product Menggabungkan data dari dua tabel/hasil query
Relations r, s: A B C D E 1 2 10 20 a b r s r x s: A B C D E 1 2 10 20 a b
16
Cartesian-Product Notasi r x s Defined as:
r x s = {t q | t r and q s} Attributes r(R) dan s(S) merupakan atribut disjoint. (That is, R S = ).
17
Contoh cartesian product
(mahasiswa x Nilai) Nilai m_nim smt kdmk klpk nilai_huruf 6 SE2 2204 SY.2 A SE2 2307 B+ C+ Mahasiswa m_nim m_nama Asrori Dwi Prasongko Nilai x Mahasiswa m_nim smt kdmk klpk nilai_huruf m_nama 6 SE2 2204 SY.2 A Asrori SE2 2307 B+ C+ Dwi Prasongko
18
Cartesian product nilai.m_nim=mahasiswa.m_nim (nilai x mahasiswa )
m_nim,m_nama,kdmk,nilai_huruf ( nilai.m_nim=mahasiswa.m_nim (mahasiswa x nilai)) m_nim smt kdmk klpk nilai_huruf m_nama 6 SE2 2204 SY.2 A Asrori SE2 2307 B+ Dwi Prasongko C+ m_nim m_nama kdmk nilai_huruf Asrori SE2 2204 A SE2 2307 Dwi Prasongko B+ C+
19
Komposisi Dapat terdiri dari beberapa operasi Contoh : A=C(r x s)
1 2 10 20 a b A B C D E 1 2 10 20 a b
20
Contoh komposisi m_nim,m_nama,kdmk,nmmk,nilai_huruf ( nilai.m_nim=mahasiswa.m_nim nilai.kdmk=matakuliah.kdmk (mahasiswa x nilai x matakuliah)) m_nim m_nama kdmk nilai_huruf Asrori SE2 2204 Pemikiran Ekonomi Islam A SE2 2307 Matematika Ekonomi Dwi Prasongko B+ C+
21
Rename Operation Melakukan penamaan pada suatu tabel/hasil proyeksi.
Contoh: x (E) x adalah nama baru dari ekspresi E Untuk ekspresi E dengan n atribut dimana A1,A2 adalah atribut pada E
22
Rename m_nim,m_nama,kdmk,nmmk,nilai_huruf ( n.m_nim=mhs.m_nim n.kdmk=mk.kdmk (mhs ( mahasiswa) x n( nilai) x mk ( matakuliah))
23
Banking Example branch (branch_name, branch_city, assets)
customer (customer_name, customer_street, customer_city) account (account_number, branch_name, balance) loan (loan_number, branch_name, amount) depositor (customer_name, account_number) borrower (customer_name, loan_number)
24
Example Queries amount > 1200 (loan)
Find all loans of over $1200 amount > 1200 (loan) Find the loan number for each loan of an amount greater than $1200 loan_number (amount > 1200 (loan)) Find the names of all customers who have a loan, an account, or both, from the bank customer_name (borrower) customer_name (depositor)
25
Example Queries Find the names of all customers who have a loan at the Perryridge branch. customer_name (branch_name=“Perryridge” (borrower.loan_number = loan.loan_number(borrower x loan))) Find the names of all customers who have a loan at the Perryridge branch but do not have an account at any branch of the bank. customer_name (branch_name = “Perryridge” (borrower.loan_number = loan.loan_number(borrower x loan))) – customer_name(depositor)
26
Example Queries Find the names of all customers who have a loan at the Perryridge branch. Query 1 customer_name (branch_name = “Perryridge” ( borrower.loan_number = loan.loan_number (borrower x loan))) Query 2 customer_name(loan.loan_number = borrower.loan_number ( (branch_name = “Perryridge” (loan)) x borrower))
27
Formal Definition A basic expression in the relational algebra consists of either one of the following: A relation in the database A constant relation Let E1 and E2 be relational-algebra expressions; the following are all relational-algebra expressions: E1 E2 E1 – E2 E1 x E2 p (E1), P is a predicate on attributes in E1 s(E1), S is a list consisting of some of the attributes in E1 x (E1), x is the new name for the result of E1
28
Write the following queries in relational algebra
Find the titles of courses in the Comp. Sci. department that have 3 credits. Find the IDs of all students who were taught by an instructor named Einstein;make sure there are no duplicates in the result.
30
Latihan 3. Tampilkan instruktur dari dept_name= ' Comp. Sci ‘
4. Tampilkan instruktur dari dept_name= ' Comp. Sci ‘ dan gaji >7000 5. Tampilkan ID,name dari instruktur 6. Tampilkan name dari instruktur untuk dept_name= ' Comp. Sci ‘
31
7. Find the set of all courses taught in the Fall 2009 semester, the Spring 2010 semester, or both 8. find all the courses taught in the Fall 2009 semester but not in Spring 2010 semester
32
9. the names of all instructors in the Physics department together with the course id of all courses they taught
33
10. Find the highest salary in the university
Presentasi serupa
© 2024 SlidePlayer.info Inc.
All rights reserved.