Delete a record from a database in Oracle

0

Sorry if the question is silly; but I am new in database and I would like to know if you can support me, please. My doubt is that I have a database in Oracle called ( Company ) with non-relational tables, in them I manage folios of people and I have different tables such as: datos_generales , occupation , health , studios , etc. Every time they ask me to delete a record, I do it like this:

DELETE FROM ocupacion WHERE folio=542;

But, I would like to know if it is possible to delete the record of all the tables in the database in a single query? In total I have 40 tables.

    
asked by AnnieT 20.09.2018 в 20:48
source

2 answers

1

It all depends on how you have created your database or your entity model relationship, I explain: If this is related or you have constraints the question becomes more civilized.

If you were created the constraints like this:

alter table sample1 
   add foreign key (col1) 
references 
   sample (col2)
on delete cascade;

If you do not have it related, the process you have to do manually. I recommend you to do a procedure and put all the tables there that you want to erase in this way when executing the procedure you delete everything in a single stroke (as it is said colloquially in my country) this can be a simple example:

create or replace procedure borrado_folio (p_folio IN varchar2)
is
Begin
delete from empresa.datos_generales where folio=p_folio;
delete from empresa.ocupacion where folio=p_folio;
delete from empresa.estudioswhere folio=p_folio;
//todas los datos de las tablas que vayas a borrar
end;
/

This way I think, in my opinion, I repeat to you if you do not have it related, it would be the best way in my opinion and you take that from the borradera.

    
answered by 21.09.2018 / 23:12
source
0

You could with a delete inner join like this:

DELETE FROM tabla1
INNER JOIN tabla2 ON tabla1.id= tabla2.id
INNER JOIN tabla3 ON tabla1.id= tabla3.id
.
.
.
WHERE tabla1.id = 1;

Then if you have more tables you just have to add them as other inner join

    
answered by 20.09.2018 в 20:57