Created
October 8, 2020 13:50
-
-
Save GregoryWiltshire/257186c02fc0ce51f95606cfb128541a to your computer and use it in GitHub Desktop.
Snowflake User Table Creation History
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// anything older than 20 days ago | |
SET cutoff = current_date() - 20; | |
SELECT h.query_text, | |
h.database_name, | |
h.user_name, | |
h.role_name, | |
t.table_name, | |
u.login_name | |
FROM snowflake.account_usage.query_history h | |
LEFT JOIN snowflake.account_usage.users u | |
ON u.name = h.user_name | |
AND u.disabled = FALSE | |
AND u.deleted_on IS NULL | |
JOIN user_stage.information_schema.tables t | |
ON t.created = h.start_time | |
WHERE execution_status = 'SUCCESS' | |
AND start_time < $cutoff | |
AND query_type LIKE '%CREATE_TABLE%' | |
AND CONTAINS(UPPER(h.query_text), UPPER(t.table_name)) | |
AND t.created < $cutoff; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment