database - Mysql on delete set default -


i have 2 tables in database following schema:

locations ( location_id int primary key, location varchar ) 

and

venues ( venue_id int primary key, venue varchar, venue_location int foreign key locations(location_id) on delete cascade ) 

a big problem arouse when need delete location not venue. how can delete location not venue same location_id. should achieve requirement.

example data:

/*locations table , data*/ locations(1, "kathmandu"); locations(2, "ilam"); locations(3, "fikkal");  /*venues table , data*/ venues(1, "green view hotel , lodge", 2); venues(2, "hyatt hotel , lodge", 1); venues(3, "abc hotel", 3); 

how can remove location "fikkal" locations without affecting venues "abc hotel". know on delete cascade removing row venues while remove locations of same id. if removed on delete cascade mysql says fk constraint fails , obvious also. how tackle problem this.

what thinking solution create default location in locations table below :

locations(0, "default location");

and perform on delete set default don't know how.

but think there professional , standard way handle problem. idea please.

thank you

you can allow null venue_location , on delete set null. there can other solutions well. seems simplest in case.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -