Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dropping Related Tables

Status
Not open for further replies.

SpenBabe

Programmer
Sep 25, 2000
70
GB
I have 3 tables (ACCOUNT, BALANCES & ORDERS) which all have primary keys created by their own trigger/generators.

BALANCES also has a foreign key that references ACCOUNT's primary key.

ORDERS also has a foreign key that references ACCOUNT's primary key.

Everything works fine, but I cannot drop the tables.
In Interactive SQL I type :-

DROP TABLE ORDERS;
DROP TABLE BALANCES;
DROP TABLE ACCOUNT;

but I get an error telling me that table BALANCES is in use ! (It has managed to drop ORDERS) I know it has something to do with the foreign keys, but I cannot seem to drop them either.

Any ideas ?


Thanks in advance



Spencer Window (not a joke name)
spencer.window@eastmidlandcomputers.ltd.uk
 
First you have to drop all constraints like foreign keys
that would be:
alter table balances
drop constraint FK_Lookup_In_Account


After this you can drop the table

It is good practice to give your foreign keys and other constraints a name, other wise you have to search for the name interbase automatically assigned.

Regards
S. van Els
SAvanEls@cq-link.sr
 
I have already tried dropping the foreign keys. When I try:-

ALTER TABLE SALRECON DROP CONSTRAINT FK_SALRECON_TRANID

I get the message :-

Unsuccessful metadata update object INDEX is in use
Statement: ALTER TABLE SALRECON DROP CONSTRAINT FK_SALRECON_TRANID

When I try to drop the index I get the message :-

Unsuccessful metadata update
ERASE RDB$INDICES failed action cancelled by trigger (1) to preserve data integrity
Cannot delete index used by an Integrity Constraint
Statement: drop index RDB$FOREIGN20

Surely this is telling me that I cannot drop the key because it is used by an index & I cannot drop the index because it is used by a key !!!!

This is the metadata for the table in question :-

CREATE TABLE "SALRECON"
(
"RECONID" INTEGER DEFAULT 0 NOT NULL,
"ACCID" INTEGER,
"TRANID" INTEGER,
"ASSOCID" INTEGER,
"ALLOCATED" DOUBLE PRECISION,
"BATCHNO" INTEGER DEFAULT 0,
"YEARNO" SMALLINT,
"PERIODNO" SMALLINT,
"ENTRYDATE" TIMESTAMP,
"USERID" VARCHAR(100),
PRIMARY KEY ("RECONID")
);
ALTER TABLE "SALRECON" ADD CONSTRAINT "FK_SALRECON_ACCID" FOREIGN KEY ("ACCID") REFERENCES SALACCOUNT ("ACCID") ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE "SALRECON" ADD CONSTRAINT "FK_SALRECON_ASSOCID" FOREIGN KEY ("ASSOCID") REFERENCES SALTRAN ("TRANID") ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE "SALRECON" ADD CONSTRAINT "FK_SALRECON_TRANID" FOREIGN KEY ("TRANID") REFERENCES SALTRAN ("TRANID") ON UPDATE CASCADE ON DELETE CASCADE; Spencer Window (not a joke name)
spencer.window@eastmidlandcomputers.ltd.uk
 
Do you have triggers, generators, views or stored procedures working with the SALRECON table?

Anything that is linked to this table will prevent altering of it.

You must drop all constraints!!

Check your procedures and triggers


Regards S. van Els
SAvanEls@cq-link.sr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top