Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql - normalization of database

Tags:

database

mysql

I have a MySQL database and I want to normalize it in an efficient way. I have a table in my database in which i am getting data into column in the form of array. Actually I have three tables (details, country, material). In table "country" I have two column that are (id,country_name). In table "material" I have two column (id, material) and in table "details" i have four column (id, vendor, countries, materials). In this scenario, each vendor has multiple countries and materials and I am inserting ids of country and material in details table. Here is the screenshot: detail table

so how I accurately normalize my database? Thanks in advance

like image 497
Haris Khan Avatar asked Jul 12 '26 09:07

Haris Khan


1 Answers

Remove countries and materials columns from Details table.

You can create a fourth table which will depict the relationship between vendor,country and material:

vendor_id   country_id   material_id
   1            3            5
   1            6            9
   1            7            24

Here all the columns will be foreign key and together they will form composite primary key

like image 178
codeLover Avatar answered Jul 14 '26 00:07

codeLover



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!