| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> c.d.o.server -> Re: script to dynmically create all foreign key constraints
Steve wrote:
> hey there,
> anyone have a script handy that generates sql to create all the
> foreign key's in the database? Our client does not like ON DELETE
> CASCADE to be left on. However, once in a while we need to use that
> functionlity so I as going to drop the FK's in restricted session,
> recreate them with ON DELETE CASCADE, perform the operation what
> requires DELETE CASCADE, and then drop and recreate the FK's without
> ON DELETE CASCADE. I know this sounds kind of hokey but the ON DELETE
> CASCADE functionality is only ever required once every odd month so. I
> know I can get the constraints from import export but I'd like a
> dynaminc sql that I can just edit one and run.
The following lists all the PK/FK constraints. You can probably modify
the routine to generate the ALTER TABLE commands:
set echo off feedback off pause off pagesize 0 set serveroutput on size 100000
DECLARE
--
cursor c_user_tables is
select table_name
from user_tables
order by table_name;
select table_name,
constraint_type,
constraint_name,
r_constraint_name,
decode ( delete_rule,
'CASCADE', '-YES-',
'No'
) decode_delete_rule,
status
from user_constraints
where constraint_type in ('P', 'R')
and table_name = vin_table_name
order by table_name, constraint_type, constraint_name;
--
select constraint_name,
column_name
from user_cons_columns
where constraint_name = vin_constraint_name
order by position;
set serveroutput off
set feedback on pagesize 24
Received on Wed Dec 11 2002 - 12:14:51 CST
![]() |
![]() |