Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 denormalised constraint [Resolved]
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

lappin
Posting Yak Master

182 Posts

Posted - 09/20/2011 :  05:35:52  Show Profile  Reply with Quote
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 PartTable
PartID, PartName, PartLocation

TableA 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.

Edited by - lappin on 09/21/2011 04:57:03

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 09/20/2011 :  05:38:54  Show Profile  Reply with Quote
why not link them by fk. probably you can create fk with no check to ignore the values that exist currently.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

lappin
Posting Yak Master

182 Posts

Posted - 09/20/2011 :  05:53:20  Show Profile  Reply with Quote
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 PartTable
PartID, PartName, PartLocation
2a, Drill, ShelfA
Go to Top of Page

lappin
Posting Yak Master

182 Posts

Posted - 09/21/2011 :  04:56:31  Show Profile  Reply with Quote
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.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 09/21/2011 :  05:58:53  Show Profile  Reply with Quote
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.47 seconds. Powered By: Snitz Forums 2000