What SQL databases support subqueries in CHECK constraints?

前端 未结 6 1892
走了就别回头了
走了就别回头了 2020-12-06 12:47

What SQL databases, if any, support subqueries in CHECK constraints?

At present and as far as I know, Oracle, MySQL, and PostgreSQL do not.

EDIT

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-06 13:01

    H2 also supports subqueries in constraints. In Psql mode no less :P

    MariaDB does not seems to also support it as a constraint.

    ALTER TABLE Table_1 ADD CONSTRAINT constraint_1 
    CHECK (column_1 > (SELECT MAX(column_2) FROM Table_2) NOT DEFERRABLE;
    

    Important Because the book is about the SQL-99 standard, the contents of this and other pages in the book may not directly apply to MariaDB. Use the navigation bar to navigate the book.

    This sort of thing was once illegal, but in modern variations of SQL, you'll see inter-table Constraint references on an occasional basis.

    For reference, this is the ticket for implementing check constraints on MariaDB. As of 2015-07-23, it is still in "Open" status.

提交回复
热议问题