views:

219

answers:

1

I have a table with (col1,col2) as a composite primary key. create table twokeytable(col1 int,col2 int,constraint twokeytable_pk primary key (col1,col2));

and another table with col3,col4 collumns witha composite foreign key(col3,col4) which references the(col1,col2) primary key.

For some processing I need to drop the foreign key and primary constraints .While restoring the constraints does order of the keys matter?.

are these same?

create table fktwokeytable(col3 int,col4 int,constraint fkaddfaa_fk foreign key(col4,col3) references twokeytable(col1,col2))

and

create table fktwokeytable(col3 int,col4 int,constraint fkaddfaa_fk foreign key(col3,col4) references twokeytable(col1,col2))

A: 

This should quite simple to test if they are the same, as if they are different surely you will fail to add the constraint back onto the table. So it should be testable on a small data set.

If it has any performance impact is a different question.

Also what database do you have in mind, as different SQL's do thing differently.

Simeon Pilgrim
Thank you for the reply.Testing aside, is there any database rule that states that order does matter?.I have to write code for all major database systems.
not sure, I was writing a generic response, asking more than answering.
Simeon Pilgrim
If you need for ALL database systems don't use that syntax. Most do not support compound keys in that fashion for FK validation. General Purpose = Least Common Denominator
Jason Short