How to create schema dynamically using dynamic SQL

Author

Soheil Bakhshi

Microsoft Data Platform

In this short post I’ll show you how to create database schema using dynamic SQL.

It’s easy, just take a look at the following code:

declare @SchemaName varchar(max)

set @SchemaName = ‘YOUR_SCHEMA_NAME’

if not exists (select 0 from sys.schemas where name=@SchemaName)

exec(‘create schema [‘+@SchemaName+‘]’)

go

 

Enjoy!


Discover more from BI Insight

Subscribe to get the latest posts sent to your email.

About the author

Soheil Bakhshi

Microsoft Data Platform

Leave a Comment

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


The reCAPTCHA verification period has expired. Please reload the page.