Reputation: 6395
I need to create an additional schema with some database objects in it within a Visual Studio 2013 Database Project. How can I do this?
Upvotes: 4
Views: 6452
Reputation: 994
To add a new Schema into a database project in Visual Studio, you need to follow below steps.
-->
New Item-->
SQL Server -->
Security)This will now create a new file with a CREATE SCHEMA
T-SQL statement in it.
If you want to create a table belonging to this new schema, and follow the recommended folder structure, do the following:
myschema
(where 'myschema' is whatever you called your schema)Tables
(and/or Views
, Stored Procedures
etc) under that folder-->
Tablemyschema.MyNewTable.sql
.This will create a file in the proper folder structure and in the proper schema. If the schema is misspelled or non-existing, you'll get an error telling you so.
This approach works in newer versions of Visual Studio:
*.sql
file containing a table definition-->
Move to schemaUpvotes: 6
Reputation: 21224
Add a new item to your project of type Schema (listed under SQL Server > Security).
For the objects that belong to this schema, add them as you normally would to your project. However they will default to the dbo schema so you will have to change that in each object's script (for example, CREATE TABLE dbo.Table1
becomes CREATE TABLE Schema1.Table1
)
Upvotes: 10