Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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));
share|improve this question
    
If K(w) is a primary or unique key, they are similar declarations. But most SQL products accept only the first syntax (FOREIGN KEY constraint) and not the second (which has a subquery in a CHECK constraint) –  ypercube Jun 16 at 8:52

1 Answer 1

Not exactly - with your second CREATE statement, the same value of b can occur multiple times in table K, whereas with the first statement, it will occur once and once only. It's unusual - what are you trying to achieve?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.