Version 2 (modified by 14 hours ago) ( diff ) | ,
---|
Нормализација и подобрувања на дизајнот
Во оваа секција е прикажана нормализацијата на постоечкиот ER модел до трета нормална форма (3NF), за да се отстранат зависностите, се избегне дуплирање на податоци и да се подобри интегритетот.
actors(actor_id, actor_code, actor_name, country_code, type_code)
Функционални зависности: actor_id → actor_code, actor_name, country_code, type_code country_code → country_name type_code → type_description
1NF: Сите атрибути се атомски 2NF: Сите не-клучни атрибути зависат целосно од примарниот клуч 3NF: Постои транзитивна зависност → actor_id → country_code → country_name
Декомпозиција: actors(actor_id, actor_code, actor_name, country_code, type_code) countries(country_code, country_name) actor_types(type_code, type_description)
locations(location_id, full_name, country_code, adm1_code, latitude, longitude, feature_id)
Функционални зависности: location_id → full_name, country_code, adm1_code, latitude, longitude, feature_id country_code → country_name
1NF: Атомски вредности 2NF: Зависности од целиот клуч 3NF: Транзитивна зависност преку country_code
Декомпозиција: locations(location_id, full_name, country_code, adm1_code, latitude, longitude, feature_id) countries(country_code, country_name)
subscription(subscription_id, user_id, plan_id, start_date, end_date, status)
Функционални зависности: subscription_id → user_id, plan_id, start_date, end_date, status status → status_description
1NF: Атомски атрибути 2NF: Сите атрибути зависат од клучот 3NF: Транзитивна зависност преку status
Декомпозиција: subscription(subscription_id, user_id, plan_id, start_date, end_date, status_code) statuses(status_code, status_description)
notifications(notification_id, user_id, event_id, notification_date, status)
Функционални зависности: notification_id → user_id, event_id, notification_date, status status → status_description
1NF: Атомски вредности 2NF: Зависности од целиот клуч 3NF: Транзитивна зависност преку status
Декомпозиција: notifications(notification_id, user_id, event_id, notification_date, status_code) statuses(status_code, status_description)
Нови релации по нормализација
CREATE TABLE countries (
country_code VARCHAR(5) PRIMARY KEY,
country_name VARCHAR(100)
);
CREATE TABLE actor_types (
type_code VARCHAR(10) PRIMARY KEY,
type_description VARCHAR(100)
);
CREATE TABLE statuses (
status_code VARCHAR(20) PRIMARY KEY,
status_description TEXT
);
Финален дизајн (за actors)
CREATE TABLE actors (
actor_id SERIAL PRIMARY KEY,
actor_code VARCHAR(10) NOT NULL,
actor_name VARCHAR(100) NOT NULL,
country_code VARCHAR(5),
type_code VARCHAR(10),
FOREIGN KEY (country_code) REFERENCES countries(country_code),
FOREIGN KEY (type_code) REFERENCES actor_types(type_code)
);
Attachments (1)
- normalized_ddl_schema.sql (4.6 KB ) - added by 14 hours ago.
Download all attachments as: .zip