Please let me know if below two declarations are same.
create table R1
( a INT PRIMARY KEY,
b INT references K(w));
Note: K is a table with single attribute w as primary key
create table R1
( a INT PRIMARY KEY,
b INT CHECK (b in (SELECT w FROM K));
Best Answer
To answer the question of whether they are equivalent, you need to declare K. Assuming:
The following would satisfy the CHECK constraint:
because:
evaluates to:
The rule is that the constraint must not evaluate to false. I don't know any DBMS that support subqueries in CHECK constraints, so I can't verify that.
I tested the foreign key variant against PostgreSQL 11, and the insert is rejected