Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

alter a constraint to add Delete Cascade

Status
Not open for further replies.

rewdee

Programmer
Aug 17, 2001
295
US
I have a foreign key constraint on a table that references another. I want to add Delete Cascade & Update Cascade. How do I do that? Do I drop the constraint and add a new one with ON DELETE Cascade or is there some way to alter table alter column blah blah?

Thanks,
Rewdee
 
Any suggestions on this one. I can't even get the adding and deleting constraint idea going.

I've tried:
Code:
ALTER TABLE [dbo].[Table1] 
        DROP CONSTRAINT [FK_Table1_Table2] 
        Constraint [FK_Table1_Table2] FOREIGN KEY     
	(
		[ID]
	) REFERENCES [dbo].[Table2] (
		[ID]
	) ON DELETE CASCADE  ON UPDATE CASCADE 
GO
I'm desperate on this one. Any help would be appreciated.

Thanks,
Rewdee
 
Try simply:
Code:
ALTER TABLE [dbo].[Table1] 
        DROP CONSTRAINT [FK_Table1_Table2]
 
Thanks, vongrunt for your reply.

It wasn't exactly what I needed because I wanted to modify the constraint but I did get it as:
Code:
ALTER TABLE [dbo].[Table1] 
        DROP CONSTRAINT [FK_Table1_Table2] 
        
GO

ALTER TABLE [dbo].[Table1] 
ADD Constraint [FK_Table1_Table2] FOREIGN KEY     
	(
		[ID]
	) REFERENCES [dbo].[Table2] (
		[ID]
	) ON DELETE CASCADE  ON UPDATE CASCADE

It ain't pretty but it works.

Thanks,
Rewdee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top