I am designing a database for a real estate application. the basic structure of the application is as follows.
A) the application consist of storing the records related to real estate properties.
B) the properties are divided into categories and transaction type (sale, rent, lease) etc.
c) categories is divided into subcategories.
take for example the following records exist.
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)
i have to create a relationship between the propert and all three above to identify which property is being stored for example
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
my current table structure is as follows
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;
Edit:
My Question is.
seeing the relationship between them, is it the right way of storing the records? my main concern here is categories and subcategory table, as because right now i am not able to think about design flaw that may occur in future. i just want to know how would you store the records in table if you were told to design something similar. mainly the category and subcategory part.