我知道主键应该是唯一的。但我正在为房地产代理创建一个数据库,其中邮政编码是地址表的主键。但是,如果一个房产是出售/出租的,并且它位于一个公寓楼内,那么许多房产将有相同的邮政编码。在将 PostCode 保留为 PK 的同时,我如何使它不是唯一的?感谢你
到目前为止我的代码:
CREATE TABLE `Properties` (
`PropertyID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`Property Type` varchar(20) NOT NULL,
`PostCode` varchar(8) NOT NULL,
`Bedrooms` tinyint(2) DEFAULT NULL,
`Bathrooms` tinyint(2) DEFAULT NULL,
`Ensuite` tinyint(1) DEFAULT NULL,
`Kitchen` tinytext,
`LivingRoom` tinytext,
`DiningRoom` tinytext,
`UtilityRoom` tinytext,
`Conservatory` tinytext,
`Garage` tinytext,
`Garden` tinytext,
`Furnished` tinytext,
`Type` char(15) NOT NULL,
PRIMARY KEY (`PropertyID`),
KEY `Property Type` (`Property Type`),
KEY `PostCode` (`PostCode`),
CONSTRAINT `Properties_ibfk_2` FOREIGN KEY (`PostCode`) REFERENCES `Address` (`PostCode`),
CONSTRAINT `Properties_ibfk_1` FOREIGN KEY (`Property Type`) REFERENCES `PropertyType` (`Property Type`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
CREATE TABLE `Address` (
`PostCode` varchar(8) NOT NULL,
`HouseN` text NOT NULL,
`AddL1` varchar(25) NOT NULL,
`AddL2` varchar(25) DEFAULT NULL,
`AddL3` varchar(25) DEFAULT NULL,
`County` char(20) NOT NULL,
PRIMARY KEY (`PostCode`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1