Thread: Relations
View Single Post
  #6 (permalink)  
Old 12-15-09, 07:19
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
"coment_id references comments" is a short-hand way of declaring a column as a foreign key to the primary key of the "referenced" table. So this:
Code:
create table images (image_id integer primary key,
  comment_id references comments);
is equivalent to this:
Code:
create table images (image_id integer primary key,
  comment_id integer,
  foreign key(comment_id) references comments (comment_id)
);
Example:
Code:
insert into comments (comment_id, comment_text) 
 values (123, 'This is a picture of my cat');
insert into images (image_id, image_file, comment_id)
 values (456, 'mycat.jpg', 123);
Of course, this model only allows one comment per object, which may not be want you want.
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote