Company Relational Database for Exercise

Company Relational Database for Exercise

employee (person_name, street, city)

works (person_name, company_name, salary)

company (company_name, city)

manages (person_name, manager_name)

  1. Consider the Company Relational Database, where the primary keys are underlined. Give an expression in the relational algebra to express each the following queries:
  • Find the names of all employees who live in the same city and on the same street as do their manager
  • Find the names of all employees in this database who do not work for “First Bank Corporation”
  • Find the names of all employees who earn more than every employee of “Small Bank Corporation”

 

  1. Consider the Company Relational Database, where the primary keys are underlined. Give an expression in the relational algebra to express each the following queries:
  • Find all employees who work directly for “Jones.”
  • Find all cities of residence of all employees who work directly for “Jones.”
  • Find the name of the manager of the manager of “Jones.”
  • Find the employees who earn more than all employees living in the city “Mumbai.”

3.

  • Find the names of all employees who work for “Small Bank Corporation”.
  • Find the names and cities of residence of all employees who work for “Small Bank Corporation”.
  • Find the names, street addresses, and cities of residence of all employees who work for “Small Bank Corporation” and earn more than $5,000.
  • Find the names of all employees in this database who live in the same city as the company for which they work.
  • Assume the companies maybe located several cities. Find all companies located in every city in which “First Bank Corporation” is located

 

  1. Choose 2 relational algebra (RA) expressions (from the answer of previous exercise). For each RA, create a Query Evaluation Plan (QEP) by selecting the appropriate algorithm.

 

  1. Let relations r1(A,B,C) and r2(C,D,E) have the following properties :
    r1 has 20,000 tuples, r2 has 45,000 tuples, 25 tuples of r1 fit on one block, and 30 tuples of r2 fit on one block.

Estimate the number of block transfers and seeks require, using each of the following join strategies for r1|x|r2:

  • Nested-loop join.
  • Block nested-loop join.

 

Jawab

1.

A) Π person_name ((employee ⋈ manages) ⋈ (manager_name = employee2.person_name ^ employee.street = employee2.street ^ employee.city = employee2.city)(ρ employeew(employee)))

B) Π person_name (σ company_name ≠ “First Bank Corporation” (works))

C) Π person_name (works) – (Π works.person_name (works ⋈ (works.salary ≤ works2.salary ^ works2.company_name = “Small Bank Corporation”) ρ works2 (works)))

2.

A) Π person_name, street, city (σ employee.person_name = manager.person_name ^manager_name = ‘Jones'(employee x manages))

B) Π  city (σ employee.person_name = manager.person_name ^ manager_name = ‘Jones'(employee x manages))

C) Π manager.person_name ∩ Πmanager.person_name = ‘Jones’ (manages))

D) Π person_name (σ salary > employee.person_name ^ Mumbai (employee x salary x company ))

3.

A) Π person_name (σ company_name = ‘Small Bank Corporation’ (works |x| employee))

B) Π person_name, city (σ company_name = ‘Small Bank Corporation’ (works |x| employee))

C) Π person_name, street, city (σ company_name = ‘Small Bank Corporation’ ^ salary > 5000 (works  |x| employee))

 

Query Processing

Selection

Selection merupakan pemilihan data dari sekumpulan data operasional. Selection perlu dilakukan sebelum tahap penggalian informasi. Data hasil seleksi yang akan digunakan untuk proses data mining, disimpan dalam suatu berkas, terpisah dari basis data operasional

 

 

Sorting

Pada system database, sorting mempunyai dua kegunaan yaitu:

  • Query dapat dengan spesifik menentukan outut yang harus diurutkan
  • Operasi dalam hubungan antar query dapat dapat lebih efisien diimplementasikan dalam hubungan antar sorting.

Join

Dalam database, kita biasanya memelukan data dari 2 tabel yang saling berhubungan. Kita bias melakukan berbagai macam join untuk menemukan data dari 2 tabel yang berhubungan tersebut. Macam maca join tersebut adalah:

  1. Inner Join

Inner join merupakan jenis join yang paling umum yang dapat digunakan pada semua database. Jenis ini dapat digunakan bila ingin merelasikan dua set data yang ada di tabel, letak relasinya setelah pada perintah ON pada join.

Bentuk baku perintah inner join :
SELECT <field1>,<field2>,<fieldn> FROM <tabel1> INNER JOIN <tabel2>
ON <key.tabel1> = <key.tabel2>

  1. Outer Join

Outer join merupakan jenis join yang sedikit berbeda dengan inner join. Pada MySQL, bentuk perintah untuk menerapkan outer join ada 2 yaitu :
SELECT <field1>,<field2>,<fieldn> FROM <tabel1> LEFT JOIN <tabel2> ON
<key.tabel1> = <key.tabel2>
dan
SELECT <field1>,<field2>,<fieldn> FROM <tabel1> RIGHT JOIN <tabel2>
ON <key.tabel1> = <key.tabel2>

  1. Cross Join

Cross join kadang kala disebut juga sebagai Cartesian Product. Bila menggunakan cross join, maka hasil dari cross join akan menciptakan hasil yang didasarkan pada semua kemungkinan kombinasi baris dalam kedua set data. Bentuk perintah dari cross join adalah :

SELECT <field1>,<field2>,<fieldn> FROM <tabel1> CROSS JOIN <tabel2> atau SELECT <field1>,<field2>,<fieldn> FROM <tabel1>, <tabel2>

  1. Union Join

Pemakaian union dapat menyederhanakan perintah persyaratan OR yang bertingkat. Bila dalam sebuah query menghasilkan pemakaian perintah OR yang lebih dari satu sehingga dapat membuat bingung, sebagai gantinya digunakan perintah UNION. Union dapat dikatakan sebagai perintah untuk menggabungkan hasil query sql yang fungsinya sama dengan perintah OR

 

Daftar Pustaka

http://memahamibdl.blogspot.co.id/2014/07/macam-macam-join-dan-penjelasannya.html

http://sigitprabowoo.blogspot.co.id/2013/04/data-mining-tahap-tahapan-knowladge.html