问题
How do I make SQL Server Managment Studio Intellisense know what is the current database in use, i.e. I want to be able to do the following
SELECT * FROM Table
instead of
SELECT * FROM DatabaseName.dbo.Table
with intellisense.
UPDATE
Just confirm, I already had the currentdatabase selected, i.e. I don't have master database shown in the bottom left corner.
回答1:
Sometimes adding
Use DatabaseName
Go
To the top of your script file and executing it will do the job. Other than that, the suggetsions on Aaron Bertrands answer provide other ways to fix the intellisense.
回答2:
If you specify USE DatabaseName;
first, then it will be automatic. Otherwise, no, IntelliSense shouldn't lead you to believe there is a table with that name in the current database - it can't read your mind and know which other database you're thinking about.
If you are in the current database and IntelliSense still doesn't seem to work, first make sure IntelliSense is enabled (Ctrl + Q, Ctrl + I, or hit the "IntelliSense Enabled" icon on the toolbar when the query window has focus), and also hit Ctrl + Shift + R to update the local IntelliSense cache (it won't always see objects that were created or renamed recently, because it has a lazy loading mechanism (to avoid hammering your server with metadata requests)).
A host of other troubleshooting tips here.
来源:https://stackoverflow.com/questions/20400672/make-sql-intellisense-know-the-current-database