0

I have a table with two columns.

Recommendation
——————————
movieID | String
recMovieID | String

I want to insert unique pair to that database. I want to check INSERT statement such that it will check if the pair already exist. If the pair is new, the INSERT statement is executed.

techraf
  • 53,268
  • 22
  • 149
  • 166
Aye Thwin
  • 79
  • 1
  • 1
  • 5
  • 1
    Possible duplicate of [Insert multiple rows with same primary key in sql using php](http://stackoverflow.com/questions/20288038/insert-multiple-rows-with-same-primary-key-in-sql-using-php) – Alessandro Da Rugna Oct 17 '16 at 07:24
  • have the db enforce uniqueness on the composite – Drew Oct 17 '16 at 07:25
  • http://stackoverflow.com/questions/15898599/insert-query-check-if-record-exists-if-not-insert-it I think it may be useful to your case. – Atom_Awesome Oct 17 '16 at 07:58

1 Answers1

1
ALTER TABLE Recommendation ADD CONSTRAINT movieRecUnique UNIQUE(movieID,recMovieID)
Twinkles
  • 1,890
  • 1
  • 16
  • 28