Unresolved Reference in Visual Studio 2012 Databas

2019-02-25 12:27发布

问题:

Is there a way to reference another database from my database project without directly referencing it?

For example, I want to be able to write something like this:

CREATE VIEW View1
AS
  SELECT X FROM OtherDB.dbo.Table1

回答1:

Your best bet is to add a database reference to your project. For VS2010 and lower DBProj files, you'll want to generate a dbschema file and add it as a database reference. For SSDT, you'll want to use a dacpac file. This works well for projects that are mostly static and you can even tailor them down to just include the objects that are relevant.

VS2010, 2008 - http://msdn.microsoft.com/en-us/library/dd193283%28v=VS.90%29.aspx has the documentation you'll need to export an existing database into a dbschema file. Place it somewhere your project can access it and add it as a "Database Reference".

SSDT - http://msdn.microsoft.com/en-us/library/hh550080%28v=VS.103%29.aspx gives you the command line reference for generating a dacpac file. Once generated, place it somewhere your project can access it and add as a database reference.

I've got a blog post on this for SSDT here: http://schottsql.blogspot.com/2012/10/ssdt-external-database-references.html