| | 2 | |
| | 3 | Во оваа секција е прикажана нормализацијата на постоечкиот ER модел до трета нормална форма (3NF), за да се отстранат зависностите, се избегне дуплирање на податоци и да се подобри интегритетот. |
| | 4 | |
| | 5 | === **actors**(**actor_id**, **actor_code**, **actor_name**, **country_code**, **type_code**) === |
| | 6 | |
| | 7 | Функционални зависности: |
| | 8 | **actor_id** → **actor_code**, **actor_name**, **country_code**, **type_code** |
| | 9 | **country_code** → **country_name** |
| | 10 | **type_code** → **type_description** |
| | 11 | |
| | 12 | 1NF: Сите атрибути се атомски |
| | 13 | 2NF: Сите не-клучни атрибути зависат целосно од примарниот клуч |
| | 14 | 3NF: Постои транзитивна зависност → **actor_id** → **country_code** → **country_name** |
| | 15 | |
| | 16 | Декомпозиција: |
| | 17 | **actors**(**actor_id**, **actor_code**, **actor_name**, **country_code**, **type_code**) |
| | 18 | **countries**(**country_code**, **country_name**) |
| | 19 | **actor_types**(**type_code**, **type_description**) |
| | 20 | |
| | 21 | === **locations**(**location_id**, **full_name**, **country_code**, **adm1_code**, **latitude**, **longitude**, **feature_id**) === |
| | 22 | |
| | 23 | Функционални зависности: |
| | 24 | **location_id** → **full_name**, **country_code**, **adm1_code**, **latitude**, **longitude**, **feature_id** |
| | 25 | **country_code** → **country_name** |
| | 26 | |
| | 27 | 1NF: Атомски вредности |
| | 28 | 2NF: Зависности од целиот клуч |
| | 29 | 3NF: Транзитивна зависност преку **country_code** |
| | 30 | |
| | 31 | Декомпозиција: |
| | 32 | **locations**(**location_id**, **full_name**, **country_code**, **adm1_code**, **latitude**, **longitude**, **feature_id**) |
| | 33 | **countries**(**country_code**, **country_name**) |
| | 34 | |
| | 35 | === **subscription**(**subscription_id**, **user_id**, **plan_id**, **start_date**, **end_date**, **status**) === |
| | 36 | |
| | 37 | Функционални зависности: |
| | 38 | **subscription_id** → **user_id**, **plan_id**, **start_date**, **end_date**, **status** |
| | 39 | **status** → **status_description** |
| | 40 | |
| | 41 | 1NF: Атомски атрибути |
| | 42 | 2NF: Сите атрибути зависат од клучот |
| | 43 | 3NF: Транзитивна зависност преку **status** |
| | 44 | |
| | 45 | Декомпозиција: |
| | 46 | **subscription**(**subscription_id**, **user_id**, **plan_id**, **start_date**, **end_date**, **status_code**) |
| | 47 | **statuses**(**status_code**, **status_description**) |
| | 48 | |
| | 49 | === **notifications**(**notification_id**, **user_id**, **event_id**, **notification_date**, **status**) === |
| | 50 | |
| | 51 | Функционални зависности: |
| | 52 | **notification_id** → **user_id**, **event_id**, **notification_date**, **status** |
| | 53 | **status** → **status_description** |
| | 54 | |
| | 55 | 1NF: Атомски вредности |
| | 56 | 2NF: Зависности од целиот клуч |
| | 57 | 3NF: Транзитивна зависност преку **status** |
| | 58 | |
| | 59 | Декомпозиција: |
| | 60 | **notifications**(**notification_id**, **user_id**, **event_id**, **notification_date**, **status_code**) |
| | 61 | **statuses**(**status_code**, **status_description**) |
| | 62 | |
| | 63 | === Нови релации по нормализација === |
| | 64 | |
| | 65 | CREATE TABLE **countries** ( |
| | 66 | **country_code** VARCHAR(5) PRIMARY KEY, |
| | 67 | **country_name** VARCHAR(100) |
| | 68 | ); |
| | 69 | |
| | 70 | CREATE TABLE **actor_types** ( |
| | 71 | **type_code** VARCHAR(10) PRIMARY KEY, |
| | 72 | **type_description** VARCHAR(100) |
| | 73 | ); |
| | 74 | |
| | 75 | CREATE TABLE **statuses** ( |
| | 76 | **status_code** VARCHAR(20) PRIMARY KEY, |
| | 77 | **status_description** TEXT |
| | 78 | ); |
| | 79 | |
| | 80 | === Финален дизајн (за **actors**) === |
| | 81 | |
| | 82 | CREATE TABLE **actors** ( |
| | 83 | **actor_id** SERIAL PRIMARY KEY, |
| | 84 | **actor_code** VARCHAR(10) NOT NULL, |
| | 85 | **actor_name** VARCHAR(100) NOT NULL, |
| | 86 | **country_code** VARCHAR(5), |
| | 87 | **type_code** VARCHAR(10), |
| | 88 | FOREIGN KEY (**country_code**) REFERENCES **countries**(**country_code**), |
| | 89 | FOREIGN KEY (**type_code**) REFERENCES **actor_types**(**type_code**) |
| | 90 | ); |