I came across a situation in couple of the enterprise application projects, where I found a strange fact in the MS SQL Server Database they used.
I found multiple foreign-key(FK) relationships existing between tables. When examining the table design, I found that same relationship existed thrice with 3 different FK constraint names.
There are tables with single primary-key(PK) and few others with composite-PKs. As there are tables linked through relationships, will it matter that tables with composite-PKs will involve redundant FK relations with other tables?
I am puzzled as how redundant FK relationships could have got created. Is this purely human error or anythign with respect to MS SQL Server?
Please explain the probable cause for this scenario.
Thanks,
Ganesh
MS SQL does not create anything automatically. If FKs are there, it is because some human or a code generator created it.You didn't say what version you were using, but there were weird problems, which were fixed early in 2000, with the "Diagrams" feature which might have done stuff like that, but I don't know anyone who uses the diagramming in MS SQL so I would be surprised if that was the cause.
|||
Hi Tom,
Thanks for the reply.
I use MS SQL Server 2000 version.
The other project used previous version of MS SQL Server.
In both these projects, the data base design was migrated from another source. I doubt this migration of design is the main cause. But still, the same question remains for the 1st database from where the design was migrated: "Does the initial database source had this duplication because of humar error or something else"?
NOTE: The diagram tool in MS SQL Server is perfect in this aspect, as I checked the design of tables from Query Analyzer - where there were duplicate FK replationships (different constraint-names) for the same column mapping. No database programmer intentionally creates multiple FK constraints on same column mapping. Then, what behind this?
Please check the database of your projects and come back if you too find the same. Also think of the cause for this.
|||There is nothing restricting the use of multiple FKs on the same fields to the same tables, with different constraint names. Yes, it is redundant and will hurt performance and should not be done.Still, either some human did this, accidentally or for some unknown purpose, or a code generator did it. Most likely a code generator created them.
In any case, they should be removed.
|||Thanks Phillips.
No comments:
Post a Comment