code_junkie

Why is this kind of foreign keys possible

Nov 14th, 2011
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. create table prova_a (a number, b number);
  2. alter table prova_a add primary key (a,b);
  3. create table prova_b (a number, b number);
  4. alter table prova_b add foreign key (a,b) references prova_a(a,b) ;
  5. insert into prova_a values (1,2);
  6.  
  7. insert into prova_b values (123,null);
  8. insert into prova_b values (null,123);
  9.  
  10. Msg 8111, Level 16, State 1, Line 2
  11. Cannot define PRIMARY KEY constraint on nullable column in table 'prova_a'.
  12. Msg 1750, Level 16, State 0, Line 2
  13. Could not create constraint. See previous errors.
Add Comment
Please, Sign In to add comment