How to add a new schema in SQL Server 2008?

How do you add a new schema to the database? I am creating a new table and want to select my own schema from the list of properties, but I do not know how to create it. I am using SQL Server Management 2008.

+51
sql-server sql-server-2008
Mar 14 '11 at 19:01
source share
6 answers

Use the CREATE SCHEMA syntax or, in SSMS, expand through Databases → YourDatabaseName → Security → Schemas. Right-click the Schemas folder and select "New Schema ..."

+77
Mar 14 '11 at 19:03
source share

Here's a trick to easily check if a circuit exists, and then create it in your own batch to avoid error messages when trying to create a circuit when it is not the only command in the package.

IF NOT EXISTS (SELECT schema_name FROM information_schema.schemata WHERE schema_name = 'newSchemaName' ) BEGIN EXEC sp_executesql N'CREATE SCHEMA NewSchemaName;'; END 
+31
Apr 10 '14 at
source share

The best way to add a scheme to an existing table: right-click on a specific table → Design → Under the guidance of the Right sight studio, open the Properties window and select a scheme and click it, see the drop-down list and select your scheme. After changing the scheme will save it. Then he will see that he will change your scheme.

+8
Oct 11
source share

I am using something like this:

 if schema_id('newSchema') is null exec('create schema newSchema'); 

The advantage is that if you have this code in a long sql-script, you can always execute it with another code and its short one.

+8
Nov 24 '14 at 7:58
source share

You can try the following:

 use database go declare @temp as int select @temp = count(1) from sys.schemas where name = 'newSchema' if @temp = 0 begin exec ('create SCHEMA temporal') print 'The schema newSchema was created in database' end else print 'The schema newSchema already exists in database' go 
+7
Mar 13 '13 at 21:30
source share

In SQL Server 2016 SSMS, expand 'DATABASNAME'> expand 'SECURITY'> expand 'SCHEMA'; right-click "SCHEMAS" from the pop-up window, click "NEW SCHEMAS ...", add a name in the window that opens and add the owner ie dbo click "OK"

+1
Aug 10 '17 at 15:29
source share



All Articles