Back to Utils

Snowflake · View

system_role_usage

All statements executed under ACCOUNTADMIN, SYSADMIN or SECURITYADMIN, including failed attempts. Useful for audits and detecting unexpected use of admin roles.

Source: SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY · Latency: ~45min

ColumnDescription
dateDate
user_nameUser
role_nameSystem role used
query_typee.g. SELECT, ALTER, GRANT
execution_statusSUCCESS, FAIL or INCIDENT
statementFull query text

Source code

create_admin_views.sql
create or replace view system_role_usage
    comment = 'Statements executed under ACCOUNTADMIN, SYSADMIN or SECURITYADMIN, including failed attempts (source: SNOWFLAKE.ACCOUNT_USAGE)'
as
select start_time::date as date
     , user_name
     , role_name
     , query_type
     , execution_status
     , query_text as statement
  from snowflake.account_usage.query_history
 where upper(role_name) in ('ACCOUNTADMIN', 'SYSADMIN', 'SECURITYADMIN')
 order by start_time desc;