رسول_57
دوشنبه 06 آذر 1391, 08:12 صبح
Normalization
Jump to: navigation (http://www.orafaq.com/wiki/Normalization#column-one), search (http://www.orafaq.com/wiki/Normalization#searchInput)
Normalization is a series of steps followed to obtain a database design that allows for efficient access and storage of data. These steps reduce data redundancy and the chances of data becoming inconsistent.
First Normal Form
First Normal Form eliminates repeating groups by putting each into a separate table and connecting them with a one-to-many relationship.
Two rules follow this definition:
Each table has a primary key (http://www.orafaq.com/wiki/Primary_key) made of one or several fields and uniquely identifying each record
Each field is atomic, it does not contain more than one value
For instance, assuming a table WAGON to follow each wagon in every station.
wagon_id integer (ex. 101) description string (ex. 'wagon_type, empty_weight, capacity, designer, design_date') state string (ex. 'under repair') timestamp datetime (ex. '22/12/2008 17:37') station string (ex. 'New York Grand Central')
The primary key (http://www.orafaq.com/wiki/Primary_key) is (wagon_id, timestamp).
This table is not in 1NF because "description" is not atomic. To move it in 1NF we have to split "description" field in its components:
wagon_id integer wagon_type string empty_weight number capacity number designer string design_date datetime state string timestamp datetime station string
Second Normal Form
Second Normal Form eliminates functional dependencies (http://www.orafaq.com/wiki/Functional_dependency) on a partial key by putting the fields in a separate table from those that are dependent on the whole key.
In our example, "wagon_type", "empty_weight", "capacity"... only depends on "wagon_id" but not on "timestamp" field of the primary key (http://www.orafaq.com/wiki/Primary_key), so this table is not in 2NF. In order to reach 2NF, we have to split the table in two in the way that each field of each table depends on all the fields of each primary key (http://www.orafaq.com/wiki/Primary_key):
wagon_id integer wagon_type string empty_weight number capacity number designer string design_date datetime wagon_id integer timestamp datetime state string station string
Third Normal Form
Third Normal Form eliminates functional dependencies (http://www.orafaq.com/wiki/Functional_dependency) on non-key fields by putting them in a separate table. At this stage, all non-key fields are dependent on the key, the whole key and nothing but the key.
In our example, in the first table it is most likely that "empty_weight", "capacity", "designer" and "design_date" depend on "wagon_type", so we have to split this table in two:
wagon_id integer wagon_type string wagon_type string empty_weight number capacity number designer string design_date datetime
Now our example with its 3 tables is in 3NF.
Fourth Normal Form
Fourth Normal Form separates independent multi-valued facts stored in one table into separate tables.
In the last table of our example, it is clear that "empty_weight" and "capacity" are interesting for every day wagon management whereas "designer" and "design_date" for historical purpose. So we can think they will never be used at the same time and have to split the table in two to fit the 4NF.
wagon_type string empty_weight number capacity number wagon_type string designer string design_date datetime
Fifth Normal Form
Fifth Normal Form breaks out data redundancy that is not covered by any of the previous normal forms.
نرمال سازی مجموعه ای از مراحل طراحی پایگاه داده است که دسترسی به داده ها و ذخیره سازی آنها را کاراتر می سازد . در نتیجه افزونگی داده ها کاهش یافته و پایگاه داده دارای تناسب بهتری می گردد .
فرم نرمال اول :
در فرم نرمال اول ، گروههای تکراری حذف می گردد . آنها در یک جدول مجزا قرار می گیرند و با استفاده از یک رابطه یک به چند با آنها ارتباط برقرار می گردد .
*هر جدول دارای یک کلید اصلی است که می تواند از یک فیلد یا ترکیبی از چند فیلد ایجاد شده و به صورت یکتا نشاندهنده یک رکورد باشد .
*هر فیلد به صورت اتمیک است ، یعنی شامل بیش از یک مقدار نیست .
به عنوان مثال جدول WAGON را در نظر بگیرید . مشخصات جدول WAGON در هر ایستگاه به شرح زیر است :
wagon_id integer (ex. 101)
description string (ex. 'wagon_type, empty_weight, capacity, designer, design_date')
state string (ex. 'under repair')
timestamp datetime (ex. '22/12/2008 17:37')
station string (ex. 'New York Grand Central')
کلید اصلی (wagon_id, timestamp) است . این جدول در فرم نرمال اول نیست زیرا description اتمیک نیست . برای این که این جدول به فرم نرمال اول تبدیل گردد باید فیلد description به اجزای آن تجزیه گردد .
wagon_id integer
wagon_type string
empty_weight number
capacity number
designer string
design_date datetime
state string
timestamp datetime
station string
فرم نرمال دوم :
فرم نرمال دوم ، رابطه تابعی کلید جزئی را ( رابطه تابعی به این معنا است که فیلدی که جزئی از کلید اصلی است با فیلدهای دیگر جدول رابطه یک به چند دارد) حذف می کند به گونه ایکه کلید جزئی با فیلدهای وابسته تشکیل یک جدول جدا می دهند که این کلید جزئی در آن جدول به کلید اصلی تبدیل می گردد . در مثال ما "wagon_type", "empty_weight", "capacity" تنها به "wagon_id" وابستگی تابعی دارند و با فیلد "timestamp" ارتباطی ندارند . بنابراین جدول در فرم نرمال دوم نیست . بنابراین برای اینکه طراحی ما در فرم نرمال دوم باشد باید جدوال را به گونه ای بشکنیم که فیلدهای هر جدول تنها با تمام فیلدهای کلید اصلی آن رابطه داشته باشند به صورت زیر :
wagon_id integer
wagon_type string
empty_weight number
capacity number
designer string
design_date datetime
------------------------------------------------------
wagon_id integer
timestamp datetime
state string
station string
فرم نرمال سوم :
در فرم نرمال سوم ، وابستگی های تابعی فیلدهای غیرکلید با قرار دادن آن در جدولی مجزا حذف می گردد . در این حالت تمامی فیلدهای غیر کلید صرفا با کلید اصلی رابطه دارند ولاغیر . در مثال ما "empty_weight", "capacity", "designer" و "design_date" با "wagon_type" رابطه داشتند . بنابراین باید آن جدول را به دو جدول به صورت زیر بشکنیم :
wagon_id integer
wagon_type string
-------------------------------------
wagon_type string
empty_weight number
capacity number
designer string
design_date datetime
فرم نرمال چهارم :
در فرم نرمال چهارم ، اطلاعات چندمقداری غیروابسته به یکدیگر در یک جدول از یکدیگر جدا می گردند . در آخرین جدول مثال ما ، "empty_weight" و "capacity" برای مدیریت واگن ها به صورت روزمره مورد نیاز است در حالیکه "designer" و "design_date" صرفا جهت اطلاع است و بنابراین این داده ها در یک زمان مورد استفاده قرار نمی گیرند و باید به جداولی در فرم نرمال چهارم تجزیه گردند ، به صورت زیر :
wagon_type string
empty_weight number
capacity number
-----------------------------------
wagon_type string
designer string
design_date datetime
فرم نرمال پنجم :
در فرم نرمال پنجم افزونگی داده هایی که در مراحل قبل پوشش داده نشده است از بین می رود .
Jump to: navigation (http://www.orafaq.com/wiki/Normalization#column-one), search (http://www.orafaq.com/wiki/Normalization#searchInput)
Normalization is a series of steps followed to obtain a database design that allows for efficient access and storage of data. These steps reduce data redundancy and the chances of data becoming inconsistent.
First Normal Form
First Normal Form eliminates repeating groups by putting each into a separate table and connecting them with a one-to-many relationship.
Two rules follow this definition:
Each table has a primary key (http://www.orafaq.com/wiki/Primary_key) made of one or several fields and uniquely identifying each record
Each field is atomic, it does not contain more than one value
For instance, assuming a table WAGON to follow each wagon in every station.
wagon_id integer (ex. 101) description string (ex. 'wagon_type, empty_weight, capacity, designer, design_date') state string (ex. 'under repair') timestamp datetime (ex. '22/12/2008 17:37') station string (ex. 'New York Grand Central')
The primary key (http://www.orafaq.com/wiki/Primary_key) is (wagon_id, timestamp).
This table is not in 1NF because "description" is not atomic. To move it in 1NF we have to split "description" field in its components:
wagon_id integer wagon_type string empty_weight number capacity number designer string design_date datetime state string timestamp datetime station string
Second Normal Form
Second Normal Form eliminates functional dependencies (http://www.orafaq.com/wiki/Functional_dependency) on a partial key by putting the fields in a separate table from those that are dependent on the whole key.
In our example, "wagon_type", "empty_weight", "capacity"... only depends on "wagon_id" but not on "timestamp" field of the primary key (http://www.orafaq.com/wiki/Primary_key), so this table is not in 2NF. In order to reach 2NF, we have to split the table in two in the way that each field of each table depends on all the fields of each primary key (http://www.orafaq.com/wiki/Primary_key):
wagon_id integer wagon_type string empty_weight number capacity number designer string design_date datetime wagon_id integer timestamp datetime state string station string
Third Normal Form
Third Normal Form eliminates functional dependencies (http://www.orafaq.com/wiki/Functional_dependency) on non-key fields by putting them in a separate table. At this stage, all non-key fields are dependent on the key, the whole key and nothing but the key.
In our example, in the first table it is most likely that "empty_weight", "capacity", "designer" and "design_date" depend on "wagon_type", so we have to split this table in two:
wagon_id integer wagon_type string wagon_type string empty_weight number capacity number designer string design_date datetime
Now our example with its 3 tables is in 3NF.
Fourth Normal Form
Fourth Normal Form separates independent multi-valued facts stored in one table into separate tables.
In the last table of our example, it is clear that "empty_weight" and "capacity" are interesting for every day wagon management whereas "designer" and "design_date" for historical purpose. So we can think they will never be used at the same time and have to split the table in two to fit the 4NF.
wagon_type string empty_weight number capacity number wagon_type string designer string design_date datetime
Fifth Normal Form
Fifth Normal Form breaks out data redundancy that is not covered by any of the previous normal forms.
نرمال سازی مجموعه ای از مراحل طراحی پایگاه داده است که دسترسی به داده ها و ذخیره سازی آنها را کاراتر می سازد . در نتیجه افزونگی داده ها کاهش یافته و پایگاه داده دارای تناسب بهتری می گردد .
فرم نرمال اول :
در فرم نرمال اول ، گروههای تکراری حذف می گردد . آنها در یک جدول مجزا قرار می گیرند و با استفاده از یک رابطه یک به چند با آنها ارتباط برقرار می گردد .
*هر جدول دارای یک کلید اصلی است که می تواند از یک فیلد یا ترکیبی از چند فیلد ایجاد شده و به صورت یکتا نشاندهنده یک رکورد باشد .
*هر فیلد به صورت اتمیک است ، یعنی شامل بیش از یک مقدار نیست .
به عنوان مثال جدول WAGON را در نظر بگیرید . مشخصات جدول WAGON در هر ایستگاه به شرح زیر است :
wagon_id integer (ex. 101)
description string (ex. 'wagon_type, empty_weight, capacity, designer, design_date')
state string (ex. 'under repair')
timestamp datetime (ex. '22/12/2008 17:37')
station string (ex. 'New York Grand Central')
کلید اصلی (wagon_id, timestamp) است . این جدول در فرم نرمال اول نیست زیرا description اتمیک نیست . برای این که این جدول به فرم نرمال اول تبدیل گردد باید فیلد description به اجزای آن تجزیه گردد .
wagon_id integer
wagon_type string
empty_weight number
capacity number
designer string
design_date datetime
state string
timestamp datetime
station string
فرم نرمال دوم :
فرم نرمال دوم ، رابطه تابعی کلید جزئی را ( رابطه تابعی به این معنا است که فیلدی که جزئی از کلید اصلی است با فیلدهای دیگر جدول رابطه یک به چند دارد) حذف می کند به گونه ایکه کلید جزئی با فیلدهای وابسته تشکیل یک جدول جدا می دهند که این کلید جزئی در آن جدول به کلید اصلی تبدیل می گردد . در مثال ما "wagon_type", "empty_weight", "capacity" تنها به "wagon_id" وابستگی تابعی دارند و با فیلد "timestamp" ارتباطی ندارند . بنابراین جدول در فرم نرمال دوم نیست . بنابراین برای اینکه طراحی ما در فرم نرمال دوم باشد باید جدوال را به گونه ای بشکنیم که فیلدهای هر جدول تنها با تمام فیلدهای کلید اصلی آن رابطه داشته باشند به صورت زیر :
wagon_id integer
wagon_type string
empty_weight number
capacity number
designer string
design_date datetime
------------------------------------------------------
wagon_id integer
timestamp datetime
state string
station string
فرم نرمال سوم :
در فرم نرمال سوم ، وابستگی های تابعی فیلدهای غیرکلید با قرار دادن آن در جدولی مجزا حذف می گردد . در این حالت تمامی فیلدهای غیر کلید صرفا با کلید اصلی رابطه دارند ولاغیر . در مثال ما "empty_weight", "capacity", "designer" و "design_date" با "wagon_type" رابطه داشتند . بنابراین باید آن جدول را به دو جدول به صورت زیر بشکنیم :
wagon_id integer
wagon_type string
-------------------------------------
wagon_type string
empty_weight number
capacity number
designer string
design_date datetime
فرم نرمال چهارم :
در فرم نرمال چهارم ، اطلاعات چندمقداری غیروابسته به یکدیگر در یک جدول از یکدیگر جدا می گردند . در آخرین جدول مثال ما ، "empty_weight" و "capacity" برای مدیریت واگن ها به صورت روزمره مورد نیاز است در حالیکه "designer" و "design_date" صرفا جهت اطلاع است و بنابراین این داده ها در یک زمان مورد استفاده قرار نمی گیرند و باید به جداولی در فرم نرمال چهارم تجزیه گردند ، به صورت زیر :
wagon_type string
empty_weight number
capacity number
-----------------------------------
wagon_type string
designer string
design_date datetime
فرم نرمال پنجم :
در فرم نرمال پنجم افزونگی داده هایی که در مراحل قبل پوشش داده نشده است از بین می رود .