Subject | Re: [firebird-support] Find all records on all tables that violate constraints? |
---|---|
Author | Kjell Rilbe |
Post date | 2014-02-28T19:51:11Z |
Den 2014-02-28 09:41 skrev Kjell Rilbe såhär:
table scans:
select 'select ''' || trim(RDB$RELATION_NAME) || ''' "Table", count(*)
"Count" from "' || trim(RDB$RELATION_NAME) ||
'" where ' || list('"' || trim(RDB$FIELD_NAME) || '" || '''' is null', '
or ') || ';'
from RDB$RELATION_FIELDS
where RDB$NULL_FLAG = 1
group by trim(RDB$RELATION_NAME);
With over 200 tables I manually grouped them in groups of 25 with union
and an outer select to only return rows with count <> 0.
Thanks for the great starting point!
Kjell
>This is what I ended up with, issuing one select per table to reduce
> Den 2014-02-28 08:42 skrev Svein Erling Tysvær såhär:
> >
> > Reinventing the wheel can sometimes be fun, Kjell. I would expect this
> > statement
> >
> > SELECT list('SELECT ''' || TRIM(RDB$RELATION_NAME) ||'''
> > RELATION_NAME, ''' || TRIM(RDB$FIELD_NAME) ||
> > ''' FIELD_NAME, COUNT(*) FROM ' || TRIM(RDB$RELATION_NAME) ||
> > ' WHERE ' || TRIM(RDB$FIELD_NAME) || '||'''' IS NULL GROUP BY 1, 2 ', '
> > UNION ')
> > FROM RDB$RELATION_FIELDS
> > WHERE RDB$NULL_FLAG = 1
> >
> > to return an SQL statement that you can execute to find which
> > combination of tables and fields contains NULL values (though it will
> > take time since it has to avoid using indexes, at least I don't think
> > you'll find NULLs if you use indexes).
> >
>
table scans:
select 'select ''' || trim(RDB$RELATION_NAME) || ''' "Table", count(*)
"Count" from "' || trim(RDB$RELATION_NAME) ||
'" where ' || list('"' || trim(RDB$FIELD_NAME) || '" || '''' is null', '
or ') || ';'
from RDB$RELATION_FIELDS
where RDB$NULL_FLAG = 1
group by trim(RDB$RELATION_NAME);
With over 200 tables I manually grouped them in groups of 25 with union
and an outer select to only return rows with count <> 0.
Thanks for the great starting point!
Kjell