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.
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.
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.
Related
I was trying to copy and paste some queries and noticed that the paste option is not working. After that I realized that my copy, paste, delete and next line option is not working at all. What will be the reason for this issue.
When you press the Ctrl key, the text editor is looking for a mouse click to "Go to Definition".
Tools>Options>Text Editor>General> Uncheck "Enable mouse click to perform Go To Definition"
(or you can change the modifier key to something you use less often if you want to continue using this feature)
What, exactly, are you trying to copy, and from where? For instance, if you're attempting to copy and paste tables, views or stored procedures (etc) in the Object Explorer, you'll have no luck.
For most of these items, you should be able to right-click, select "Script [Table | View | Stored Procedure ] As > CREATE TO > New Query Editor Window", then run the script.
Unfortunately(?), SSMS isn't as easy going as Microsoft Access, there's definitely a little work involved.
just experienced the same situation in SSMS v18.5!
Also wasn't able to paste/copy code in the Query's Window.
After playing around and restarting the App it wouldn't work.
I did not have issues copying/pasting in all other applications.
Then I found a solution myself by simply thinking about how to "re-init" the engine of Copy/Paste in SSMS:
Go to: Tools | Options | General | Check "Apply Cut or Copy to blank lines when there is no selection".
After applying the "fix" you should be able to copy/paste again! You may reset the checkmark later.
Hope you other guys have the same luck!
Edit: A few hours later the Copy/Paste again was not working and the fix did not work. I found out that a separate instance of Visual Studio had the same copy/paste problem. So it may be either a Windows 10 or .NET problem.
A reboot helped me in that case.
I encountered this problem too, and got a message saying my pc was out of memory. This could be caused by too many apps being open or too many background processes running.
Simply restarting the pc resolved the problem.
Autocomplete stopped working some while ago for me. Intellisense seems to be otherwise working.
I tried everything mentioned here:
Tools >> Options >> Text Editor >> Transact-SQL >> IntelliSense, and
Enable IntelliSense is selected
Refreshed IntelliSense local cache: both Edit >> IntelliSense >> Refresh Local Cache or the CTRL+Shift+R keyboard shortcut to refresh
Enabled statement completion: please go to Tools >> Options >> Text Editor >> Transact-SQL >> General, and checked on Auto list members and Parameter information boxes
Rebooted SQL Server Management Studio several times
Checked that shortcut "CTRL+Space" is enabled for "Edit.CompleteWord" in Text Editor in Tools >> Options >> Environment >> Keyboard
I have problem only with option:
For each opening query window, please go to Query >> Intellisense Enabled
which is greyed out all the time:
I do not know, whether it is connected to my issue, but it might be.
So, how do I enable Autocomplete again?
it worked for me after pressing Alt+(Right Arrow)
I would recommend to forget about this issue and install 17.1 instead https://learn.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms. It is stable, free, looks beautiful and has more nice features than 2016.
Had the same problem: I did all the above mentioned. Solved it finally by disabling the SQLCMD Mode (which was activated)!
IntelliSense stopped working for me, due to offline databases. After bringing them online again, IntelliSense worked again.
My issue was solved by: Edit -> Intellisense -> Refresh Local Cache
I tried all the suggested solutions but nothing worked then I realized it didn't effect the query windows that was currently open.
Simply opening a new query window solved it.
SSMS version 18.12.1
I found that Intellisense was failing on an existing large SQL query window with many lines of different queries contained within.
I took the suggestion from Rikard Askelöf of opening up a NEW query window, and Intellisense started working to auto complete the table names after I put a DOT after the schema name in a new query line.
I finally found the problem was caused by this:
My large original query window had some "errors" in it from me pasting row data, and not commenting it out. I'm guessing Intellisense was getting so confused it just gave up.
Once I went through my query window and commented out all of the lines that had RED error's indicated by the scrollbar on the right, Intellisense works once again.
Invalid Linked Server Credentials
There is one additional case that I have seen. Took quite a bit of trouble to diagnose!
If the Server has a linked server and the credentials are no longer valid.
Autocompletion on objects freezes the cursor for a few seconds, then control comes back with no objects listed.
My issue was solved by: Edit -> Intellisense -> Toggle Completion Mode
intellij idea data sources doesn't see existing table in my mysql database, while Netbeans see it.
i've created a table in the database. When i create connection in intellij idea data sources, it sees my scheme, i do select it in "schemas and tables" but then i don't see it in the list.
every schema, but mine's. When i try to connect to it with netbeans or mysql workbench, it's just ok. same story with several databases, with root access, too. any table, but mine's.
what could be wrong?
i see question like mine's here, related to visual studio, no answer.
please, give a good clue
I had the same problem in IntelliJ IDEA 15.
I fixed it by right clicking the data source -> Properties -> Schemas -> Use legacy introspector.
I found the reason of problem for HSQLDB: There is IDEA bug (i have 11.0 version).
Create db with relative path (relative of MODULE), like this:
jdbc:hsqldb:file:db_file/testDBInMemory;shutdown=true;hsqldb.write_delay=false;
f:\TestModule\db_file\
When added it to Data Sources, IDEA recognizes this path as relative of $IDEA_HOME$/bin folder.
f:\Program Files\JetBrains\IntelliJ IDEA 11.0\bin\db_file\
So you have two different data bases. And when JPA updated first, Data Source doesn't see update in other.
WORKAROUND:
use absolute path in file db url.
For the latecomers still experiencing this, Intellij IDEA also has the following features which might help you as they have me:
'Force Refresh' (ctrl + shift + F5): "The Force Refresh action clears the data source information from cache and loads it again from scratch."
'Forget Cached Schema' which clears the schema cache. Does require you to set which schema you want shown again.
Right click your datasource -> Diagnostics -> 'Force Refresh' or 'Forget Cached Schema'
Source: https://www.jetbrains.com/help/idea/cannot-find-a-database-object-in-the-database-tree-view.html
The answer for me was buried in a comment, so I'm posting it here. The symptom for me was seeing an error like this:
Unable to resolve table 'thetablename'
And the table name was highlighted in red.
The following fixes are all ways to trigger IntelliJ to refresh data sources:
CTRL+ALT+Y to refresh the db stuff, or
CTRL+F5, or
Click the database vertical tab on the right, expand, right-click on each DB connection and select 'Refresh'
Kudos to #ice for answering this earlier in a comment. I'm basically just elaborating and making sure this shows up as an answer.
Can I find in management studio the Following feature?
I want to write a specific word and that it be replaced by a statement specifies. Ex: I write "ss" and replace "select * from" or write "johnid" and is replaced by "where id = '555 '"
In Toad for Oracle You might still in: "option - behsvior - template code - code template"
http://www.toadworld.com/Blogs/tabid/67/EntryId/343/Customizing-Toad-Code-Templates.aspx
There is nothing I know of built into Management Studio that will behave exactly like you are suggesting. There are some shortcuts you can advantage of in Tools > Options > Environment > Keyboard > Query Shortcuts, but these run the code rather than paste them into your window, so you can't use them as partial syntax completion. For example if you assign SELECT * FROM to Ctrl+9, then open a new query window and press Ctrl+9, you have an empty query window and the following error message:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'FROM'.
Chris already mentioned templates, so I won't treat those.
In SQL Server 2012 you can use a new feature (well, an old feature recycled from Visual Studio) called Snippets, which I think is a lot more powerful than the Template feature (I wrote about them here, and someone else did a decent job here). But I still don't think it's quite what you're after - there's a menu system to go through to insert a snippet, and so far in my research I've been unable to assign a keyboard shortcut -- even though there is an empty element in the Snippet XML called <Shortcut></Shortcut>, and most of the people who talk about this feature mention it, but I've yet to see a working snippet that used it (and I have tried many variations to get it work like it does in Visual Studio with no luck).
You can also use 3rd party tools, such as Mladen Prajdic's free SSMS Tools Pack. For what you want to do, I think this is the best fit, since it allows you to do real expansions snippets where the replacement text is put into your code based on the keyword you typed ad further keystrokes. However if you're using SQL Server 2012, at the time of posting we're still waiting on a compatible release for that version of SSMS. You may also want to look into Red-Gate's SQL Prompt, but I'd try Mladen's free tool first if you can. I'm sure there are other alternatives you can turn up with a standard search.
This feature is present in these free add-ins:
SSMSBoost or SSMS Tools Pack
Use Template Explorer
SQL Server provides a variety of templates. Templates are boilerplate files containing SQL scripts that help you create objects in a database. The first time the template explorer is opened, a copy of the templates are placed in the user’s folder in C:\Users, under AppData\Roaming\Microsoft\SQL Server Management Studio\110\Templates.
You can browse the available templates in Template Explorer, then open a template to incorporate the code into a code editor window. You can also create custom templates.
Either the autocomplete in SQL Server Management Studio 2008 is buggy, or I am. Either way, when I try to type this and hit the spacebar:
SELECT TOP
Autocomplete immediately changes it to this (Topics is a table in one of our databases, btw):
SELECT Topics
Is there a way to fix, or at least gracefully work around this?
Unfortunately, no. SSMS Intellisense is a 1.0 product, and is not as feature-rich as many third-party products. You can turn it off OR ignore the suggestion (with the ESC key).
I think all you can do is hit ESC when the intellisense pop-up appears which will cancel any change it makes, or just turn Intellisense off completely by going to Text Editor -> Transact-SQL -> Intellisense.
I know this has been answered already but if you are looking for a tool that is quite useful/helpful try SQL Prompt from Red Gate. I have used this tool for years and found it is a great replacement for the built-in intellisense with plenty of options to allow for the tool help you be more efficient...
Also, you can cheesily add one column empty tables for the most common keywords you have issues with. Then it autocompletes to the table name but context puts it into the right usage.
Going one further you can:
CREATE table [top ] (c bit)
with the space at the end so the auto-complete is perfect.
After you create the object you'll want to hit CTRL-SHFT-R to refresh your Intellisense.