Skip to content

Latest commit

 

History

History
102 lines (88 loc) · 5.24 KB

File metadata and controls

102 lines (88 loc) · 5.24 KB

SSMS Solutions and Projects Explained!

Just like Visual Studio, SSMS has solutions and projects. Solutions and projects organize the files that are important to your database application.

The biggest difference between working directly with database objects and working with SSMS solutions is that solutions are based on files in your filesystem, not on objects in your database.

Projects provide a way to organize the files in a solution into groups, and are basically subfolders on your filesystem. The solution is at the top of the hierarchy. All projects must be part of a solution, and every file must be part of a project. Solutions can have, and often do have, more than one project. You may create as many projects as needed.

How to create a solution

  1. Select New → Project... from the File Menu

    New Project (and also Solution)
    image
  2. Follow these steps in the correct order

    1. Tick the checkbox, "Create directory for solution"
    2. Enter the "Solution name:"
    3. Enter the "Project name:"
    4. Click "OK"
    Names and Locations
    image
  3. Note: If you don't see the Solution Explorer, open it by selecting Solution Explorer from the View Menu

    Solution and Project Created
    image

How to add a new file

  1. Right-click on the project name in the Solution Explorer and select Add → New Item... from the context menu

    Add - New Item
    image
  2. Select "SQL Server Query" in the "Add New Item" dialog box

    SQL Server Query
    image
  3. Enter the "Name:" and click "Add"

    Item Name
    image

    Note: You can use this same technique to add non-SQL files. Just use the appropriate extension in the file name.

  4. New SQL files will always be listed under the "Queries" branch in the project tree view. Non-SQL files can be found under "Miscellaneous"

    MyQuery.sql
    image

How to create an additional project for an existing solution

  1. Right-click on the solution name, and select Add → New Project... from the context menu
    Add - New Project
    image
  2. Enter the "Name:" for the project and click "OK"
    New Project Name
    image
  3. The project will be listed in alphabetical order in the solution
    New Project Created
    image

How to add an existing file

  1. Right-click on the project name, and select Add → Existing Item... from the context menu
    Add - Existing Item
    image
  2. In the "Add Existing Item" dialog, select the file you want to add to the project and click "Add"
    Selecting a File - Anywhere
    image
  3. Note: If the file you selected is not in the project directory, SSMS will create a copy for you in the project directory.
    Copied and Added File
    image

Directory structure of the SSMS solution and related files

SSMS creates a directory for each project in the solution and adds a .ssmssqlproj file in it. There is also a .ssmssln file that contains the main information for that solution. Other files in those directories might be part of a project in the solution. However, files are not automatically added, so you might see files that are not part of the solution at all (for example ~\Documents\repos\SolutionName\PreexistingSQLFile.sql in the image below).

  1. SSMS Solution Folder Structure
    image

Best practices

We recommend the following for your database projects:

  • Create one project for your database application code and another project for the tests. However in more complex scenarios you can create as many projects as you like for each of the two areas, code and tests.

  • Delete your connection information before checking in if you are working in a team. This is not a security issue, but makes working on different SQL Server instances easier.