I am trying to drop two experimental tables from an HSQLDB server database. But, every attempt has failed, due to auto-generated foreign keys. Short of blowing away the entire database on the file system, I am running out of ideas, and would appreciate any pointers or suggestions that y'all may have.
The tables and indexes were created by JPA. The generated DDL for the tables is:
CREATE TABLE SUDOKU.DIVISION (
DIVISION_ID BIGINT NOT NULL,
DIVISION_NAME VARCHAR(255),
CHIEF_EMPLOYEE_ID BIGINT,
DEPUTYCHIEF_EMPLOYEE_ID BIGINT,
PRIMARY KEY (DIVISION_ID)
);
CREATE TABLE SUDOKU.EMPLOYEE (
EMPLOYEE_ID BIGINT NOT NULL,
DIVISION_ID BIGINT,
EMPLOYEE_NAME VARCHAR(255),
PRIMARY KEY (EMPLOYEE_ID)
);
ALTER TABLE SUDOKU.DIVISION
ADD FOREIGN KEY (CHIEF_EMPLOYEE_ID,DEPUTYCHIEF_EMPLOYEE_ID)
REFERENCES EMPLOYEE (EMPLOYEE_ID,EMPLOYEE_ID);
ALTER TABLE SUDOKU.EMPLOYEE
ADD FOREIGN KEY (DIVISION_ID)
REFERENCES DIVISION (DIVISION_ID);
When I attempt to delete either table, the drop fails with the error message similar to the following ERROR: is referenced by FOREIGN KEY constraint: SUDOKU.FKSPXEERGASS9WA2IXFLHC20IOY in statement [DROP TABLE SUDOKU.DIVISION] Error Code: -5533
So, then I try to delete the 'foreign key' that is referenced, and that
fails with the error message user lacks privilege or object not found
.
I am not able to find either of the foreign keys, that are referenced in the error message, using either RazorSQL, or the JPA view in Eclipse Neon-3.
A strange thing that I noticed was that the foreign key that is referenced in the error message, changes. It seems to depend on which tool I use to connect with.
There is a simple solution:
DROP TABLE SUSOKU.DIVISION CASCADE
Similarly when you want to delete the data from tables that have FK references:
TRUNCATE TABLE SUSOKU.DIVISION AND COMMIT NO CHECK