Storing comma seperated Foreign Key values in a table in mysql (getting 1452 error) -
i having 2 tables brand , vendors.
the brand table follows (brand_id varchar):
brand_id brand_name --------- -------------- 01 kfc 02 mcd 03 cream stone i created table vendor has brand_id foreign key statement:
create table vendor(vendor_id varchar(20), name varchar(50), brand_id varchar(10), primary key (vendor_id), foreign key(brand_id) references vendor_brand(brand_id)); now requirement want store comma separated brand_id's in vendor table as:
vendor_id name brand_id --------- -------------- --------------- 1 hi bakers 01, 02 2 test confectioners 02 3 cream parlour 01, 02, 03 iam getting error #1452 on inserting. how create comma separated values?
that not work store multiple foreign keys in column. , should absolutely not if weren't keys. never, never, never store multiple values in 1 column! give headaches future selects , slow performance-wise.
a improve approach have new table called
vendor_brands ------------- vendor_id brand_id mysql
No comments:
Post a Comment