MIDOONY Logo

نرمال سازی داده (بخش چهارم - شکل دوم، سوم، چهارم و پنجم نرمال Other normal forms)

1400/02/28
نرمال سازی داده (بخش چهارم - شکل دوم، سوم، چهارم و پنجم نرمال Other normal forms)

#دومین_شکل_نرمال
تعریف آقای Date برای شکل نرمال دوم (2NF) این است: "یک رابطه R در شکل نرمال دوم است (2NF) اگر و فقط اگر در شکل 1NF باشد و هر ویژگی غیر کلیدی آن کاملاً به کلید اصلی وابسته باشد".
می توان با بیان شرط زیر، اصلاح جزئی در تعریف فوق انجام داد:
هر ویژگی غیر کلیدی باید به کلید و کلیه اجزا آن وابسته باشد.
اگر مقدار ویژگی فقط با دانستن بخشی از کلید اصلی تعیین گردد، 2NF نقض می گردد.
Attribute Description
Customer
**CustomerIdentifier The alpha-numeric string that uniquely identifies each customer
CustomerTelephoneNumber The customer’s telephone number
CustomerName The customer’s name
CustomerStreetAddress The street name associated with the customer’s account
CustomerCity The city in which the customer lives
CustomerState The state in which the customer lives
CustomerZipCode The customer’s zip code
CustomerCreditRating The credit rating for this customer
Order
**OrderNumber A unique identifier for each order
CustomerTelephoneNumber The customer’s telephone number
CustomerName The unique name for this customer
OrderDate The date when the order was placed
ShippingStreetAddress The street address for where the order is to be shipped
ShippingCity The city to which the order is to be shipped
ShippingState The state to which the order is to be shipped
ShippingZipCode The zip code associate with the shipping address
CustomerCreditCardNumber The credit card number used for this purchase
CustomerCreditCardName The customer’s name on the credit card used
ShippingDate The date the order was shipped
Advertised_Item
**ItemNumber The unique identifier for each Advertised_Item
ItemDescription A description of the item advertised
ItemDepartment A code classifying the item into one of the various product categories
of items for sale
ItemWeight The shipping weight for each item
ItemColor The color of the item
ItemPrice The selling price of the item sold
Supplier
**SupplierID A unique identifier for each supplier
SupplierName The unique name for this supplier
SupplierStreetAddress The street address for this supplier’s main office
SupplierCity The city in which the supplier’s main office is located
SupplierState The state in which the supplier’s main office is located
SupplierZipCode The zip code for the supplier’s main office
Item_Ordered
**ItemNumber The unique identifier for each item on an order
**OrderNumber A unique identifier for each order
ItemDescription The description of the item advertised
QuantityOrdered The number of items purchased
SellingPrice The price of the item purchased
ShippingDate The date the item purchased was shipped to the customer
Restock_Item
**ItemNumber The unique identifier for each item on an order
**SupplierID A unique identifier for each supplier
PurchasePrice The current cost of this item if purchased from this supplier
جدول زیر را برای کسورات حقوق و دستمزد در نظر بگیرید تا کسورات هر فیش حقوقی را ثبت نماید.
Payroll Deduction
**EmployeeID
**DateDeductionTaken
EmployeeName <== 2NF error; dependent only on EmployeeID
DeductionType
DeductionAmount
در اینجا، EmployeeName خطایی برای 2NF است زیرا نام فقط به EmployeeID وابسته است نه تاریخی که کسر انجام شده است.
تنظیمات لازم برای رفع نقض 2NF همان مراحل رفع خطای 1NF می باشد. اولا، اطمینان حاصل کنید که ویژگی عامل خطا به درستی در شکل 1NF است. سپس، رابطه بین موجودیت عامل خطا (در اینجا کسر حقوق و دستمزد) و موجودیتی که ویژگی به درستی به آن تخصیص یافته (در اینجا کارمند) را بررسی نمایید. اگر رابطه یک به چند بود،  هیچ کار دیگری لازم نیست اگر رابطه چند به چند بود اشتراکات موجودیت ها رابررسی و در صورت لزوم آنها را در موجودیت دیگری قرار دهید.
تقریباً تمام موارد نقض 2NF در موجودیت هایی وجود دارد که کلید اصلی آنها از به هم پیوستن چند ویژگی بوجود آمده است. واضح است که برای موجودیت هایی با یک کلید منفرد، ویژگی های غیر کلیدی باید به آن کلید متکی باشند. (به عنوان مثال، در موجودیت مشتری، انتظار داریم فقط ویژگی هایی را پیدا کنیم که اطلاعات مربوط به مشتری را ارائه می دهند.)
هنگام ایجاد لیست موجودیت و ویژگی، بلافاصله کلیدها شناسایی شدند و بررسی های لازم برای اطمینان از اینکه فقط ویژگی های وابسته به آن کلید اضافه شده اید، انجام شد بنابراین دراینجا لازم است فقط موجودیت هایی را بررسی نماییم که از ویژگی های به هم پیوسته برای کلید استفاده می کنند اگر آن بررسی اولیه انجام نشده بود، باید تمام ویژگی ها را در تمام موجودیت ها از نظر وابستگی به کلید اصلی بررسی می کردیم.

#سومین_شکل_نرمال
سرانجام، آقای Date تعریفی را برای 3NF ارائه می دهد که به شرح زیر است: "رابطه R به شکل سوم نرمال است
(3NF) اگر و فقط اگر در شکل 2NF باشد و هر ویژگی غیر کلیدی منفک نشدنی آن به کلید اصلی وابسته باشد
تعریف فوق را می توان با افزودن شرط زیر به NF2 بیان کرد:
هیچ ویژگی غیر کلیدی نباید به ویژگی غیر کلید دیگری وابسته باشد.
Attribute Description
Customer
**CustomerIdentifier The alpha-numeric string that uniquely identifies each customer
CustomerTelephoneNumber The customer’s telephone number
CustomerName The customer’s name
CustomerStreetAddress The street name associated with the customer’s account
CustomerCity The city in which the customer lives
CustomerState The state in which the customer lives
CustomerZipCode The customer’s zip code
CustomerCreditRating The credit rating for this customer
Order
**OrderNumber A unique identifier for each order
CustomerTelephoneNumber The customer’s telephone number
CustomerName The unique name for this customer
OrderDate The date when the order was placed
ShippingStreetAddress The street address for where the order is to be shipped
ShippingCity The city to which the order is to be shipped
ShippingState The state to which the order is to be shipped
ShippingZipCode The zip code associate with the shipping address
CustomerCreditCardNumber The credit card number used for this purchase
CustomerCreditCardName The customer’s name on the credit card used
ShippingDate The date the order was shipped
Advertised_Item
**ItemNumber The unique identifier for each Advertised_Item
ItemDescription A description of the item advertised
ItemDepartment A code classifying the item into one of the various product
categories of items for sale
ItemWeight The shipping weight for each item
ItemColor The color of the item
ItemPrice The selling price of the item sold
Supplier
**SupplierID A unique identifier for each supplier
SupplierName The unique name for this supplier
SupplierStreetAddress The street address for this supplier’s main office
SupplierCity The city in which the supplier’s main office is located
SupplierState The state in which the supplier’s main office is located
SupplierZipCode The zip code for the supplier’s main office
Item_Ordered
**ItemNumber The unique identifier for each item on an order
**OrderNumber A unique identifier for each order
QuantityOrdered The number of items purchased
SellingPrice The price of the item purchased
ShippingDate The date the item purchased was shipped to the customer
Restock_Item
**ItemNumber The unique identifier for each item on an order
**SupplierID A unique identifier for each supplier
PurchasePrice The current cost of this item if purchased from this supplier
اگر مقدار یک ویژگی غیر کلیدی بسادگی با دانستن مقدار ویژگی غیر کلیدی دیگر بدست آید، موجودیت فوق در شکل 3NF نیست.
به عنوان مثال، در موجودیت Order، ویژگی های غیر کلیدی زیر را در نظر بگیرید:
CustomerCreditCardNumber و CustomerCreditCardName. بین شماره کارت اعتباری و نام موجود روی آن کارت اعتباری وابستگی واضحی وجود دارد که نقض 3NF است و بنابراین ویژگی  CustomerCreditCardName باید حذف شود.
چگونه باید این کار را انجام داد؟ یک بار دیگر مراحل زیر را تکرار کنید
مطمئن شوید موجودیت در شکل NF1 است، سپس روابط یک به چند و چند به چند را بررسی کنید
در اینجا، باید موجودیت جدید کارت اعتباری برای ذخیره اطلاعات کارت های اعتباری مورد استفاده مشتری ایجاد شود. 
CustomerCreditCardNumber کلید این موجودیت است و CustomerCreditCardName یک ویژگی غیر کلیدی می باشد.
بنابراین می توان NF3 را اینطور تعریف کرد که هر ویژگی غیر کلیدی باید به کل کلید اصلی مرتبط باشد نه قسمتی از آن.
لیست موجودیت و ویژگی اکنون در شکل 3NF است و هر ویژگی غیر کلیدی در جای مناسب قرار دارد. ویژگی های غیر کلیدی فقط یک بار در موجودیت ها ظاهر می شوند. ویژگی های کلیدی می توانند در چندین موجودیت مرتبط به هم ظاهر شوند. این سلسله اقدامات باعث ایجاد روابط یک به چند بین موجودیت ها می گردد. این اقدامات برای پایگاه های داده رابطه ای لازم می باشند، که پیوند داده ها را فقط بر اساس محتوای داده ها فراهم می کنند. برای
مثال، موجودیت های مرتبط با Advertised_Item (Ordered_Item and Restock_Item) همه باید کلید موجودیتAdvertized_Item ، یعنی ItemNumber را در خود ذخیره کنند تا امکان دسترسی به اطلاعات توسط  ItemNumber را وجود داشته باشد.
به خاطر داشته باشید که ساختار نهایی داده ها هنوز ایجاد نشده است. مدل داده فقط یک نمایش منطقی از عناصر داده و چگونگی ارتباط آنها با هم می باشد. از این ساختار منطقی می توان برای ایجاد جداول استفاده کرد، اما تصمیمات نهایی در خصوص طراحی پایگاه داده بعدا، پس از در نظر گرفتن نحوه دسترسی به داده ها انجام می شود. 
اکنون به مرحله نهایی این قسمت از تجزیه و تحلیل می رسیم، با ترسیم تصویری از روابط داده ای که ایجاد شده اند.
Attribute Description
Customer
**CustomerIdentifier The alpha-numeric string that uniquely identifies each customer
CustomerTelephoneNumber The customer’s telephone number
CustomerName The customer’s name
CustomerStreetAddress The street name associated with the customer’s account
CustomerCity The city in which the customer lives
CustomerState The state in which the customer lives
CustomerZipCode The customer’s zip code
CustomerCreditRating The credit rating for this customer
Order
**OrderNumber A unique identifier for each order
CustomerIdentifer The unique name for this customer
OrderDate The date when the order was placed
ShippingStreetAddress The street address for where the order is to be shipped
ShippingCity The city to which the order is to be shipped
ShippingState The state to which the order is to be shipped
ShippingZipCode The zip code associate with the shipping address
CustomerCreditCardNumber The credit card number used for this purchase
ShippingDate The date the order was shipped
Ordered_Item
**OrderNumber A unique identifier for each order
**ItemNumber The unique identifier for each Advertised_Item
QuantityOrdered The number of items purchased
SellingPrice The price of the item purchased
ShippingDate The date the item purchased was shipped to the customer
Advertised_Item
**ItemNumber The unique identifier for each Advertised_Item
ItemDescription A description of the item advertised
ItemDepartment A code classifying the item into one of the various product
categories of items for sale
ItemWeight The shipping weight for each item
ItemColor The color of the item
ItemPrice The selling price of the item sold
Supplier
**SupplierID A unique identifier for each supplier
SupplierName The unique name for this supplier
SupplierStreetAddress The street address for this supplier’s main office
SupplierCity The city in which the supplier’s main office is located
SupplierState The state in which the supplier’s main office is located
SupplierZipCode The zip code for the supplier’s main office
Restock_Item
**ItemNumber The unique identifier for each item on an order
**SupplierID A unique identifier for each order
ReorderPrice The current cost of new items ordered from this supplier
Credit_Card
**CustomerCreditCardNumber The credit card number used for this purchase
CustomerCreditCardName The customer’s name on the credit card used

 

#چهارمین_شکل_نرمال
رونالد فاگین برای شکل چهارم نرمال تعریف زیر را ارائه می دهد. یک جدول در شکل چهارم نرمال (4NF) است اگر اولا 3NF باشد، ثانیا هیچ ستونی در جدول وابستگی چند مقداری نداشته باشد.
وابستگی چند مقداری (multivalued dependency) به این معنی است که حضور رکوردهای معینی در جدول، وجود رکوردهای معین دیگری را برساند.
 مثال. اگر مشتریانی با چند آدرس داشته باشیم، در جدول CUSTOMER نمی توانیم چند ستون آدرس را اضافه کنیم چون تعداد آدرس های ممکن را نمی دانیم. بنابراین ناگزیر به اضافه کردن رکورد جدید برای هر آدرس مشتری هستیم که باعث تکرار و افزونگی داده می شود. زیرا CustomerNo دیگر تنها یک آدرس را معین نمی کند بلکه مجموعه ای از آدرس های را نشان می دهد به عبارت دیگر وابستگی چند مقداری دارد. با حذف چنین وابستگی هائی و تقسیم جدول به صورت زیر به شکل چهارم نرمال می رسیم.
CUSTOMER (CustomerNo, First, Last, CreditLimit)
CUSTOMER_ADDRESS (CustomerNo, Address)
مثال دیگر جدول حاوی اطلاعات مربوط به رستوران ها، انواع پیتزا و ناحیه تحویل در نظر بگیرید. توجه داشته باشید که کلید اصلی این جدول ترکیب هر سه ستون است.
Pizza Delivery
**Restaurant
**Pizza_Variety <== 4NF error
**Delivery_Area <== 4NF error

اگر یک رستوران تمام انواع پیتزا را در تمام محل ها عرضه نماید یک خطا برای 4NF وجود دارد چون انواع پیتزا فقط به رستوران بستگی دارد و مستقل از محل تحویل است. بنابراین جدول فوق باید به دو جدول زیر شکسته شود :
Restaurant Variety
**Restaurant
**Pizza_Variety

Delivery Area
**Restaurant
**Delivery_Area

#پنجمین_شکل_نرمال
یک جدول در شکل 5NF است اگر و فقط اگر هر ویژگی منفک نشدنی آن به کلیدهای کاندید وابسته باشند. جدول زیر را در نظر بگیرید :
Saleman Product by Brand
**Traveling_Saleman
**Brand
**Product_Type
برای تبدیل به شکل نرمال پنجم باید این جدول بصورت جداول زیر پیاده سازی شود :
Product Type by Salesman
**Traveling_Saleman
**Product_Type

Brand by Salesman
**Traveling_Salesman
**Brand

Product Type by Brand
**Brand
**Product_Type

 

#Normalization

#Databse

#2NF

#3Nf

#4NF

#5NF

 

 

 

نرم افزار همسو

3 3437
دیدگاه کاربران
0 دیدگاه
شما هم دیدگاه خود را ارسال کنید