I need a table table to hold hierarchy tree data (i.e. continents, countries, cities) like this
id name parent
-------------------
1 world null
2 Europe 1
3 Asia 1
4 France 2
5 Paris 4
6 Lyon 4
I want to delete France
and would expect the table to cascade delete all French cities. But when I create the table like this
create table locations
(
id int identity(1, 1),
name varchar(255) not null,
parent_id int,
constraint pk__locations
primary key clustered (id),
constraint fk__locations
foreign key (parent_id)
references locations (id)
on delete cascade
on update no action
)
I got an error
Introducing FOREIGN KEY constraint 'fk__locations' on table 'locations' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Info says
- to specify
ON DELETE NO ACTION
- that is exactly what do not I want - to specify
ON UPDATE NO ACTION
- specified - modify other FOREIGN KEY constraint - I don't understand this one
Can anyone help?