Self-referencing FK added in ALTER TABLE statement
Appears that in Derby you can't have a self-reference FK in a
CREATE TABLE statement
@@ -32,10 +32,14 @@ CREATE TABLE DATA_PRODUCT
CREATION_TIME TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
LAST_MODIFIED_TIME TIMESTAMP DEFAULT '0000-00-00 00:00:00',
PRODUCT_TYPE VARCHAR(10),
- PRIMARY KEY (PRODUCT_URI),
- FOREIGN KEY (PARENT_PRODUCT_URI) REFERENCES DATA_PRODUCT (PRODUCT_URI) ON DELETE CASCADE
+ PRIMARY KEY (PRODUCT_URI)
+ -- in Derby can't create self-reference FOREIGN KEY in CREATE TABLE
+ -- statement so this gets added via the following ALTER TABLE statement
+ -- FOREIGN KEY (PARENT_PRODUCT_URI) REFERENCES DATA_PRODUCT (PRODUCT_URI) ON DELETE CASCADE
);
+ALTER TABLE DATA_PRODUCT ADD FOREIGN KEY (PARENT_PRODUCT_URI) REFERENCES DATA_PRODUCT (PRODUCT_URI) ON DELETE CASCADE;
+
CREATE TABLE DATA_REPLICA_LOCATION
(
REPLICA_ID VARCHAR (255),
