Hi all,
I have few doubts which I want to clear regarding referential constraints.
Lets say I have three tables
a) Users
b) Gallery
c) Images
a) Users has following columns:
usr_id int
first_name nchar(30)
last_name nchar(30)
email_id nchar(45)
password nchar(25)
gender char(1)
dob date
In Users table I have set usr_id as the primary key.
b) Gallery has following columns:
gallery_id int
user_id int
gallery_name nchar(50)
gallery_description nchar(250)
date_created datetime
In Gallery table I have set gallery_id as the primary key.
c) Images table has following columns:
img_id int
gallery_id int
img_path nvarchar(200)
img_caption nvarchar(250)
in Images table I have set img_id as the primary key.
now my doubt is I want to link these tables using foreign key.
Users -> Gallery -> Images
which is the best column in gallery to be a foreign key to the Users table.
In Users table usr_id is my primary key and in gallery it is gallery_id.
So should I link usr_id of user table with the usr_id in Gallery table ?? i m little confused… because by default shouldn’t it be the primary key that gets linked ??
thanks
…:: peace ::…
Jeba