Day # 2 of SQL –
I am trying to run a function that I made yesterday, but SMSS is looking at the "Master" database and not my "Metrics" database so it won’t run – it says "Invalid Object Name".
I know this is a simple question, but I’m not even sure what the correct term is. Do I need to change my "scope"? My "focus"? My "active database"? Not sure how to look this up on Google.
Add the line
USE Metrics before your function call.
You can also change the database by using the dropdown list on the toolbar in the top left of Management Studio.
And of course, you can also fully qualify your call like this:
USE YourDatabaseName at the start of all your scripts is a good habit to get into. That’s my own preference.