Truncate tables with Cache

Asked

Viewed 148 times

2

I have a hotel table and reserve table.

In the reserve table I have the primary key of the hotel table as foreign key.

I can’t truncate because there are relationships between keys. How can I?

I’ve already done:

truncate table hospede on delete cascade;

But I can’t.

Just remembering that the fk are with on delete cascade. And that use version 11g express Edition.

1 answer

2

The on delete cascade should only be used in some instructions DDL (data Definition language), and not in instructions DML (data Manipulation language). That is, it is to use only where there is change in the structure of the tables, and not in the data. But in your case, you just want to erase the data without changing the structure of the tables.

So here’s what I’d do:

TRUNCATE TABLE hospede;
TRUNCATE TABLE reserva;
TRUNCATE TABLE hotel;

The order of the instructions is important.

  • If this doesn’t work, edit the question by providing column names and how relationships are defined.

  • I didn’t test why I deleted the constraints and truncated the table. If there was a way to force the truncate without so much lap, it would be ideal.

  • Constraints exist to ensure the integrity of tables, not using them you can do what you want but with risk. Apart from this it is often a simple matter of order in which the trucates or Deletes are made as said @Victor Stafusa.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.