I have two tables one is product which is a parent table with one primary key and i do have another child table of product, which is a product_details table. But the child table is linking with parent table(product) with logical data instead of foreign key,as we are doing this relationship with the help of java code in the coding side, instead of depending on the data base, which make it as tight couple.To avoid tight coupling between the tables we are storing the primary key value in the child table.
Please refer this image with data which is creating the logical relationship between Product and Product Details tables.
The Scripts are :
CREATE TABLE `tbl_product` (
`product_id` varchar(200) NOT NULL,
`product_details_id` varchar(200) DEFAULT NULL,
`currency` varchar(20) DEFAULT NULL,
`lead_time` varchar(20) DEFAULT NULL,
`brand_id` varchar(20) DEFAULT NULL,
`manufacturer_id` varchar(150) DEFAULT NULL,
`category_id` varchar(200) DEFAULT NULL,
`units` varchar(20) DEFAULT NULL,
`transit_time` varchar(20) DEFAULT NULL,
`delivery_terms` varchar(20) DEFAULT NULL,
`payment_terms` varchar(20) DEFAULT NULL,
PRIMARY KEY (`product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `tbl_product_details` (
`product_details_id` varchar(200) NOT NULL,
`product_id` varchar(200) DEFAULT NULL,
`product_name` varchar(50) DEFAULT NULL,
`landingPageImage` varchar(100) DEFAULT NULL,
`product_description_brief` text CHARACTER SET latin1,
`product_description_short` text CHARACTER SET latin1,
`product_price_range` varchar(50) DEFAULT NULL,
`product_discount_price` varchar(20) DEFAULT NULL,
`production_Type` varchar(20) DEFAULT NULL,
PRIMARY KEY (`product_details_id`),
UNIQUE KEY `product_id` (`product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Please suggest me, we are following this kind of relationship in my company, as the manager is saying it will give us flexible to us. Please suggest me the Pros and Cons of the design.I know that if we lose the data from the table, we can't know the relationship between the two tables.
PRIMARY KEY
and aUNIQUE
key, bothVARCHAR(200)
in one of the tables??