Sql-server – SQL Server – Create Additional Database File for New Schema

sql servert-sql

I'm trying to create a change script for some upcoming changes. We're adding a new schema to the database and our client wants the new schema to make use of a new database file.

How do I, in T-SQL, create the new file and assign the new objects within the schema to use the new file?

We're using SQL Sever 2012.

Best Answer

You can create a new filegroup, make it DEFUALT, create all schema objects and switch DEFAULT filegroup back. If at any later point you would need to add objects to that schema, you can explicitly specify filegroup through ON filegroup clause for each object in create statement or temporarily switch DEFUALT filegroup.

Alternatively you can explicitly specify ON filegroup for each object of this client's schema.