title: multiple foreign keys as primary key postgres, should I do it?
body: <p>This is one of those: why I should or why I should not.</p>
  
  <p>So my books app has reviews, but one user must not review the same book more than one time. In my point of view makes sense to create a table for the reviews and make the user_id and the book_id (ISBN) as the PRIMARY KEY for the reviews table. But, could it be a problem at some point if the application gets too many reviews, for example, could that decision slow the queries?</p>
  
  <p>I am using postgres and I am not sure if the following code is correct:</p>
  
  <pre><code>CREATE TABLE users(
      user_id PRIMARY KEY SERIAL,
      user_name VARCHAR NOT NULL UNIQUE,
      pass_hash VARCHAR NOT NULL,
      email VARCHAR NOT NULL UNIQUE,
  );
  
  CREATE TABLE books(
      book_id PRIMARY KEY BIGINT,
      author VARCHAR NOT NULL,
      title VARCHAR NOT NULL,
      year INT NOT NULL CHECK (year &gt; 1484),
      review_count INT DEFAULT 0 NOT NULL,
      avrg_score FLOAT,
  );
  
  CREATE TABLE reviews(
      user_id INT FOREIGN KEY REFERENCES users(user_id) NOT NULL
      book_id INT FOREIGN KEY REFERENCES books(book_id) NOT NULL
      score INT NOT NULL CHECK (score &gt; 0, score &lt; 11)
      PRIMARY KEY (book_id, user_id)
  
  );
  </code></pre>