SQL One Liners

From bibbleWiki
Revision as of 21:05, 20 July 2021 by Iwiseman (talk | contribs) (Created page with "=Snowflake= ==List row count for views in a schema== This creates a command you subsequently execute <syntaxhighlight lang="sql"> select listagg(xx, ' union all ') from (...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Snowflake

List row count for views in a schema

This creates a command you subsequently execute

select listagg(xx, ' union all ')
from (
    select 'select count(*) c, \'' || x || '\' v from ' || x as xx
    from (
        select TABLE_CATALOG ||'.'|| TABLE_SCHEMA ||'."'||TABLE_NAME||'"' x
        from IHC.INFORMATION_SCHEMA.VIEWS
        where table_schema='APPROVALPLUS'
    )
);

MS SQL

List row count for tables in a schema

SELECT o.NAME,
  i.rowcnt
FROM sysindexes AS i
  INNER JOIN sysobjects AS o ON i.id = o.id
WHERE i.indid < 2  AND OBJECTPROPERTY(o.id, 'IsMSShipped') = 0
ORDER BY o.NAME