Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fully qualified name with dollar sign in SSDT project

I was working on a tsql project, and I have noticed that the existing code used a syntax that I have not seen before. They have put a dollar sign in front of the database name for fully qualified address.

Here is one example :

SELECT  c.AccountCode, FROM **[$(SmartAdmin)]**.dbo.Customers c

enter image description here

If I rename the database name as SmartAdmin.dbo.Customers, Visual Studio throws error says "contains an unresolved reference to an object".

It appears to be a Visual Studio related thing, can anyone explain what is this and whether I can remove it.

Please see the attached screenshots, the last one comes from project solution file.

enter image description here

enter image description here

like image 220
Shin Kazama Avatar asked Dec 05 '25 17:12

Shin Kazama


1 Answers

The [$(SmartAdmin)] syntax is used in an SSDT project to reference objects in other databases. To be precise, it is SQLCMD syntax.

If you have a database reference to SmartAdmin, and if the reference is set up so that [$(SmartAdmin)] properly references it, then that is not the problem. It looks like the problem is the other two references to [SmartAdmin]. Change them to look like [$(SmartAdmin)].dbo.whatever.


Example of why these references are useful: I just edited a stored procedure I had in SSDT to misspell a column name. Within seconds, the column name was underlined in red. I then deleted the database reference the column name depended on. The red underline went away. I added the database reference back, and the column was once again underlined in red. I corrected the column name, and the red underline went away.

Without the database reference, I would have had to wait until the stored procedure was deployed, or possibly executed, to see the error. With the database reference, I found out about the problem in the editor. Just like code.

like image 53
John Saunders Avatar answered Dec 09 '25 21:12

John Saunders



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!