SSMS: keyboard shortcut to execute current row? [duplicate] - sql-server

This question already has answers here:
How can I run just the statement my cursor is on in SQL Server Management Studio?
(27 answers)
Closed 6 years ago.
SQL Server Management Studio: Is there a way to execute current row (keyboard shortcut) without highlighting it?

Highlighting the text beforehand, i.e. by clicking the combination Home, Shift + End, F5 would appear to be the only option.
See answers here: How can I run just the statement my cursor is on in SQL Server Management Studio?

The add-in SQL Complete has this exact feature. Execute current statement using a hotkey without selecting it. Their free express version has it, but I also recommend standard version for its additional features. It's a major time-saver.

https://connect.microsoft.com/SQLServer/feedback/details/125200/execute-current-statement is a Connect issue on this - Guess it's a low priority.
I've just gotten used to using standard keyboard shortcuts. One such is to (if for example the query i want to work with is written in the end) select everything before this query using ctrl-shift-home, then ctrl-k, ctrl-c to comment this out, hit end, then f5. once i need to get all back i just ctrl-a then ctrl-k,ctrl-u to uncomment again.
In either case, it helps being familiar with the keyboard :)

I know of 2 shortcuts that will perform the Execute, but if you have more SQL statements within the SQL file, it will execute them all unless you highlight the line you want.
F5
ctrl+E

I've never come across a shortcut that will do that without selecting the row first. There isn't one listed in the SSMS Keyboard Shortcuts MSDN article either, so I don't think it is possible.

This works for me: Home, Shift + Left click

Here's an improvement on DaveRead's answer: Shift+Home, F5

Related

Microsoft SQL Server Management Studio and displaying queries as they happen in real time

Two years ago a SQL expert opened a SSMS and showed all queries as they were happening in real time. That way he saw which SQL statements were running fast and which took some time to be ran. I remember the queries to be displayed in a "CMD" look alike window. I can't remember if new queries were displayed at the top or were they shown at the bottom of the window.
For the past month I have been trying to figure out how he got this working. I looked everywhere in monitor, but I can't find anything similar to what he showed me than.
The results were similar to the "claymore eth miner window" ...
Can someone point me in the direction of getting this?
You can use sp_whoisactive to get the current running queries. It is very useful to see if currently there is blocking, locking, long running statements.
In order to get better picture of what was going on in the past, you can enable the Query Store. There are some predefined reports:
and various statistics and it is user friendly:

Copy/Paste, Delete option not working in SQL Management Studio

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.

Make SQL Intellisense know the current database

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.

code template in management studio

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.

SQL Server 2008 Intellisense - Typing 'top' brings up tables, causes confusion [duplicate]

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.

Resources