Search

Showing posts with label examples. Show all posts
Showing posts with label examples. Show all posts

Sunday, December 14, 2008

Relational Database Normalization Examples 7/7

ตัวอย่าง 5.1 ตารางที่ยังไม่ทำ normalization (จากเอกสารของผู้ใช้ที่ส่งให้นักวิเคราะห์)
เป็นตารางการสั่งซื้อ ให้ท่านลองนำไปทำ normalization
orderid
301
orderdate
15/12/46
productid
401
402
quan
2
5
302 16/12/46 402
405
406
4
4
1
ตัวอย่าง 5.2 ตารางที่ยังไม่ทำ normalization (จากเอกสารของผู้ใช้ที่ส่งให้นักวิเคราะห์)
เป็นตารางเงินเดือน ให้ท่านลองนำไปทำ normalization
saleid
101




salesalary
2000
saleposition
sale
custid
201
202
203
204
custname
tom
dang
boy
girl
ตัวอย่าง 5.3 ใบเสร็จ 2 ใบ เลขที่ A0001 และ A0002 (ให้ท่านลองนำไปทำ normalization)
ตัวอย่างนี้ได้รับการเสนอแนะจาก sudomvon@minebea.co.th
                              Invoice No.:      A0001
Date: 24/10/2004
Sold to: ABC company
Item Quantity UnitPrice Amount
Pen 50 3 150
Book 100 5 500
Ruler 20 2 40
Total 690


Invoice No.: A0002
Date: 24/10/2004
Sold to: XYZ company
Item Quantity UnitPrice Amount
Pen 100 3 300
Book 120 5 600
Ruler 50 2 100
Total 1000
การทำ Normalization ของตัวอย่าง 5.3 (ได้รับคำแนะนำจาก อ.อมรทิพย์ rung@yonok.ac.th)
    การเริ่มต้นทำ normalization ต้องนำข้อมูลมาสร้าง ตารางเริ่มต้น ซึ่งเป็นขั้นตอนก่อนการทำ 1NF
    โดยไม่เขียน amount และ total เพราะเป็นค่าที่เกิดจากการคำนวณเท่านั้น
    ตาราง temp
    A0001,24/10/2004,ABC company,Pen,50,3
    A0001,24/10/2004,ABC company,Book,100,5
    A0001,24/10/2004,ABC company,Ruler,20,2
    A0002,24/10/2004,XYZ company,Pen,100,3
    A0002,24/10/2004,XYZ company,Book,120,5
    A0002,24/10/2004,XYZ company,Ruler,50,2

    การทำ 1NF ของ ตัวอย่าง 5.3
    นำตารางเริ่มต้นมาจัดการเรื่อง multivalue เช่น คนชอบกินหลายอย่าง หรือการเพิ่ม key ประกอบข้อมูลที่อาจซ้ำ
    ตัวอย่างนี้เพิ่มรหัสลูกค้า และรหัสสินค้า เป็น key เพราะคิดว่า ชื่อลูกค้า และชื่อสินค้า อาจมีโอกาสซ้ำกันได้ และไม่เหมาะที่จะเป็น key
    ตาราง tempoforder
    A0001,24/10/2004,101,ABC company,201,Pen,50,3
    A0001,24/10/2004,101,ABC company,202,Book,100,5
    A0001,24/10/2004,101,ABC company,203,Ruler,20,2
    A0002,24/10/2004,102,XYZ company,201,Pen,100,3
    A0002,24/10/2004,102,XYZ company,202,Book,120,5
    A0002,24/10/2004,102,XYZ company,203,Ruler,50,2
    การทำ 2NF ของ ตัวอย่าง 5.3
    แยกตาราง tempoforder เป็นหลายตาราง และทุกตารางมี primary key ที่มีการตรวจสอบการขึ้นตรงอย่างถูกต้อง
    primay key คือ รหัสใบสั่งซื้อ
    ตาราง invoid_1
    A0001,24/10/2004,101,ABC company
    A0002,24/10/2004,102,XYZ company
    primay key คือ รหัสใบสั่งซื้อ และรหัสสินค้า
    ตาราง invoid_2
    A0001,201,50,3
    A0001,202,100,5
    A0001,203,20,2
    A0002,201,100,3
    A0002,202,120,5
    A0002,203,50,2
    ตาราง product เพราะราคาขึ้นกับรหัสสินค้า
    primary key คือ รหัสสินค้า

    ตาราง product
    201,Pen,3
    202,Book,5
    203,Ruler,2

    การทำ 3NF ของ ตัวอย่าง 5.3
    ตาราง invoid_1 เพราะชื่อลูกค้าไม่ขึ้นกับรหัสใบสั่งซื้อ จึงต้องแยกไปทำตาราง customer
    primay key คือ รหัสใบสั่งซื้อ

    ตาราง invoid_1
    A0001,24/10/2004,101
    A0002,24/10/2004,102
    ตาราง customer เพราะชื่อลูกค้าไม่ขึ้นกับ รหัสใบสั่งซื้อ แต่ขึ้นกับรหัสลูกค้า
    primay key คือ รหัสลูกค้า

    ตาราง customer
    101,ABC company
    102,XYZ company
    primay key คือ รหัสใบสั่งซื้อ และรหัสสินค้า เพราะ ปริมาณ และราคาต้องขึ้นกับ key 2 ตัวนี้
    ตาราง invoid_2
    A0001,201,50,3
    A0001,202,100,5
    A0001,203,20,2
    A0002,201,100,3
    A0002,202,120,5
    A0002,203,50,2
    ตาราง product เพราะราคาขึ้นกับรหัสสินค้า
    primary key คือ รหัสสินค้า

    ตาราง product
    201,Pen,3
    202,Book,5
    203,Ruler,2

Sunday, August 31, 2008

สร้าง Effect Menu ด้วย jquery





$(document).ready(function(){
$("#nav-one li").hover(
function(){ $("ul", this).fadeIn("fast"); },
function() { }
);
if (document.all) {
$("#nav-one li").hoverClass ("sfHover");
}
});

$.fn.hoverClass = function(c) {
return this.each(function(){
$(this).hover(
function() { $(this).addClass(c); },
function() { $(this).removeClass(c); }
);
});
};




A hover method for simulating hovering (moving the mouse on, and off, an object). This is a custom method which provides an 'in' to a frequent task.

Whenever the mouse cursor is moved over a matched element, the first specified function is fired. Whenever the mouse moves off of the element, the second specified function fires. Additionally, checks are in place to see if the mouse is still within the specified element itself (for example, an image inside of a div), and if it is, it will continue to 'hover', and not move out (a common error in using a mouseout event handler).