As a long time Toad for Oracle user, I have gotten used to hitting Ctrl+Enter and having just the statement under the cursor be executed.
In SQL Server Management Studio, hitting F5 runs the entire script. To run just the current statement, I have to manually highlight the statement I want, and then hit F5.
That is really annoying to me. Does anyone know of a tool with a keyboard shortcut to run just the current statement on a SQL Server? I would change tools just for this one feature.
Note: Oddly enough, even the free Toad for SQL Server does not let you run just the statement under the cursor.
Use Ctrl+KU to select a line.
Then use F5 to run it.
Although it only works for single line selection, still I find it quite useful.
Hope it helps!!
You can check out this add-in for SSMS 2012. Place the cursor within the statement you want to execute and press CTRL+SHIFT+E
SSMS Executor - https://github.com/devvcat/ssms-executor/releases
Update:
Project moved to github and the addin re-written to support SSMS 2014, SSMS 2016. (Previously, the project lived on codeplex, at SSMS Executor - http://ssmsexecutor.codeplex.com/.)
Ok, so what I'm getting from all these answers is "No, that is not possible."
Edit:
Here is how I was able to do this:
1 - Download SQL Developer
2 - Download the jTDS driver
3 - Follow these instructions to add that driver to SQL Developer
4 - Connect to SQL Server using SQL Developer (cool!)
5 - Run it and life is good
Somebody suggested this features on Devart dbForge SQL Complete (addon for Management Studio) , and it's still in the development stage. Let's hope that it's finished and doesn't get abandoned halfway through development.
Above answer helped me to create a shortcut to Execute current Statement without selecting the query
1 - Click on Tools > Options > Environment > Keyboard
2 - For Show commands containing, set it to SqlComplete10.Common_ExecuteCurrentStatement
3 - For Use new shortcut in, set it to SQL Query Editor
4 - For Press shortcut keys(desired shortcut key), perform the Ctrl-Enter combination.
5 - Click on Assign. Click on OK.
I used this work around; when code is not commented out
Ctrl + K + U
(this command highlight current query line) and then
Ctrl + E
(this run highlighted query).
It is useful when you want to run a single line query between some other lines like :
Select top 100 * from [dbo].[Order]
Select top 100 * from [dbo].[OrderItem]
Select top 100 * from [dbo].[OrderStatus]
Note: Oddly enough, even the free Toad
for SQL Server does not let you run
just the statement under the cursor.
It is really annoying that TOAD does not hold to what it promises:
From TOAD help: [F9 to execute] a portion of a statement, which can contain one or more statements. You can select the portion of the statement by placing the cursor within or adjacent to the statement, or by selecting the statement.
Note: Toad considers "adjacent" all statements (including comments) separated from the cursor or from each other by fewer than two blank lines. If an error occurs during statement execution, an error message displays, allowing you to either ignore the error and continue or to abort execution.
I tried it million times but it simply executes the whole script. I wanted to search for it in the user support group (toadss(at)yahoogroups.com) but yahoo has the stupidest search facility ever! It can't even find the keyword "toad" in the toad mail group, DOH!
I think TOAD is the best querying tool ever, but the lack of this feature really annoys me too.
UPDATE: SOLUTION FOUND!
I asked this issue in toadss mail group and got the answer. Unlike Oracle, you have to separate statements in SQL Server with the keyword GO after each statement. Only if you do that the F9 button works as expected, executing the current statement.
I use a workaround: I comment queries I'm not using. You can use CTRL-K, CTRL-C to comment the SQL you've highlighted. Use CTRL-K, CTRL-U to uncomment. That way, you can comment all other queries, and execute the one you're interested in with F5.
I don't think this is possible to do using just the management studio.
BUT you can use keyboard shortcut software (e.g. http://www.autohotkey.com/) to have a special sequence recorded and assigned to a hotkey.
In your case you need:
<home><shift-end><F5>
This will select the current line and execute it.
Hit Ctrl-E while text is highlighted.
In Toad for SQL Server the following default hot-keys can be used for execution:
F5: Execute all SQL statements in editor
F9: Execute SQL statement at current cursor position
Shift-F9: Execute all SQL statements from cursor, including the current at cursor position
However, like 'ercan' wrote, you need to seperate/follow each statement with 'GO'.
SELECT TOP 5 * FROM accounts
GO
SELECT TOP 5 * FROM users
GO
SELECT TOP 5 * FROM contracts
GO
This feature is present in SSMSBoost add-in for SSMS (I am the developer of this add-in):
Shift-F5 will select the current statement (which allows you to review what you are currently going to execute). Then you press F5 and execute it.
Easiest way to do this is assignment for CTRL + Enter combination for action Query.Execute in SQL Server Management Studio.
Open Tools > Options menu.
Select Environment > Keyboard page in left pane.
Find Query.Execute action and select it.
Set SQL Query Editor in "Use new shortcut in:" dropdown list.
Now type CTRL + Enter combination in press shortcut keys: textbox.
Click the Assign button.
Change Shortcut currently used by: to Query.Execute (Ctrl+Enter (SQL Query Editor))
Click OK. Done.
If it's the having to move your hand to the mouse part that bothers you, you can hold the Ctrl down while hitting an up or down arrow key to select a line at once.
SQL Complete Express edition has this built in. But you don't get it without the custom intellisense.
(I got this from Salamander2007's post)
If the executor add-on solution (in the top posted answer) isn't working properly, i got it to work for me (SSMS v17.8.1):
The add-on adds a command under tools: Tools > Execute Inner Statement.
You can assign a custom keyboard shortcut key to it by going to Tools > Options > Keyboard then search for "execute" in the 'Show commands containing:' and selecting Tools.ExecuteInnerStatement.
Then just assign your desired keystroke(s) in the 'Press shortcut keys:' field and hit the Assign button.
Try to define macro in SSMSBoost
SSMSBoost/Settings/Macros:
Select free slot for your macro
in right panel fill caption (if you want)
add 2 commands to sequence:
SSMSBoost.SelectCurrentStatement
Query.Execute
assign youur favorite shortcut
and that's all.
I agree with JosephStyons but can not upvote or comment. DBeaver, squirrel, PL/SQL Developer, Toad all have the option to execute a single statement.
In my case I use these other tools which all have the option but then when I us SQLServer Management Studio, I am at risk of inserting and/or deleting because I forgot to highlight the select statement.
This is not an option, it is a requirement. However Microsoft refuses to acknowledge logical useful features needed by users but chooses to cater to useless and cosmetic features.
UPDATE: I wonder if Microsoft and SQL Server users feel this bug is a "feature" because they are able to (forced to) chain SQL Statements together and all execute at once. Perhaps that is why the request fall on deaf ears?
Microsoft is developing Azure Data Studio as the preferred, cross-platform management tool these days. In fact, installing a recent version of SSMS also installs ADS.
Azure Data Studio can run the current query in a query window with Ctrl+F5. In a SQL Notebook the current cell is executed with F5
select the line you want to execute and click on the execute button
you could always use the command line tools sqlcmd and osql. I did a lot of sybase all at the unix command line using a wrapper function that passed my command string into the equivalent (which i think was isql?). I used vi to, so maybe I was just crazy then ;-)
Just select (highlight) the single statement you want to run and hit F5.
You can combine the two Tools as follow : SQL Complete from dbForce and AuhotHotkey.
With SQL Complete: you can execute the current statement at the cursor, by pressing the combination Ctrl Shift E
The reason that I used the AutoHotkey is to make life easier :-) by using just F6 to execute the current statement, by setting the following code in AutoHotkey script:
;SQL EXECUTE THE CURRENT STATEMENT
F6::
Send ^+E
return
And voilà you can execute any current statement at the cursor by just pressing F6
But sometimes, again my big problem is I mistakely press F5 instead of F6 :D
Redgate's SQL Prompt extension for SSMS can do this.
It's not free but in my experience it's well worth having. Better intellisense than the SSMS out of the box version, tab colouring, tab history (so valuable!), snippets, single statement (not just a single line) execution, and lots more.
To run just a section of a larger script, try this ..
Steps:
Collapse the SQL statement you want to run by clicking the minus sign in the left margin next to the statement. That will show only the first line (with an ellipsis "..." to indicate more code not shown) and the ending ";" for the statement.
Highlight the line.
Press [F5] key.
That will run just the highlighted statement. If you want to run more than the one
statement at a time, collapse each statement and highlight all that you want to run, then click [F5].
It's a work-around, but still much easier than having to drag and highlight numerous lines of code every time.
Use Shift+▼ (arrow down) to select single row, save a button than
Ctrl+KU :D lol.
Then use F5 to run it.
Hope it help too..
The following works for me ... I use SSMS 2012
1 - Click on Tools > Options > Environment Keyboard
2 - For Show commands containing, set it to Query.Execute
3 - For Use new shortcut in, set it to SQL Query Editor
4 - For Press shortcut keys, perform the Ctrl-Enter combination.
5 - Click on Assign. Click on OK.
What is the simplest way to edit value of a single cell in SQL Management Studio. In the GUI (graphical user interface).
For example:
1) I select a row from the table customer.
2) I want to change in the selected and shown row the value of its fk_order column. Which now has value 5 and I want to edit it to have value 8.
In SQL Squirrel this was easy. Just "Make Editable" from context menu and then click the cell and edit value.
How to do that exactly same operation in SQL Server Management studio?
I don't want to write queries this time. I want to learn this way as well. Sometimes this is safer.
No worries use "Edit top n records" command in SQL management studio.
However beware, this is not a good practice, use SQL updates, rather do not update records manually, unless at most required.
Have a look at this video, which shows what I mean,
https://www.youtube.com/watch?v=lzCZunqeVlg
Regards,
N Baua
SQL Server Mgmt Studio is driving me crazy.
If I create a view and SELECT '*' from a table, it's all OK and I can save the view.
Looking at the SQL for the view (eg.by scripting a CREATE) reveals that the 'SELECT *' really is saved to the view's SQL.
But as soon as I reopen the view using the GUI (right click > modify), SELECT * is replaced with a column list of all the columns in the table.
How can I stop Management Studio from doing this ? I want my 'SELECT *' to remain just that.
Perhaps it's just the difficulty of googling 'SELECT *' that prevented me from finding anything remotely relevant to this (i did put it in double quotes).
Please, I am highly experienced in Transact-SQL, so please DON'T give me a lecture on why I shouldn't be using SELECT *. I know all the pros and cons and I do use it at times. It's a language feature, and like all language features can be used for good or evil (I emphatically do NOT agree that it is never appropriate to use it).
Edit: I'm giving Marc the answer, since it seems it is not possible to turn this behaviour off. Problem is considered closed. I note that Enterprise Manager did no similar thing.
The workaround is to either edit SQL as text, or go to a product other than Managment Studio. Or constantly edit out the column list and replace the * every time you edit a view. Sigh.
When SQL Server Mgmt Studio creates a view, I assume they're expanding the * to the complete list of columns that are present in the underlying table(s) at that particular time exactly for this reason: what if one of the underlying tables changes? Do you want the new columns to just simply show up in every view that references that table?? Seriously???
I think Microsoft tries to impmenent the "element of least surprise" here - your view will contain those columns that are present at the time the view gets created - and it stays that way, unless you explicitly and knowingly change that.
I for one wouldn't want to have my views suddenly having more columns than before, when an underlying table changes..... do you??
And I don't think there's any setting in Mgmt Studio to turn this behavior off, sorry.
Don't use the GUI editor.
Instead use the T-SQL editor. You get this by selecting "Script View As" -> "ALTER to" -> "New Query Window" from the right-click menu.
Try either of these: they are alternatives to using the GUI and can be setup as snippets with keyboard shortcuts:
select view_definition
from information_schema.views
where table_name = 'viewname'
or
exec sp_helptext 'viewname'
The results will retain the "select *". (Tested)
I am using SQL Server Management studio and keep getting the same error, and the only way to get rid of it(usually) is to reset the SQL server(which is very annoying, and sometimes impossible from my remote machine)
When I add a row to a table, and then I goto "Edit Top 200 Rows" it all displays and acts fine, and I go to a field I want to change. Then I change something like 0 -> 1 and then I get a nice friendly popup saying "Data has changed since the Results Pane was last retrieved... Optimistic Concurrency Control Error" If from here I say "Yes to commit changes to database anyway" I get "No row updated... The updated row has changed or been deleted since data was last retrieved"
It's a very annoying little thing, cause I don't like having to look up RIDs and then make an update statement(and possibly having to worry about escaping 's by hand)
Is there some way to turn this concurrency checking off or something? I know the row wasn't updated or anything, and I tried completely closing Sql Server Management Studio and reopening to no avail, and also tried refreshing the result pane, or refreshing the column view. Nothing gets rid of this error, but if I do a "update ... set ...=..." then it works, so I'm not really having any concurrency error..
I had exactly the same problem. It looks like this article was pretty good at solving it. Seems all sorts of buggy things in some versions.
See: You may receive an error message when you try to use SQL Server Management Studio to update a row of a table in SQL Server 2005.
The table contains one or more columns of the text or ntext data type. The value of one of these columns contains the following characters.
Percent sign (%)
Underscore (_)
Left bracket ([)
The table does not contain a primary key.
http://social.msdn.microsoft.com/Forums/en-US/sqldatabaseengine/thread/7bf48a75-58a0-41d7-b514-b804a49ae8ff/
it seems to be a bug in SSMS I don't think I have over 4000 characters, but I can confirm this only happens on rows that have more data than others.. there seems to be some abritary limit that I can't quite put my finger on..
So, plainly SSMS is complete crap. I'll be looking for a new SQL manager..
You shouldn't edit a table directly from the table view.. you should use an UPDATE sql command.
I would like to edit data directly from result grid in ssms. eg:
When I execute SELECT TOP 10 * FROM some_table, I want to edit data directly from result grid.
I don't want to open some_table and edit from there.
I know that result grid is read-only, but maybe someone written addin for it.
You can't edit the data from within the result grid. You'd have to go via the "open table" route if you want to edit the data manually instead of using UPDATE/INSERT SQL statements.
Is there a reason you specifically want to use the result grid instead?
You can specify a query when you go via open table to limit the results if that's your reason? There's a "Show SQL Pane" button in the top toolbar you need to select (square box with "SQL" written in it).
I have very large database (70+ GB) with so many tables.
I'm using Red Gate's SQL refactor for intellisense and few other things.
It's so boring to type in update sql statements every time I need to change single field.
It also takes some time to find that table in the Object explorer.
Intellisense doesn't work when I use "Show SQL Pane".
I'm new to SQL Server and have used the Oracle product 'PL/SQL developer' by All Round Automations at a previous job... It would allow you to do a SELECT in the query window and then simply add "FOR UPDATE" to the end of your refined SQL SELECT and 'ta-da' you can now edit the results in a nice grid. No need to Open Table View, click the SQL button, paste in the SQL you you have been working on and then hit execute ;)
EMS SQL Manager for SQL Server allows to update data directly inside a results grid.
This tool is boring for typing new requests (poor intellisense and error management) but fine for this. I always have the two tools opened.
If you right click on the table and choose edit top 200 records, it produces a result screen with an query.
Add to this your query and then you can edit the records in the result screen.
Also you can change the 200 to a number you want (2000).
The "results" pane is not just results.
Results in text
Assorted time and IO statistics
Estimated and actual execution plans
Row counts, Error messages, PRINT output
etc
This is why they are separate.
Feel free to write your own add-in :-) Or here
SQL Server ISN'T Access!
When you run a query and get the results - thats exactly what you are doing, reading the data, not opening the table for editing. Can you imagine the necessary transactional control around allowing the results window to be edited? The locking would probably grind SQL to a halt - I hope no-one ever writes that kind of add-in!