【发布时间】:2026-02-10 16:05:01
【问题描述】:
我正在为房地产应用程序设计一个数据库。应用程序的基本结构如下。
A) 应用程序包括存储与 房地产。
B) 属性分为类别和交易类型 (出售、出租、租赁)等。
c) 类别分为子类别。
以存在以下记录为例。
Transaction = Rent , Sale, Lease.
Categories = Residential , Commercial , Industrial , Agricultural
SubCategories = Residential_Apartment (belongs to residential category)
Villa/House (belongs to residential category)
Commercial_OfficeSpace (belongs to commercial category)
Commercial_Plot (belongs to commercial category)
Industrial_Plot (belongs to industrial category)
我必须在属性和上述所有三个之间创建关系,以识别例如正在存储的属性
Property with id:1 is Transaction:Rent, Category:Residential, Subcategory:Villa/House
Property with id:2 is Transaction:Sale, Category:Residential, Subcategory:Residential_Apartment
Property with id:3 is Transaction:Lease, Category:Commercial, Subcategory:Commercial_Officespace
我目前的表结构如下
CREATE TABLE IF NOT EXISTS `transaction` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`transactionName` varchar(30) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `category` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`categoryName` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `subcategory` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`subCategoryName` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `property` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(100) NOT NULL,
`transaction_id` int(11) NOT NULL,
`category_id` int(11) NOT NULL,
`subcategory_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
编辑:
我的问题是。
看到它们之间的关系,是不是存储记录的正确方式?我主要关心的是类别和子类别表,因为现在我无法考虑将来可能发生的设计缺陷。我只是想知道如果您被告知设计类似的东西,您将如何将记录存储在表中。主要是类别和子类别部分。
【问题讨论】:
标签: mysql database-design one-to-many