marko_b123
marko_b123

Reputation: 330

database grouping data in tables

I have a database with 3 main tables, and every of that table has first 7 of 20 fields the same.

for example:

table1 - a,b,c,d,e,f,g,x,y,z,df,gt,er,re,re    
table2 - a,b,c,d,e,f,g,q,w,c,v,t,v,b,t,l,f    
table3 - a,b,c,d,e,f,g,b,n,m,j,h,g,d,f,r,e

first fields (a,b,c,d,e,f,g) are same and other are different.

My question is:

together_table:a,b,c,d,e,f,g

table1 - together_table_id,x,y,z,df,gt,er,re,re    
table2 - together_table_id,q,w,c,v,t,v,b,t,l,f    
table3 - together_table_id,b,n,m,j,h,g,d,f,r,e

or it muste be like:

table1 - a,b,c,d,e,f,g,x,y,z,df,gt,er,re,re    
table2 - a,b,c,d,e,f,g,q,w,c,v,t,v,b,t,l,f    
table3 - a,b,c,d,e,f,g,b,n,m,j,h,g,d,f,r,e

i am using mySql

Upvotes: 0

Views: 46

Answers (1)

simon at rcl
simon at rcl

Reputation: 7344

together_table:a,b,c,d,e,f,g

table1 - together_table_id,x,y,z,df,gt,er,re,re    
table2 - together_table_id,q,w,c,v,t,v,b,t,l,f    
table3 - together_table_id,b,n,m,j,h,g,d,f,r,e

This is much, much better. Look up Normal Form. Databases are usually designed to be in 3rd Normal Form (also written as 3NF). To get there, you start with your first guess and then apply the rules to make it 1NF (First Normal Form). Then apply the rules of 2NF, and finally 3NF. There are other higher Normal Forms but they are only required for very rare circumstances.

Upvotes: 1

Related Questions