我有点困惑如何在数据库图中检查 BCNF。我看到了一些关于什么是数据库规范化(1NF、2NF ......)的 youtube 视频,但是到了将这些规则应用于我的项目的时候,我不知道该怎么办 。
ER图到postgre sql代码:
CREATE TABLE People (
birth_date DATE NOT NULL,
last_name CHAR(30) NOT NULL,
name CHAR(30) NOT NULL,
person_id INTEGER NOT NULL,
PRIMARY KEY (person_id) );
CREATE TABLE Roles (
role_id INTEGER NOT NULL,
role_name CHAR(30) NOT NULL,
PRIMARY KEY (role_id) );
CREATE TABLE genre (
genre_id INTEGER NOT NULL,
genre_name INTEGER NOT NULL,
PRIMARY KEY (genre_id) );
CREATE TABLE Movies (
movie_id INTEGER NOT NULL,
title CHAR(30) NOT NULL,
rating REAL NOT NULL,
release_date DATE NOT NULL,
PRIMARY KEY (movie_id) );
CREATE TABLE film_people (
role_id INTEGER NOT NULL,
person_id INTEGER NOT NULL,
movie_id INTEGER NOT NULL,
FK1_movie_id INTEGER NOT NULL,
FK2_person_id INTEGER NOT NULL,
FK3_role_id INTEGER NOT NULL,
PRIMARY KEY (FK1_movie_id, FK2_person_id, FK3_role_id),
UNIQUE (role_id),
UNIQUE (person_id),
UNIQUE (movie_id) );
CREATE TABLE film_genre (
movie_id INTEGER NOT NULL,
genre_id INTEGER NOT NULL,
FK1_movie_id INTEGER NOT NULL,
FK2_genre_id INTEGER NOT NULL,
PRIMARY KEY (FK1_movie_id, FK2_genre_id),
UNIQUE (movie_id),
UNIQUE (genre_id) );
ALTER TABLE film_people ADD FOREIGN KEY (FK1_movie_id) REFERENCES Movies (movie_id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE film_people ADD FOREIGN KEY (FK2_person_id) REFERENCES People (person_id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE film_people ADD FOREIGN KEY (FK3_role_id) REFERENCES Roles (role_id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE film_genre ADD FOREIGN KEY (FK1_movie_id) REFERENCES Movies (movie_id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE film_genre ADD FOREIGN KEY (FK2_genre_id) REFERENCES genre (genre_id) ON DELETE CASCADE ON UPDATE CASCADE;
电影数据库设计的主要来源: 如何设计电影数据库?
因此,在给定的 ER 图上,我的目的是找到函数依赖关系并应用 BCNF 规范化。
任何帮助表示赞赏!