Database Reference in SSDT project with UDFs and Views

北城以北 提交于 2019-12-02 04:09:05
Kevin Cunnane

When you add a database reference, by default it sets a database variable to use in your TSQL scripts. This allows your project to target multiple environments, where the referenced DB may have a different name.

The correct usage given this default would be:

CREATE VIEW [dbo].[MessagesV]
AS SELECT Id, [$(Bart)].dbo.Message() AS [Message]
FROM dbo.Messages

I've verified this works for the code snippet you sent. Note that if you do want to use the Database Name directly you can simply delete the Database Variable value when adding the reference. Then Bart.dbo.Message() will work as expected for you.

Shown below is the Add Database Reference dialog with the relevant Database Variable and Example Usage shown. You will see the usage change depending on whether there is any text in the database variable text box.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!