Last active
July 26, 2022 21:43
-
-
Save dhmacher/875233700ef4743a97adb8b9f977ff80 to your computer and use it in GitHub Desktop.
Move temp/backup objects to Deprecated schema
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
IF (SCHEMA_ID('Deprecated') IS NULL) | |
EXEC('CREATE SCHEMA [Deprecated];'); | |
SELECT 'ALTER SCHEMA [Deprecated] TRANSFER '+QUOTENAME(OBJECT_SCHEMA_NAME([object_id]))+'.'+QUOTENAME(OBJECT_NAME([object_id]))+';' | |
FROM sys.objects | |
WHERE [schema_id] NOT IN (SCHEMA_ID('Deprecated'), SCHEMA_ID('sys')) | |
AND [type] NOT IN ('PK', 'F', 'D', 'UQ') | |
AND ([name] LIKE '%xx%' OR [name] LIKE '%[0-9][0-9][0-9][0-9][0-9][0-9]%' | |
OR [name] LIKE '%[ _]temp' OR [name] LIKE 'temp[ _]%' | |
OR [name] LIKE '%[ _]old' OR [name] LIKE 'old[ _]%' | |
OR [name] LIKE '%backup' OR [name] LIKE 'backup%') | |
ORDER BY OBJECT_SCHEMA_NAME([object_id]), OBJECT_NAME([object_id]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment