|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Monday, June 04, 2012 5:00 PM
Points: 891,
Visits: 225
|
|
Hi, I was trying to reply the Posts by David McKinney and chrs-513176 in the same thread.
Where he is talking about rare scenario of having mutiple foreign keys between Table1 and Table2.
For Example- Table1 Column1 int not null Primary key Column2 int not null Unique Key
Table2 Column1 int references table1.column1 Column2 int references table1.column1
Here we can not go with the naming the foreign key like FK_Table2_Table1, becauase there are two keys. Name duplication will become the issue
Here we can follow names like FK1_Table2_Table1 FK2_Table2_Table1
As a second option we can add column name(s) along with FK_Table2_Table1, but key name may become lengthy if the keys are composite.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Wednesday, April 18, 2012 9:31 AM
Points: 7,
Visits: 26
|
|
This is an interesting topic, which needs further discussion. As an example I have several tables that have duplicated foreign keys to the same relationship. When resolving system generated foreign keys into something more developer/support friendly, there are two options.
1. FK_ForeignTableName_ForeignColumnName(s)_PrimaryTableName_PrimaryColumnName(s) (SQL-92, so some degree) Or in the parent child order of: 2. FK_PrimaryTableName_PrimaryColumnName(s) _ForeignTableName_ForeignColumnName(s)
The standard doesn't seem to be well established for SQL Server if you want to name your own foreign keys, so from my perspective, this must be decided within the organization or enterprise. I have never liked the system generated method and the number one method above is more to SQL-92 standards. I personally like the second option, for it has a natural flow.
The problem I have had is the renaming of the system established foreign keys is best resolved using 4-points names Option 1 or 2 above. Failure to use something that has just three qualifiers will result in duplicate names for foreign keys and thus be un-usable.
I welcome any return comments.
|
|
|
|