简体   繁体   中英

MySQL/PHP Database Normalisation

Im working amongst a group of fellow students creating relational mysql database to be used in conjunction with php.

We are attempting to normalise the database and are differing in opinion. When normalising and creating a new table two of the group, myself included feel the best practice is for the foreign key to be left behind in the existing table as the unique identifier in the new table becomes the new PK.

The remainder of the group have been taught/feel this should be implemented the other way, ie the primary key is left behind.

Could it be the case as long as a relationship is present it will do the job, or is it the case one method is correct over the other.

Thanks in advance

Gary

This depends on what you are doing. When you are removing a partial dependency then the rule is:

r = (A, B, C, D)
   where
      A and B makes a composite primary key and
      C is dependent on A 
   then
      r1 = (A, C)
      r2 = (A, B, D)

If you are removing a Transitive dependency then:

r = (A, B, C)
     where A is the primary key and C is dependent on B then

     r1 = (A, B)
     r2 = (B, C)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM