tags:

views:

53

answers:

3

can i consider 3 columns of a single table together as a composite primary key.... & wat if i want to refer just 1 column out of that in some other table as a foreign key....is it possible....plzzz reply as soon as possible...thank u..

+1  A: 

yes you can put 3 columns as primary key, also you can put one of them as foreign key.

Wael Dalloul
A: 

Yes, on both accounts. 3 columns can be used as a composite key and 1 of those could be used as a foreign key.

Taylor Leese
You've got to be able to take into account the fact that the columns you are using might not be unique.
Mauro
I was assuming the combination of the 3 columns would be unique since he wants to use it as a primary key. Otherwise, the question doesn't really make sense.
Taylor Leese
A: 

Foreign keys must reference a set of columns over which a unique constraint is defined (SQL 2008 standard 11.8: Syntax Rules: 3.a). A single attribute of a composite primary key does not necessarily have a unique constraint defined.

If the single attribute does have a unique constraint defined, that most likely indicates bad design -- the primary key's unique constraint would be redundant.

With that in mind, I would say that "no" is the correct answer to your question, although I suppose technically it may be possible in some situations that I doubt apply in your case.

Jeff Davis