In Visual Studio 2013, I have setup two database projects in the same solution (DatabaseA and DatabaseB), with DatabaseA having a "database reference" to DatabaseB.
This all looks great, so I create TableB in DatabaseB and then a view in DatabaseA to get the data in TableB.
CREATE VIEW [dbo].[vDatabaseB]
AS SELECT Id FROM [$(DatabaseB)].dbo.TableB
Works perfectly. I now create a TableA in DatabaseA which will have a foreign key constraint to TableB.
CREATE TABLE [dbo].[TableA]
(
[Id] INT NOT NULL PRIMARY KEY,
[TableBID] INT NOT NULL
CONSTRAINT FK_TableA_TableBID FOREIGN KEY (TableBId) REFERENCES [$(DatabaseB)].dbo.TableB(Id) ON DELETE CASCADE,
Unfortunately, this just doesn't build:
Error SQL71501: Foreign Key: [dbo].[FK_TableA_TableBID] has an unresolved reference to Column [dbo].[TableB].[Id]. DatabaseA TableA.sql 5
How do I get this table constraint to work? I also tested this in Visual Studio 2015 (preview) with the same results.