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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Change key value

Author  Topic 

vmon
Yak Posting Veteran

63 Posts

Posted - 2006-11-06 : 13:24:58
I have a database that has an item master (tblItem) table and a values table (tblValue) that is related but not with a relationship. An tblItem record can exist without a tblValue record. tblValue records are added after the item exists. I want to change the key (ItemId) of tblItem and have the key in tblValue update (cascade) the change to the ItemId. I don't think I can put a relationship in because the tblValue table will not have records so I cant "enforce" the relationship. Is there a way to change the key in tblItem and have that change update tblValue?

thanks,
vmon

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-06 : 13:47:10
Why would you? Are the numbers for ItemID running out?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

vmon
Yak Posting Veteran

63 Posts

Posted - 2006-11-06 : 14:16:21
The way this system was set up the user can change the ItemId and it handles changing all of the related tables even though there are no relationships defined. I have inherited this system and the tblValue table was added but not included in the udpate when an ItemId is changed. I am not real sure how to do this. Can I just run an update statement against a key value?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-06 : 15:32:59
In that case, a trigger might help. Make use of the INSERTED and DELETED help tables.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -