Link to home
Start Free TrialLog in
Avatar of onebite2
onebite2

asked on

Update Reference/Foreign tables

Database: SQL Server2005.
I have Glossary table with bunch of Foreign Key relationship tables. Glossary table has some invalid data and same exists on the other relation tables.. Now in order to delete those invalid values out of Glossary i need remove them various other tables... so i wrote a update statement for each foreign key table(reference table) but that tidous process.. is there any way i can do this.. other than updating every single foreign key table..
For instance: TableA has foreign key relations with TableB,TableC, TableD..
Fields on TableA: UniqueID,Category,Description (UniqueID is a Primary Key on Table A and Foreign key table on TableB and also Foreign key table on TableC..) So i can't delete a UniqueID on TableA since the value exists on TableB, TableC.. So i want TableB & TableC to update with correct values and delete the invalid value from TableA but i dont want to write too many update queries..
Hope my question is clear! Let me know if you have any questions.
Need to know what's the best way to deal with this issue.

Thanks,
Cindy
Avatar of jogos
jogos
Flag of Belgium image

If it's about 20 tables copy paste is much faster. If you think you will need id again in the future you make a stored procedure out of it.
With a select starting from sysforeignkeys you can speed up your typing.


Avatar of onebite2
onebite2

ASKER

Is there any to get foreign key tables and the fields using sql statement, Let me know
I had to spend more time on this but I wrote the sql.. I think its worth spending time on the sql instead of manually writing update statement. I get to know lots of new things.. informative.. but thanks for the help.


ASKER CERTIFIED SOLUTION
Avatar of jogos
jogos
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Force accepted.
Vee_Mod
Community Support Moderator