Apologies in advance, cause I'm probably asking a bit much
The challenge:
writing a scan an repair procedure (in one or more steps) which should:
1. Scan a database (DWH-type) for FK's of the nullable kind
2. Process this information to perform succesive updates to a certain default for the null values encountered.
for simplicities sake, I'll assume that the default already exists as a PK in the referenced table.
(Nice additional step)
Complications may be the fact that a table can have multiple FK's and that an FK may consist of more than 1 field.
So far I came up with scan scripts like:
and:
Unfortunately, I am not very experienced with writing PL/SQL procedures to tackle this one.
Can imagine that someone , somewhere has had the same challenge.
Any input is highly appreciated...
Ties Blom
The challenge:
writing a scan an repair procedure (in one or more steps) which should:
1. Scan a database (DWH-type) for FK's of the nullable kind
2. Process this information to perform succesive updates to a certain default for the null values encountered.
for simplicities sake, I'll assume that the default already exists as a PK in the referenced table.
(Nice additional step)
Complications may be the fact that a table can have multiple FK's and that an FK may consist of more than 1 field.
So far I came up with scan scripts like:
Code:
-- nullable FK and index --
select
T.CONSTRAINT_NAME,
T.TABLE_NAME,
S.COLUMN_NAME,
S.POSITION,
V.NULLABLE,
V.DATA_DEFAULT,
V.DATA_TYPE,V.DATA_LENGTH,V.DATA_PRECISION,
(CASE WHEN X.INDEX_NAME IS NOT NULL THEN 'INDEXED' ELSE 'NOT INDEXED' END) AS IDX_IND from
sys.all_constraints T,
SYS.all_CONS_COLUMNS S,
SYS.all_TAB_COLUMNS V,
SYS.all_IND_COLUMNS X
where
T.OWNER = S.OWNER AND T.TABLE_NAME = S.TABLE_NAME AND T.CONSTRAINT_NAME = S.CONSTRAINT_NAME AND
S.OWNER = V.OWNER AND S.TABLE_NAME = V.TABLE_NAME AND S.COLUMN_NAME = V.COLUMN_NAME AND
S.OWNER = X.TABLE_OWNER(+) AND S.TABLE_NAME = X.TABLE_NAME(+) AND S.COLUMN_NAME = X.COLUMN_NAME(+) AND
t.constraint_type = 'R'
and T.status = 'ENABLED'
AND T.TABLE_NAME LIKE 'TB_%'
AND V.NULLABLE = 'Y'
AND T.OWNER = [COLOR=red]<user>[/color]
order by 2,1,3,4
and:
Code:
-- tables without FK ,but potential candidate for dummy PK
SELECT T.TABLE_NAME,S.CONSTRAINT_NAME,
FROM SYS.ALL_TABLES T,SYS.all_CONS_COLUMNS S,SYS.ALL_CONSTRAINTS X
WHERE T.OWNER = S.OWNER AND T.TABLE_NAME = S.TABLE_NAME AND
T.OWNER = X.OWNER AND T.TABLE_NAME = X.TABLE_NAME AND
T.OWNER = [COLOR=red]<USER>[/color] AND T.TABLE_NAME LIKE 'TB%' AND X.CONSTRAINT_TYPE = 'P' AND
S.CONSTRAINT_NAME NOT LIKE 'SYS%' AND X.STATUS = 'ENABLED' AND
T.TABLE_NAME NOT IN
(SELECT V.TABLE_NAME FROM SYS.ALL_CONSTRAINTS V WHERE V.OWNER = [COLOR=red]<USER>[/color] AND V.CONSTRAINT_TYPE = 'R')
Unfortunately, I am not very experienced with writing PL/SQL procedures to tackle this one.
Can imagine that someone , somewhere has had the same challenge.
Any input is highly appreciated...
Ties Blom