这是在 3NF 中吗?
is this in 3NF?
这是在 3NF 中吗?
mysql show tables;
+--------------------+
| Tables_in_hospital |
+--------------------+
| address |
| bed |
| department |
| hospital_number |
| phone_number |
| region |
| type |
+--------------------+
mysql desc hospital_number; //PRI key = Hospital_Number
+-----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------+-------+
| name | varchar(64) | NO | | NULL | |
| Hospital_Number | int(11) | NO | PRI | NULL | |
+-----------------+-------------+------+-----+---------+-------+
mysql desc address; //PRI key = Address, FOR key = Hospital_number
+-----------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+-------+
| Address | varchar(128) | NO | PRI | NULL | |
| Latitude | double | NO | | NULL | |
| Longitude | double | NO | | NULL | |
| Postcode | varchar(32) | NO | | NULL | |
| Hospital_Number | int(11) | NO | MUL | NULL | |
+-----------------+--------------+------+-----+---------+-------+
mysql desc department; //PRI key = Hospital_number + Department,
//FOR key = Hospital_number
+-----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------+-------+
| Hospital_Number | int(11) | NO | PRI | NULL | |
| Department | varchar(64) | NO | PRI | NULL | |
+-----------------+-------------+------+-----+---------+-------+
mysql desc bed; //PRI key = Hospital_number + Bed,
//FOR key = Hospital_number
+-----------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+---------+------+-----+---------+-------+
| Hospital_Number | int(11) | NO | PRI | NULL | |
| Bed | int(11) | NO | PRI | NULL | |
+-----------------+---------+------+-----+---------+-------+
mysql desc phone_number; //PRI key = Hospital_number + Phone_number,
//FOR key = Hospital_number
+-----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------+-------+
| Hospital_Number | int(11) | NO | PRI | NULL | |
| Phone_Number | varchar(64) | NO | PRI | NULL | |
+-----------------+-------------+------+-----+---------+-------+
mysql desc region; //PRI key = Hospital_number + region,
//FOR key = Hospital_number
+-----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------+-------+
| Hospital_Number | int(11) | NO | PRI | NULL | |
| Region | varchar(12) | NO | PRI | NULL | |
+-----------------+-------------+------+-----+---------+-------+
mysql desc type; //PRI key = Hospital_number + type,
//FOR key = Hospital_number
+-----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------+-------+
| Hospital_Number | int(11) | NO | PRI | NULL | |
| Type | varchar(12) | NO | PRI | NULL | |
+-----------------+-------------+------+-----+---------+-------+
第一次用MySQL做数据库table,不知道是否满足3NF。
1 NF 对将部门 table 从医院 table 分开感到满意。
我认为 2 NF、3 NF 令人满意,但我不确定。
请检查我的数据库
我的表格有什么错误的部分?
我所说的医院和地区(或类型)之间的多对多关系过于复杂:给定的医院不太可能与多个地区相关联(至少在您的模型中不是;医院 可以 存在多个区域)。因此,我们将采用更简单的一对多关系。您的模型中的问题仍然存在,您可能在同一地区拥有多家医院,如果您决定更改该地区的名称,您将需要更新多行(与 type
[=26 相同的故事=]):
使用 tables hospital_number
(顺便说一句,我可能只是命名为 hospital
)和 region
作为示例(您可以概括这个至 table type
):
CREATE TABLE `region` (
`Region_Number` int(11) NOT NULL AUTO_INCREMENT,
`Region` varchar(12) NOT NULL,
PRIMARY KEY (`Region_Number`)
) ENGINE=InnoDB;
CREATE TABLE `hospital_number` (
`name` varchar(64) NOT NULL,
`Hospital_Number` int(11) NOT NULL AUTO_INCREMENT,
`Region_Number` int(11) NOT NULL,
PRIMARY KEY (`Hospital_Number`),
CONSTRAINT FOREIGN KEY (`Region_Number`) REFERENCES `region` (`Region_Number`) ON UPDATE CASCADE
) ENGINE=InnoDB;
请注意,在 table region
中,列 Region
不是主键的一部分。
这是在 3NF 中吗?
mysql show tables;
+--------------------+
| Tables_in_hospital |
+--------------------+
| address |
| bed |
| department |
| hospital_number |
| phone_number |
| region |
| type |
+--------------------+
mysql desc hospital_number; //PRI key = Hospital_Number
+-----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------+-------+
| name | varchar(64) | NO | | NULL | |
| Hospital_Number | int(11) | NO | PRI | NULL | |
+-----------------+-------------+------+-----+---------+-------+
mysql desc address; //PRI key = Address, FOR key = Hospital_number
+-----------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+-------+
| Address | varchar(128) | NO | PRI | NULL | |
| Latitude | double | NO | | NULL | |
| Longitude | double | NO | | NULL | |
| Postcode | varchar(32) | NO | | NULL | |
| Hospital_Number | int(11) | NO | MUL | NULL | |
+-----------------+--------------+------+-----+---------+-------+
mysql desc department; //PRI key = Hospital_number + Department,
//FOR key = Hospital_number
+-----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------+-------+
| Hospital_Number | int(11) | NO | PRI | NULL | |
| Department | varchar(64) | NO | PRI | NULL | |
+-----------------+-------------+------+-----+---------+-------+
mysql desc bed; //PRI key = Hospital_number + Bed,
//FOR key = Hospital_number
+-----------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+---------+------+-----+---------+-------+
| Hospital_Number | int(11) | NO | PRI | NULL | |
| Bed | int(11) | NO | PRI | NULL | |
+-----------------+---------+------+-----+---------+-------+
mysql desc phone_number; //PRI key = Hospital_number + Phone_number,
//FOR key = Hospital_number
+-----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------+-------+
| Hospital_Number | int(11) | NO | PRI | NULL | |
| Phone_Number | varchar(64) | NO | PRI | NULL | |
+-----------------+-------------+------+-----+---------+-------+
mysql desc region; //PRI key = Hospital_number + region,
//FOR key = Hospital_number
+-----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------+-------+
| Hospital_Number | int(11) | NO | PRI | NULL | |
| Region | varchar(12) | NO | PRI | NULL | |
+-----------------+-------------+------+-----+---------+-------+
mysql desc type; //PRI key = Hospital_number + type,
//FOR key = Hospital_number
+-----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------+-------+
| Hospital_Number | int(11) | NO | PRI | NULL | |
| Type | varchar(12) | NO | PRI | NULL | |
+-----------------+-------------+------+-----+---------+-------+
第一次用MySQL做数据库table,不知道是否满足3NF。 1 NF 对将部门 table 从医院 table 分开感到满意。 我认为 2 NF、3 NF 令人满意,但我不确定。 请检查我的数据库 我的表格有什么错误的部分?
我所说的医院和地区(或类型)之间的多对多关系过于复杂:给定的医院不太可能与多个地区相关联(至少在您的模型中不是;医院 可以 存在多个区域)。因此,我们将采用更简单的一对多关系。您的模型中的问题仍然存在,您可能在同一地区拥有多家医院,如果您决定更改该地区的名称,您将需要更新多行(与 type
[=26 相同的故事=]):
使用 tables hospital_number
(顺便说一句,我可能只是命名为 hospital
)和 region
作为示例(您可以概括这个至 table type
):
CREATE TABLE `region` (
`Region_Number` int(11) NOT NULL AUTO_INCREMENT,
`Region` varchar(12) NOT NULL,
PRIMARY KEY (`Region_Number`)
) ENGINE=InnoDB;
CREATE TABLE `hospital_number` (
`name` varchar(64) NOT NULL,
`Hospital_Number` int(11) NOT NULL AUTO_INCREMENT,
`Region_Number` int(11) NOT NULL,
PRIMARY KEY (`Hospital_Number`),
CONSTRAINT FOREIGN KEY (`Region_Number`) REFERENCES `region` (`Region_Number`) ON UPDATE CASCADE
) ENGINE=InnoDB;
请注意,在 table region
中,列 Region
不是主键的一部分。