我想创建一个数据库来存储虚构的“宇宙创建尝试”。我的第一个想法是打破结构,我最终得到了这些表格。但当我将这些表视为图表时,它突然看起来像一个糟糕的方法:(。现在我想要求指导,如果我的方法是正确的,或者是否有更好的设计模式来创建我打算创建的结构。
我正在寻找信息,但我没有达到“链式”这个词或者我发现的信息并没有真正帮助我找到答案。也许我在使用错误的术语进行搜索。
DROP TABLE IF EXISTS galactic_department CASCADE;
CREATE TABLE galactic_department (
id serial UNIQUE PRIMARY KEY,
code text
);
DROP TABLE IF EXISTS researcher CASCADE;
CREATE TABLE researcher (
id serial UNIQUE PRIMARY KEY,
galactic_department_id bigint REFERENCES galactic_department (id),
code text,
galactic_name text,
galactic_phone text,
galactic_email text
);
DROP TABLE IF EXISTS experiment CASCADE;
CREATE TABLE experiment (
id serial UNIQUE PRIMARY KEY,
creation_attampt_id text,
conditions text,
creation_success boolean,
researcher_id bigint REFERENCES researcher (id),
universe_id bigint REFERENCES universe (id)
);
DROP TABLE IF EXISTS universe CASCADE;
CREATE TABLE universe (
id serial UNIQUE PRIMARY KEY,
name text
);
DROP TABLE IF EXISTS cluster CASCADE;
CREATE TABLE cluster (
id serial UNIQUE PRIMARY KEY,
universe_id bigint REFERENCES universe (id),
name text
);
DROP TABLE IF EXISTS galaxy CASCADE;
CREATE TABLE galaxy (
id serial UNIQUE PRIMARY KEY,
cluster_id bigint REFERENCES cluster (id),
name text
);
DROP TABLE IF EXISTS star CASCADE;
CREATE TABLE star (
id serial UNIQUE PRIMARY KEY,
galaxy_id bigint REFERENCES galaxy (id),
name text
);
DROP TABLE IF EXISTS planet CASCADE;
CREATE TABLE planet (
id serial UNIQUE PRIMARY KEY,
star_id bigint REFERENCES star (id),
name text
);
DROP TABLE IF EXISTS planet_moon CASCADE;
CREATE TABLE planet_moon (
id serial UNIQUE PRIMARY KEY,
planet_id bigint REFERENCES planet (id),
name text
);
DROP TABLE IF EXISTS lifeform CASCADE;
CREATE TABLE lifeform (
id serial UNIQUE PRIMARY KEY,
planet_id bigint REFERENCES planet (id),
name text
);
DROP TABLE IF EXISTS lifeform_water CASCADE;
CREATE TABLE lifeform_water (
id serial UNIQUE PRIMARY KEY,
lifeform_id bigint REFERENCES lifeform (id),
fin_count text
);
DROP TABLE IF EXISTS lifeform_ground CASCADE;
CREATE TABLE lifeform_ground (
id serial UNIQUE PRIMARY KEY,
lifeform_id bigint REFERENCES lifeform (id),
leg_count text
);
DROP TABLE IF EXISTS lifeform_air CASCADE;
CREATE TABLE lifeform_air (
id serial UNIQUE PRIMARY KEY,
lifeform_id bigint REFERENCES lifeform (id),
wing_count text
);
架构如下:
答案 0 :(得分:0)
我是数据库设计师和程序员,对我来说很好看。我不太确定该部门,研究人员,实验是否正确,但银河系和相关表格看起来还不错。我需要更多地了解这一切是如何一起工作的......但你肯定是在正确的轨道上。