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
 General SQL Server Forums
 New to SQL Server Programming
 On Delete Cascade and On Delete Update

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2011-02-03 : 12:32:03
Hello,

I have the following constraint:

alter table dbo.Devices
add constraint Devices_ModelId_FK foreign key(ModelId) references dbo.Models(Id) on delete cascade on update cascade,

On table devices:

create table dbo.Devices
(
Id int identity not null
constraint Devices_Id_PK primary key clustered (Id),
ModelId int not null,
[Serial] nvarchar (120) not null
constraint Devices_Used_DF default (0)
)

So my interpretation is when a Device is deleted the Model is deleted. So I should change the Delete Cascade to no action. Correct?

And what about update cascade. In my case I will never change the Id of Devices so having update cascade or no action will be the same. Correct?

What is the correct approach for this?

Thank You,
Miguel

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-02-03 : 12:59:35
Whether or not you change the delete cascade to no action is based upon what you want to do when a delete occurs. The cascade option just means you won't have to run delete commands for the respective child rows.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -