Database Reference in SSDT project with UDFs and Views

后端 未结 1 929
南旧
南旧 2021-01-23 12:10

Running into a weird issue. Assuming there are two database projects in one empty solution, Bart and Homer. Bart has been added as a Database Reference to Homer.

Bart pr

1条回答
  •  再見小時候
    2021-01-23 12:34

    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.

    enter image description here

    0 讨论(0)
提交回复
热议问题