locked
How to avoid Duplicate rows in Dynamic Data? RRS feed

  • Question

  • User206176584 posted

    I have a table which will hold only foreign key reference to the other table. For e.g. if we have 2 different tables for Customer and Address, and another table say CustAddress which will hold just the CustomerID and AddressID to pair them.

    Since both the keys are Foreign Keys, in the Insert screen they appear as dropdown with CustomerName and Address as text and value as ID. And thats the way it should be because of usability. if it had been text box it would had been easy to validate :)

    Now, in the Dynamic Data website insert screen.. I can insert the same combination of CustomerName and Address any number of  times. Is there any way to restrict this without writing the custom page?

     

    Thursday, March 19, 2009 5:04 PM

Answers

  • User-1005219520 posted

    See this post. I'd also consider an update trigger on the row to check for duplicates.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 19, 2009 6:35 PM
  • User-1032240251 posted

    The problem with "prevention better than cure" is that the database could be changing behind the scenes, making the valid choices something that's constantly changing. The only fool-proof way to do this is allow all choices and have the database verify it during insert.

    And, FWIW, it's pretty common to use a composite primary key in this scenario.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 20, 2009 1:05 PM

All replies