SQL One Liners: Difference between revisions

From bibbleWiki
Jump to navigation Jump to search
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 (..."
 
Line 13: Line 13:
);
);
</syntaxhighlight>
</syntaxhighlight>
==Convert date from known format==
<syntaxhighlight lang="sql">
select to_date('3/4/2013', 'dd/mm/yyyy');
</syntaxhighlight>
=MS SQL=
=MS SQL=
==List row count for tables in a schema==
==List row count for tables in a schema==

Revision as of 21:08, 20 July 2021

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'
    )
);

Convert date from known format

select to_date('3/4/2013', 'dd/mm/yyyy');

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