Skip to content

Instantly share code, notes, and snippets.

@woganmay
Last active September 17, 2015 16:19
Show Gist options
  • Save woganmay/d1e83f82e871bde2568e to your computer and use it in GitHub Desktop.
Save woganmay/d1e83f82e871bde2568e to your computer and use it in GitHub Desktop.
/** MS SQL */
SELECT
t.NAME AS TableName,
p.[Rows] AS NumRows
FROM
sys.tables t
INNER JOIN
sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN
sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN
sys.allocation_units a ON p.partition_id = a.container_id
WHERE
t.NAME NOT LIKE 'dt%' AND
i.OBJECT_ID > 255 AND
i.index_id <= 1
GROUP BY
t.NAME, i.object_id, i.index_id, i.name, p.[Rows]
ORDER BY
object_name(i.object_id)
/* Firebird */
set term !! ;
EXECUTE BLOCK
returns ( stm varchar(60), cnt integer )
as
BEGIN
for select cast('select count(*) from "'||trim(r.RDB$RELATION_NAME)||'"' as varchar(60))
from RDB$RELATIONS r
where (r.RDB$SYSTEM_FLAG is null or r.RDB$SYSTEM_FLAG = 0) and r.RDB$VIEW_BLR is null
order by 1
into :stm
DO
BEGIN
execute statement :stm into :cnt;
suspend;
END
END
/** Older Firebird */
select 'select '''||trim(r.RDB$RELATION_NAME)||''', count(*) from "'||trim(r.RDB$RELATION_NAME)||'" union '
from RDB$RELATIONS r
where (r.RDB$SYSTEM_FLAG is null or r.RDB$SYSTEM_FLAG = 0)
and r.RDB$VIEW_BLR is null
order by 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment