Background: I am programming an application that uses Java for DB2 (V9.5 for UNIX) access.
For testing I made this:
CREATE TABLE country(
name VARCHAR(100) NOT NULL,
population BIGINT,
PRIMARY KEY(name)
);
CREATE TABLE city(
name VARCHAR(100) NOT NULL,
country VARCHAR(100) NOT NULL,
PRIMARY KEY(name),
FOREIGN KEY(country) REFERENCES country(name)
);
And here is my problem:
DB2 doesn’t support “ON UPDATE CASCADE” and still referenced primary keys aren’t allowed to change. So how can I change a name of a country while it is still used by a city?
I am not searching a solution that realize this within Java (There I could insert the new value, update affected cities and delete than the old value) There must be a way to do this in DB2. Hopefully.
Thanks for your help.
The problem is in your design. Generally, a primary key is not supposed to change after insertion. What you might want to do is this:
Optionally, you can still make the
namecolumnsUNIQUE