Search code examples
c#visual-studio-2012database-projectsql-server-data-tools

VS2012: Database reference


As a C# developer, I'm familiar with adding assembly references in a Visual Studio project. It looks like you can also add a database reference to a project.

My question is: Why would you want to add a database reference to a project?

Does this let you do something special like track dependencies on database tables or columns?


Solution

  • For SSDT projects such as you mentioned, there are two main use cases for database references:

    • Composite projects are a great way to handle cases where you have common schema elements such as tables that are shared by a number of databases. This maps to the concept of inheritance and object reuse in C#, and helps you avoid duplicate code and improve your design.
    • External database references are used when your code such as sprocs and views needs to reference elements from other databases. It is useful in resolving references and ensuring the project can build successfully. In this case it maps pretty directly to the concept of referencing Apis in C#.

    Note that the help you linked to is the old help for VS2010 projects, more accurate help for SSDT is here.

    Also you might notice that you can also add references to .Net assemblies, that may be necessary if you are writing SQL CLR code in your project and need to reference external code.