How to: Add Files and Filegroups

Every database has a default filegroup with at least one file defined on it. You can define additional filegroups and files for a database project. After you have defined a filegroup, you can create objects on that filegroup or modify existing objects so that they reside on that filegroup. You configure filegroups and their associated files as part of the properties for a database project.

If you delete a filegroup from a database project, you can deploy that change to a new database, but the change is ignored if you deploy to an existing database. For more information about deleting filegroups, files, and log files, see Overview of Files and Filegroups.

To add a filegroup

  1. In Solution Explorer, click the database project to which you want to add a filegroup.

  2. On the Project menu, click ProjectName Properties.

    The Properties window appears.

  3. Click the Filegroups tab.

  4. In the list of filegroups, right-click the Filegroups node, and click Add New Filegroup.

    The filegroup is added to the database project, a new entry appears in the list of filegroups, and a warning appears in the Error List window. This error appears because you must add at least one file to the filegroup before you can use it. You can modify the name of the new filegroup.

  5. On the File menu, click Save All.

    When you build and deploy the database project, any new files and filegroups are created in the database that you are updating.

To add a file to a filegroup or to add a log file

  1. In Solution Explorer, click the database project that contains the filegroup to which you want to add a file.

  2. On the Project menu, click ProjectName Properties.

    The Properties window appears.

  3. Click the Filegroups tab.

  4. Take one of the following actions:

    1. To add a file to a filegroup, right-click the filegroup to which you want to add a file, and click Add New File.

    2. To add a log file, right-click the Log Files node, and click Add New File.

    A new entry appears in the list of filegroups, with the default name FileName.

  5. Type the logical name of the new file.

  6. In the details pane, in Physical file path and name, type the path and name of the file that you are adding.

    Note

    You can use an MSBuild variable for the path by clicking Edit and then clicking a variable in the list. For example, you could specify $(DefaultDataPath)$(TargetDatabase).mdf, which is the default value for the file in the PRIMARY filegroup. You can then override the value of an MSBuild variable at a command prompt. For an example of how you can override such a value, see the Command-line Syntax section of An Overview of Database Build and Deployment. You can also update the .dbproj file to add the values of the MSBuild variables for each build configuration. For more information, see MSBuild Properties.

  7. In Initial file size, take one of the following actions:

    1. Click Use default size from the target server.

    2. Click Specify size (MB), and type a specific number of megabytes.

  8. In File Autogrowth, take one of the following actions:

    1. To prevent the file from growing larger than the size from the previous step, click Specify autogrowth, clear the Enable autogrowth check box, and go to the last step in this procedure.

    2. To allow the file to grow larger than the size from the previous step, either click Use default autogrowth from the target server, or click Specify autogrowth and then select the Enable autogrowth check box.

  9. (optional) If you selected the Enable autogrowth check box in the previous step, take one or both of the following actions:

    1. Click In Percent or In Megabytes to allow the file to incrementally grow by a percentage of the current file size or by a specific number of megabytes. Then type the percentage or the number of megabytes by which the file can grow.

    2. Click Restricted file growth or Unrestricted file growth to specify whether the file should stay smaller than a particular size. If you clicked Restricted file growth, type the maximum file size, in megabytes.

  10. On the File menu, click Save All.

    When you build and deploy the database project, any new log files and filegroups are created in the database that you are updating.

See Also

Tasks

How to: Deploy Changes to New or Existing Databases

Concepts

Terminology Overview of Team Edition for Database Professionals

Other Resources

Overview of Files and Filegroups
How to: Define Variables for Database Projects
How to: Define Full-text Catalogs