3

I've this table:

CREATE TABLE [SomeTable](
                         [Id] int NOT NULL
                        ,[SomeColumn] varchar(50) NULL
                        ,[ParentId] int NULL CONSTRAINT [PK_SomeTable] PRIMARY KEY CLUSTERED ([Id] ASC)

ALTER TABLE [SomeTable]  WITH CHECK ADD CONSTRAINT 
     [FK_SomeTable_SomeTable] FOREIGN KEY([ParentId])
     REFERENCES [SomeTable] ([Id])

ALTER TABLE [SomeTable] CHECK CONSTRAINT [FK_SomeTable_SomeTable]

Sql Server does not allow me to put ON UPDATE CASCADE.

Is there any way to get that if i update Id column, all child rows ParentId get updated too?

iamdave
  • 12,023
  • 3
  • 24
  • 53
ʞᴉɯ
  • 5,376
  • 7
  • 52
  • 89
  • 4
    I don't think you can workaround that limitation except for writing a trigger that does this for you (using a recursive query) –  Mar 24 '15 at 09:56
  • 4
    Generally speaking, the primary key columns should be immutable. In this particular case, even more. The only way to work around your problem is to remove the FK declaration altogether and implement the RI with code (read: triggers). – dean Mar 24 '15 at 10:03
  • There's somewhat of a related conversation here.. http://stackoverflow.com/questions/1481476/when-to-use-on-update-cascade – sam yi Mar 24 '15 at 12:40

0 Answers0