-1

I am using mysql to create a database.

I have one base table named GP, with its Primary Key a composite Primary Key(SAT_ID, DATE). I want to create multiple tables with the same Primary Key (SAT_ID,DATE), but would like to avoid data redundancy.

Is there a way to create a Primary Key for the children tables (for example ID INT NOT NULL AUTO_INCREMENT) that references the composite Primary Key (SAT_ID,DATE), so that I can avoid having the same composite Primary Key (SAT_ID,DATE) in every other table ?

I know the question can seem silly but there is something I don't understand about composite keys and data redundancy.

Thanks

Antezo
  • 63
  • 2
  • 7
  • Is there a way to create a Primary Key f... no there isn't, but you might consider junction r=tables – P.Salmon Nov 04 '20 at 16:08
  • You could modify your GP table to have an autoincrement `ID` as PK and an unique index on `(SAT_ID, DATE)`, then you can use `ID` as foreign key in your other tables – Pepper Nov 04 '20 at 16:24
  • Thanks @Pepper, that should do the trick. – Antezo Nov 05 '20 at 14:19

1 Answers1

1

@pepper's solution (suggested in the comments) works just fine:

You could modify your GP table to have an autoincrement ID as PK and an unique index on (SAT_ID, DATE), then you can use ID as foreign key in your other tables

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Antezo
  • 63
  • 2
  • 7