Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
lappin
Posting Yak Master
182 Posts |
Posted - 2011-09-20 : 05:35:52
|
Hi, I have a legacy table which has some denormalised columns showing data which is also stored in other tables. Here is a simple example tableA (with denormalised columns)ID, PartID, PartName, ...........and PartTablePartID, PartName, PartLocationTableA contains PartName - which it should not really have - but it is used in a lot of legacy code so I don't want to delete it yet. In meantime I'd like to use a constraint or change to a computed column so PartName in tableA checks /references the PartTable.Any suggestions other than create a VIEW and modify all the legacy applications - which is my longer-term goal. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-20 : 05:38:54
|
why not link them by fk. probably you can create fk with no check to ignore the values that exist currently.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
lappin
Posting Yak Master
182 Posts |
Posted - 2011-09-20 : 05:53:20
|
Would the FK not just check that the PartID is a valid ID? I need to check that the PartName is correct. E.g. stop this happening- ID, PartID, PartName, ...........1 2a Hammer,........and PartTablePartID, PartName, PartLocation2a, Drill, ShelfA |
|
|
lappin
Posting Yak Master
182 Posts |
Posted - 2011-09-21 : 04:56:31
|
Resolved using visakh's suggestion of FK but used the pair of columns as key. Had to create a unique constraint on the paired columns to do this. Thanks for help. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-21 : 05:58:53
|
wc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|
|
|