Web Hosting

Thursday, March 25, 2010

Pemrogaman SQL (Select) Multi Tabel

Pemrogaman SQL Select Multi Tabel


Pada artikel ini akan diberikan beberapa contoh perintah SQL yang diimplementasikan pada multi tabel. Adapun perintah SQL untuk manipulasi data pada satu tabel, saya yakin hal ini cukup mudah bagi Anda. Dalam contoh ini akan diambil studi kasus tentang pengambilan matakuliah mahasiswa.

Tabel-tabel yang dibuat pada studi kasus ini cukup sederhana saja untuk memudahkan pemahaman. Adapun tabel-tabel tersebut adalah:

 
mhs (
nim varchar(3),
namaMhs varchar(30),
primary key(nim)
)
mk (
kodeMK varchar(3),
namaMK varchar(30),
sks integer,
primary key(kodeMK)
)
ambilMK (
nim varchar(3),
kodeMK varchar(3),
nilai integer,
primary key(nim, kodeMK)
)

Dalam hal ini, field nim dan kodeMK pada tabel ambilMK merupakan foreign key. Apabila diperhatikan, tabel mhs dengan tabel ambilMK saling berelasi karena nim dalam tabel ambilMK berasal dari nim dalam tabel mhs (master tabel).

Demikian pula antara tabel mk dengan ambilMK. Kedua tabel ini juga berelasi karena kodeMK dalam tabel ambilMK berasal dari kodeMK dalam tabel mk.

Untuk record masing-masing tabel, misalkan diberikan berikut ini:


Tabel : mhs

nim    namaMhs
001 Joko
002 Amir
003 Budi


Tabel : mk

kodeMK    namaMK        sks
A01 Kalkulus 3
A02 Geometri 2
A03 Aljabar 3


Tabel : ambilMK

 
nim    kodeMK    nilai
001 A01 3
001 A02 4
001 A03 2
002 A02 3
002 A03 2
003 A01 4
003 A03 3


Selanjutnya misalkan akan dicari data-data sbb:

  1. Tampilkan nim dan nama mahasiswa yang mengambil Kalkulus (kodeMK = A01)
  2. Tampilkan nim, nama mahasiswa dan jumlah SKS matakuliah yang diambil untuk setiap mahasiswa
  3. Berapakah IPK mahasiswa bernama Budi (NIM: 003)
  4. Tampilkan nim, nama mahasiswa, dan IPK setiap mahasiswa

Untuk menjawab no. 1, kita harus cari dulu tabel mana yang terkait dengan query tersebut. Apabila kita akan mencari query tersebut berdasarkan nama matakuliah ‘Kalkulus’ maka tabel yang terkait adalah mhs (untuk menampilkan nim dan nama mahasiswa), mk (karena dalam tabel ini terdapat nama matakuliah), serta tabel ambilMK (karena tabel ini berisi data pengambilan matakuliah oleh mahasiswa).

Setelah menentukan tabel mana yang terkait dengan query, selanjutnya dapat dibuat statement SQL nya, yaitu

 
SELECT mhs.nim, mhs.namaMhs
FROM mhs, mk, ambilMK
WHERE mhs.nim = ambilMK.nim AND mk.kodeMK = ambilMK.kodeMK
AND mk.namaMK = 'Kalkulus';


Maksud mhs.nim, maksudnya adalah menampilkan data nim yang berasal dari tabel mhs. Dapat pula Anda menuliskan SQL nya seperti ini

 
SELECT ambilMK.nim, mhs.namaMhs
FROM mhs, mk, ambilMK
WHERE mhs.nim = ambilMK.nim AND mk.kodeMK = ambilMK.kodeMK
AND mk.namaMK = 'Kalkulus';


Hal ini dikarenakan untuk menampilkan nim dapat pula berasal dari tabel ambilMK.

Perhatikan bagian FROM dari kedua statement SQL di atas. Nama-nama tabel yang terkait dengan query dituliskan pada bagian FROM ini.

Selanjutnya apa maksud dari perintah mhs.nim = ambilMK.nim? Perintah ini digunakan untuk merelasikan tabel mhs dan ambilMK, dimana kedua tabel direlasikan melalui field nim di kedua tabel. Hal yang sama juga berlaku untuk perintah mk.kodeMK = ambilMK.kodeMK.

Sedangkan perintah mk.namaMK = ‘Kalkulus’ digunakan sebagai syarat pencarian data (menampilkan data mahasiswa yang mengambil matakuliah Kalkulus).

Apabila pencarian data mahasiswa yang mengambil Kalkulus ini berdasarkan kode matakuliah (A01), maka Anda tidak perlu menggunakan tabel mk, tapi cukup tabel mhs dan ambilMK saja. Hal ini dikarenakan kodeMK dapat diketahui dari tabel ambilMK. Sehingga perintah SQL nya

 
SELECT mhs.nim, mhs.namaMhs
FROM mhs, ambilMK
WHERE mhs.nim = ambilMK.nim AND ambilMK.kodeMK = 'A01';

Ketiga statement SQL di atas akan menghasilkan hasil yang sama yaitu

 
NIM    namaMhs
001 Joko
003 Budi


Selanjutnya akan dijawab pertanyaan no. 2. Seperti halnya langkah penyelesaian pertanyaan no. 1, langkah pertama harus kita tentukan dulu tabel apa saja yang terkait dengan query. Dalam hal ini kita akan menggunakan tabel mhs, mk dan ambilMK. Tabel mhs untuk menampilkan nim dan nama mahasiswa. Tabel mk digunakan karena di dalamnya terdapat data SKS. Sedangkan tabel ambilMK digunakan karena berisi data yang menunjukkan pengambilan matakuliah mahasiswa.

Perintah SQL untuk pertanyaan no. 2 adalah

 
SELECT mhs.nim, mhs.namaMhs, sum(mk.sks) as jumlahSKS
FROM mhs, mk, ambilMK
WHERE mhs.nim = ambilMK.nim AND mk.kodeMK = ambilMK.kodeMK
GROUP BY ambilMK.nim

atau

SELECT mhs.nim, mhs.namaMhs, sum(mk.sks) as jumlahSKS
FROM mhs, mk, ambilMK
WHERE mhs.nim = ambilMK.nim AND mk.kodeMK = ambilMK.kodeMK
GROUP BY mhs.nim


Untuk mencari jumlah SKS setiap mahasiswa, kita menggunakan perintah sum(mk.sks). Supaya perintah ini bisa jalan, maka harus ditambahkan perintah GROUP BY mhs.nim atau GROUP BY ambilMK.nim. Hal ini dikarenakan proses penjumlahan sks harus dilakukan pada setiap kelompok data. Maksudnya apa ya?
Perhatikan perintah SQL berikut ini

 
SELECT mhs.nim, mhs.namaMhs, mk.sks
FROM mhs, mk, ambilMK
WHERE mhs.nim = ambilMK.nim AND mk.kodeMK = ambilMK.kodeMK


Perintah di atas akan menampilkan nim, nama mahasiswa serta sks setiap mata kuliah yang diambil. Hasilnya adalah

 
NIM    namaMhs        SKS
001 Joko 3
001 Joko 2
001 Joko 3
002 Amir 2
002 Amir 3
003 Budi 3
003 Budi 3


Untuk pertanyaan no. 2 ini, seharusnya akan tampil hasil berikut

 
NIM    namaMhs        jumlahSKS
001 Joko 8
002 Amir 5
003 Budi 6


Sehingga supaya mendapatkan hasil seperti di atas, kita akan menjumlahkan setiap SKS yang diambil mahasiswa, berdasarkan kelompok mahasiswa, dalam hal ini dikelompokkan berdasarkan NIM. Mengapa tidak dikelompokkan berdasarkan nama mahasiswa? Wah bisa gawat kalau ini terjadi, karena ada kemungkinan nama mahasiswa yang sama. Oleh karena itu harus ada perintah GROUP BY mhs.nim

Untuk pembahasan nomor yang lain akan dilanjutkan pada tutorial yang lain.


Daftar Shortcut Keyboard

Daftar shortcut Keyboard

Pernah merasa lelah pindah tangan dari mouse ke keyboard ato keyboard ke mouse? khususnya bagi anda yang sering mengetik, akan terasa segan memindahkan tangan anda yang tengah menari2 di keyboard untuk memegang tikus. untuk mengatasinya gunakan saja shortcut di bawah ini, kalo bisa hapalkan biar anda ga megang tikus lagi.

Windows key + R = Run menu
This is usually followed by:
cmd = Command Prompt
iexplore + “web address” = Internet Explorer
compmgmt.msc = Computer Management
dhcpmgmt.msc = DHCP Management
dnsmgmt.msc = DNS Management
services.msc = Services
eventvwr = Event Viewer
dsa.msc = Active Directory Users and Computers
dssite.msc = Active Directory Sites and Services
Windows key + E = Explorer

ALT + Tab = Switch between windows
ALT, Space, X = Maximize window
CTRL + Shift + Esc = Task Manager
Windows key + Break = System properties
Windows key + F = Search
Windows key + D = Hide/Display all windows
CTRL + C = copy
CTRL + X = cut
CTRL + V = paste
Also don’t forget about the “Right-click” key next to the right Windows key on your keyboard. Using the arrows and that key can get just about anything done once you’ve opened up any program.
Keyboard Shortcuts
[Alt] and [Esc] Switch between running applications
[Alt] and letter Select menu item by underlined letter
[Ctrl] and [Esc] Open Program Menu
[Ctrl] and [F4] Close active document or group windows (does not work with some applications)
[Alt] and [F4] Quit active application or close current window
[Alt] and [-] Open Control menu for active document
Ctrl] Lft., Rt. arrow Move cursor forward or back one word
Ctrl] Up, Down arrow Move cursor forward or back one paragraph
[F1] Open Help for active application
Windows+M Minimize all open windows
Shift+Windows+M Undo minimize all open windows
Windows+F1 Open Windows Help
Windows+Tab Cycle through the Taskbar buttons
Windows+Break Open the System Properties dialog box
acessability shortcuts
Right SHIFT for eight seconds…….. Switch FilterKeys on and off.
Left ALT +left SHIFT +PRINT SCREEN……. Switch High Contrast on and off.
Left ALT +left SHIFT +NUM LOCK……. Switch MouseKeys on and off.
SHIFT……. five times Switch StickyKeys on and off.
NUM LOCK…… for five seconds Switch ToggleKeys on and off.
explorer shortcuts
END……. Display the bottom of the active window.
HOME……. Display the top of the active window.
NUM LOCK+ASTERISK……. on numeric keypad (*) Display all subfolders under the selected folder.
NUM LOCK+PLUS SIGN……. on numeric keypad (+) Display the contents of the selected folder.
NUM LOCK+MINUS SIGN……. on numeric keypad (-) Collapse the selected folder.
LEFT ARROW…… Collapse current selection if it’s expanded, or select parent folder.
RIGHT ARROW……. Display current selection if it’s collapsed, or select first subfolder.
Type the following commands in your Run Box (Windows Key + R) or Start Run
devmgmt.msc = Device Manager
msinfo32 = System Information
cleanmgr = Disk Cleanup
ntbackup = Backup or Restore Wizard (Windows Backup Utility)
mmc = Microsoft Management Console
excel = Microsoft Excel (If Installed)
msaccess = Microsoft Access (If Installed)
powerpnt = Microsoft PowerPoint (If Installed)
winword = Microsoft Word (If Installed)
frontpg = Microsoft FrontPage (If Installed)
notepad = Notepad
wordpad = WordPad
calc = Calculator
msmsgs = Windows Messenger
mspaint = Microsoft Paint
wmplayer = Windows Media Player
rstrui = System Restore
netscp6 = Netscape 6.x
netscp = Netscape 7.x
netscape = Netscape 4.x
waol = America Online
control = Opens the Control Panel
control printers = Opens the Printers Dialog

internetbrowser
type in u’re adress “google”, then press [Right CTRL] and [Enter]
add www. and .com to word and go to it

For Windows XP:
Copy. CTRL+C
Cut. CTRL+X
Paste. CTRL+V
Undo. CTRL+Z
Delete. DELETE
Delete selected item permanently without placing the item in the Recycle Bin. SHIFT+DELETE
Copy selected item. CTRL while dragging an item
Create shortcut to selected item. CTRL+SHIFT while dragging an item
Rename selected item. F2
Move the insertion point to the beginning of the next word. CTRL+RIGHT ARROW
Move the insertion point to the beginning of the previous word. CTRL+LEFT ARROW
Move the insertion point to the beginning of the next paragraph. CTRL+DOWN ARROW
Move the insertion point to the beginning of the previous paragraph. CTRL+UP ARROW
Highlight a block of text. CTRL+SHIFT with any of the arrow keys
Select more than one item in a window or on the desktop, or select text within a document. SHIFT with any of the arrow keys
Select all. CTRL+A
Search for a file or folder. F3
View properties for the selected item. ALT+ENTER
Close the active item, or quit the active program. ALT+F4
Opens the shortcut menu for the active window. ALT+SPACEBAR
Close the active document in programs that allow you to have multiple documents open simultaneously. CTRL+F4
Switch between open items. ALT+TAB
Cycle through items in the order they were opened. ALT+ESC
Cycle through screen elements in a window or on the desktop. F6
Display the Address bar list in My Computer or Windows Explorer. F4
Display the shortcut menu for the selected item. SHIFT+F10
Display the System menu for the active window. ALT+SPACEBAR
Display the Start menu. CTRL+ESC
Display the corresponding menu. ALT+Underlined letter in a menu name
Carry out the corresponding command. Underlined letter in a command name on an open menu
Activate the menu bar in the active program. F10
Open the next menu to the right, or open a submenu. RIGHT ARROW
Open the next menu to the left, or close a submenu. LEFT ARROW
Refresh the active window. F5
View the folder one level up in My Computer or Windows Explorer. BACKSPACE
Cancel the current task. ESC
SHIFT when you insert a CD into the CD-ROM drive Prevent the CD from automatically playing.

Use these keyboard shortcuts for dialog boxes:
To Press
Move forward through tabs. CTRL+TAB
Move backward through tabs. CTRL+SHIFT+TAB
Move forward through options. TAB
Move backward through options. SHIFT+TAB
Carry out the corresponding command or select the corresponding option. ALT+Underlined letter
Carry out the command for the active option or button. ENTER
Select or clear the check box if the active option is a check box. SPACEBAR
Select a button if the active option is a group of option buttons. Arrow keys
Display Help. F1
Display the items in the active list. F4
Open a folder one level up if a folder is selected in the Save As or Open dialog box. BACKSPACE

If you have a Microsoft Natural Keyboard, or any other compatible keyboard that includes the Windows logo key and the Application key , you can use these keyboard shortcuts:
Display or hide the Start menu. WIN Key
Display the System Properties dialog box. WIN Key+BREAK
Show the desktop. WIN Key+D
Minimize all windows. WIN Key+M
Restores minimized windows. WIN Key+Shift+M
Open My Computer. WIN Key+E
Search for a file or folder. WIN Key+F
Search for computers. CTRL+WIN Key+F
Display Windows Help. WIN Key+F1
Lock your computer if you are connected to a network domain, or switch users if you are not connected to a network domain. WIN Key+ L
Open the Run dialog box. WIN Key+R
Open Utility Manager. WIN Key+U

accessibility keyboard shortcuts:
Switch FilterKeys on and off. Right SHIFT for eight seconds
Switch High Contrast on and off. Left ALT+left SHIFT+PRINT SCREEN
Switch MouseKeys on and off. Left ALT +left SHIFT +NUM LOCK
Switch StickyKeys on and off. SHIFT five times
Switch ToggleKeys on and off. NUM LOCK for five seconds
Open Utility Manager. WIN Key+U

shortcuts you can use with Windows Explorer:
Display the bottom of the active window. END
Display the top of the active window. HOME
Display all subfolders under the selected folder. NUM LOCK+ASTERISK on numeric keypad (*)
Display the contents of the selected folder. NUM LOCK+PLUS SIGN on numeric keypad (+)
Collapse the selected folder. NUM LOCK+MINUS SIGN on numeric keypad (-)
Collapse current selection if it’s expanded, or select parent folder. LEFT ARROW
Display current selection if it’s collapsed, or select first subfolder. RIGHT ARROW



Habis Core i7 terus i5 dan i3...

INTEL MERILIS SECARA RESMI CORE i7, CORE i5 DAN CORE i3

Setelah merilis processor Core i7, Intel kembali merilis dua varian lainnyayaitu Core i5 dan Core i3. Beberapa tambahan penting lainnya adalah :

  • Brand Core 2 Duo dan Core2 Quad akan dihilangkan.
  • Brand Pentium, Celeron dan Atom akan tetap dipertahankan.
  • Brand Centrino akan dihilangkan juga.Kemungkinan produk berbasis Intel WiFi dan WIMAX yang akan menggunakan namaCentrino, jadi bukan Notebook lagi

Pada dasarnya Core i5 dan Core i3 merupakan versi “value” (alias memilikiperforma lebih rendah) dari Core i7. Positionignya adalah sebagai berikut; Corei3 sebagai produk Entry Level, Core i5 sebagai produk Mid Level dan Corei7 sebagai produk High Level. Seluruh processor ini akan tersedia pada PCDesktop & Mobile.

Perbedaan antara Core i7 dan keduanya adalah pada jumlah socket LGA.Core i7 menggunakan socket LGA-1366 sedangkan Core i5 dan i3 menggunakan socketLGA-1156. Selain itu Core i7 dan Core i5 memiliki fitur “Intel Turbo ModeTechnology”. Fitur ini akan mengatur hidup/mati (on/off) core yang tidak digunakanpada saat aplikasi menjalankan single-thread. Seperti diketahui bahwa tidaksemua aplikasi memanfaatkan jumlah core yang tersedia; padahal jika melakukanproses -semua core itu harus aktif. Dengan Turbo Mode, Processor hanya akanmengaktifkan core yang akan digunakan saja, lalu meng-overclock aliran threaddata yang lewat diatasnya agar berjalan lebih cepat. Turbo Mode hanya tersediadi Core i7 dan i5 saja.

Core i7 sendiri merupakan processor pertama dengan teknologi “Nehalem”.Nehalem menggunakan platform baru yang betul-betul berbeda dengan generasisebelumnya. Salah satunya adalah mengintegrasikan chipset MCH langsung diprocessor, bukan motherboard. Nehalem juga mengganti fungsi FSB menjadi QPI(Quick Path Interconnect) yang lebih revolusioner.

Mengenai Core i5

Jika Bloomfield adalah codename untuk Core i7 makaLynnfield adalah codename untuk Core i5. Core i5 adalah seri value dari Core i7yang akan berjalan di socket baru Intel yaitu socket LGA-1156. Tertarik begitumendengar kata value? Tepat! Core i5 akan dipasarkan dengan harga sekitarUS$186.

Kelebihan Core i5 ini adalah ditanamkannya fungsichipset Northbridge pada inti processor (dikenal dengan nama MCH padaMotherboard). Maka motherboard Core i5 yang akan menggunakan chipset Intel P55(dikelas mainstream) ini akan terlihat lowong tanpa kehadiran chipsetnorthbridge. Jika Core i7 menggunakan Triple Channel DDR 3, maka di Core i5hanya menggunakan Dual Channel DDR 3. Penggunaan dayanya juga diturunkanmenjadi 95 Watt. Chipset P55 ini mendukung Triple Graphic Cards (3x) dengan1×16 PCI-E slot dan 2×8 PCI-E slot. Pada Core i5 cache tetap sama, yaitu 8 MBL3 cache.

Intel juga meluncurkan Clarksfield, yaitu Core i5versi mobile yang ditujukan untuk notebook. Socket yang akan digunakan adalahmPGA-989 dan membutuhkan daya yang terbilang cukup kecil yaitu sebesar 45-55Watt.

Mengenai Core i3

Intel Core i3 merupakan varian paling valuedibandingkan dua saudaranya yang lain. Processor ini akan mengintegrasikan GPU(Graphics Processing Unit) alias Graphics On-board didalam processornya.Kemampuan grafisnya diklaim sama dengan Intel GMA pada chipset G45. Selain ituCore i3 nantinya menggunakan manufaktur hybrid, inti processor dengan 32nm,sedangkan memory controller/graphics menggunakan 45nm. Code produk Core i3adalah “Arrandale”.


Sumber: Nurseto (Nurseto@terra.co.id)


Struktur kontrol VB 0.6

  • Struktur Kontrol pada VB 6.0


Didalam pemrogaman VB 6.0 terdapat beberapa struktur kontrol diantaranya:

  • Struktur Kontrol For ...Next

Bentuk penulisan sintak (For...next) adalah FOR (pencacah) = (awal) TO (akhir) [step (langkah)] (blok kode program) NEXT (pencacah)
Keterangan:

1).Pencacah adalah variabel (tipe:integer) yang digunakan untuk menyimpan angka pengulangan.

2).Awal adalah nilai awal dari pencacah.

3).Akhir adalah nilai akhir dari pencacah.

4).Langkah adalah perubahan nilai pencacah setiap pengulangan.

Sifatnya optional boleh ditulis ataupun tidak.Bila ditulis maka nilainya (langkah ) adalah 1.

  • Struktur Kontrol Do....loop

1. DO WHILE (kondisi)
(blok kode program
LOOP
(blok kode program) akan diulang selama (kondisi) bernilai TRUE. Pengulangan berhenti bila (kondisi) sudah bernilai FALSE.

2. DO UNTIL (kondisi)
(blok kode program)
LOOP
(blok kode program) akan diulang sampai (kondisi) bernilai TRUE. Pengulangan berhenti bila (kondisi) sudah bernilai TRUE.