By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,067 Members | 1,849 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,067 IT Pros & Developers. It's quick & easy.

Are Primary Keys Necessary for Linking Tables?

P: 1
We have a PostgreSQL database that contains several linking tables (all they contain is two foreign keys to link 2 other tables together). Is it necessary and/or advisable to specify the two attributes in these tables as a joint primary key? There is some disagreement among our team members and I'd like to get some more opinions.

Thanks,
Brandy
Oct 20 '06 #1
Share this Question
Share on Google+
1 Reply


P: 2
cam
Hi,

As you must be aware that primary keys prevent violation of duplicate data. But if you have the two fields a joint primary key and if the data that you are linking it to only gets displayed once then yes why not have a joint primary key instead of foreign keys. This will make it a composite key. Or alternative another way around this will be a have a joint UNIQUE key. so it will look something like this:-

create table test
(
a int,
b int,
constraint primary key (a,b)
);

OR

create table test
(
a int,
b int,
constraint UNIQUE key (a,b)
);

Any project or design has many solutions but every solution has to be the best decision for a company. But thats my point of view on it.

;) have fun!!!!!!

We have a PostgreSQL database that contains several linking tables (all they contain is two foreign keys to link 2 other tables together). Is it necessary and/or advisable to specify the two attributes in these tables as a joint primary key? There is some disagreement among our team members and I'd like to get some more opinions.

Thanks,
Brandy
Nov 23 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.