Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 1
    I doubt, if CHECK-constraint in any RBDMS can refer to different table Commented May 15 at 12:57
  • @Sergey but that's exactly what foreign key constraints do :). but you're right that there isn't likely to be CHECK support for this case in any RDMBS. Commented May 15 at 13:04
  • There is probably a better way of designing your database, can you post more of the DDL, including the parent and child tables? Perhaps a different design, such as polymorphic association or something. Commented May 15 at 13:04
  • @Sergey In SQL Server you can do it with a function in a CHECK constraint, although it's not recommended and has serious locking issues. SQL Server also has the option for an index view trick, see spaghettidba.com/2011/08/03/… Commented May 15 at 13:05
  • 3
    use before update/insert triggers for this Commented May 15 at 13:05