Created
November 23, 2022 07:26
-
-
Save QuadmanSWE/f66cd1d11b997f1e120f0bf9cff52a74 to your computer and use it in GitHub Desktop.
remove all user objects from master
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
USE MASTER | |
GO | |
SET NOCOUNT ON | |
GO | |
SELECT N'ALTER TABLE [' + schema_name([schema_id]) + N'].[' + object_name(parent_object_id) + N'] DROP ' + [name] command from sys.objects where [type] = 'F' AND is_ms_shipped <> 1 | |
UNION ALL | |
SELECT 'GO' command | |
UNION ALL | |
SELECT N'DROP PROCEDURE [' + schema_name([schema_id]) + N'].[' + [name] + N']' command from sys.objects where [type] = 'P' AND is_ms_shipped <> 1 | |
UNION ALL | |
SELECT 'GO' command | |
UNION ALL | |
SELECT N'DROP TABLE [' + schema_name([schema_id]) + N'].[' + [name] + N'] ' command from sys.objects where [type] = 'U' AND is_ms_shipped <> 1 | |
UNION ALL | |
SELECT 'GO' command | |
UNION ALL | |
SELECT N'DROP VIEW [' + schema_name([schema_id]) + N'].[' + [name] + N'] ' command from sys.objects where [type] = 'V' AND is_ms_shipped <> 1 | |
UNION ALL | |
SELECT 'GO' command | |
UNION ALL | |
SELECT N'DROP FUNCTION [' + schema_name([schema_id]) + N'].[' + [name] + N'] ' command from sys.objects where [type] = 'FN' AND is_ms_shipped <> 1 | |
UNION ALL | |
SELECT 'GO' command | |
UNION ALL | |
SELECT N'DROP FUNCTION [' + schema_name([schema_id]) + N'].[' + [name] + N'] ' command from sys.objects where [type] = 'TF' AND is_ms_shipped <> 1 | |
-- You can verify the counts before and after using below query. | |
SELECT count(1) | |
FROM master.sys.objects | |
WHERE is_ms_shipped <> 1 AND TYPE IN ('U','P','FN','V','TF') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment