Find All DB objects that belong to specific schema
/* Find All DB objects that belong to specific schema */
CREATE PROCEDURE [dbo].[usp_utl_GetAllSchemaSpecificMetadata]
(
@NewSchemaName VARCHAR(200)
, @OldSchemaName VARCHAR(200)
)
AS
/*
Author: Mihir Shah
Modified Date: 03/07/2018
Purpose: To determine and transfer database objects from NDISBillCalc schema to relevant processing schemas
Example:
Execute [dbo].[usp_utl_GetAllSchemaspecificDBObjects]
@NewSchemaName = 'NewSchemaName' , @OldSchemaName = 'stg'
Output Example:
--ALTER SCHEMA tmp TRANSFER [UHC\mshah1].[Table1];
--ALTER SCHEMA tmp TRANSFER [UHC\mshah1].[Table2];
*/
SELECT 'ALTER SCHEMA ' + @NewSchemaName + ' TRANSFER [' + SysSchemas.name + '].[' + DbObjects.name + '];'
FROM sys.objects DbObjects
INNER JOIN sys.schemas SysSchemas ON DbObjects.schema_id = SysSchemas.schema_id
WHERE SysSchemas.name = @OldSchemaName;
--AND (DbObjects.Type IN ('U', 'P', 'V'))
GO
Comments
Post a Comment