Should create a surrogate key instead of a composite key?

Composition:

Actor <=== ActorMovie ===> Movie

ActorMovie: ActorID (fk), MovieId (fk)... ===> pk: (ActorID, MovieID)

Should I create a surrogate key for a table ActorMovielike this?

ActorMovie: ActorMovieID (pk), ActorID (fk), MovieId (fk)...
+4
source share
7 answers

Conventions are good if they are useful

"SQL Antipatterns", Chapter 4, "ID Required"

Primary key intent

The primary key is what you can use to identify your row with a unique address in the table. This means that the primary key can be not only a surrogate column. In fact, the primary key should be:

  • . . , , .
  • . , (.. , )
  • Single. , .

, . - . first_name + last_name + taxpayer_id ? - . , , , . , , .

, "--" , , . , , , ( - , , ). ActorID + MovieID , . , ( ), , . , , :

  • . , . : ,
  • (, , ) . .

- , , ( ) , antipattern - .

:

+8

. :

  • , , .
  • / , .
  • .

, , .

+3

, , -, : InnoDB .

, ​​ B-Tree, . B-Tree ( " ", , - , ), .

, .

+2

, () (-), ( ), . , , .

+1

(1NF) .

ActorID MovieID , ActorMovieID.

. :

+1

: , , .

, " , ", . . . .

+1

:

  • .
  • . , ; , .
  • , ( , , , ). , , .
  • , , , , , .
  • - , CRUD , .
  • . , . , , , .
  • , -, , .
  • .
  • , , . , , . , .
0

All Articles