Only creating a schema, when it does not exist in a Microsoft SQL Server database.

If you want to create a schema in a Microsoft SQL Server database only when it does not exist, use:

declare @SchemaName nvarchar(128)
set @SchemaName = 'Staging'
if not exists(select top 1 1 from information_schema.schemata where schema_name = @SchemaName)
exec('create schema ' + @SchemaName)

Leave a Reply

Your email address will not be published. Required fields are marked *