Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a new schema to sql server 2008?

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

like image 778
chobo Avatar asked Mar 14 '11 19:03

chobo


People also ask

How do I add a schema to a SQL Server database?

Right-click the Security folder, point to New, and select Schema. In the Schema - New dialog box, on the General page, enter a name for the new schema in the Schema name box. In the Schema owner box, enter the name of a database user or role to own the schema.

How do I import a schema in SQL?

To import schema from the export script, use the Schema Import Wizard. To call the Schema Import Wizard and import the schema from the export script: On the Database menu, point to Export & Import, and then click Schema Import. Select an export script file to import and a target schema.

What is create schema in SQL?

Creates a schema in the current database. The CREATE SCHEMA transaction can also create tables and views within the new schema, and set GRANT, DENY, or REVOKE permissions on those objects. Transact-SQL Syntax Conventions.

Why do we create schemas in SQL Server?

A SQL schema is a useful database concept. It helps us to create a logical grouping of objects such as tables, stored procedures, and functions.


2 Answers

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

like image 69
Joe Stefanelli Avatar answered Sep 25 '22 07:09

Joe Stefanelli


Here's a trick to easily check if the schema already exists, and then create it, in it's own batch, to avoid the error message of trying to create a schema when it's not the only command in a batch.

IF NOT EXISTS (SELECT schema_name      FROM information_schema.schemata      WHERE schema_name = 'newSchemaName' ) BEGIN     EXEC sp_executesql N'CREATE SCHEMA NewSchemaName;'; END 
like image 23
Mark Avatar answered Sep 23 '22 07:09

Mark