SQL Management Studio - Execute current line - ssms

In SQL Server 2008 Management studio, I can hit F5 to execute everything in the current query window. I can also highlight a query, and hit F5 to run that highlighted query.
Instead of having to highlight a query, is there a way I can run the single query my cursor is on, or run a query my cursor is on up to a the first ';'?

In options you can configure line numbers to be displayed, then you can just click on a line number, which will highlight the whole line.

Unfortunately no there is no such keyboard shortcut in the MSDN list of keyboard shortcuts for SMSS, and I don't see any way of recording a macro to do so. The only solutions I've found require creating an add-in which is quite a bit of work for a little savings.

Install SQL Complete Express. Its an SSMS plugin that free (also a paid version) and it allows using CTRL+SHIFT+E to execute current statement, I have remapped it to F9 as I use Toad frequently too.
I tried several others but they either didn't work with SSMS 2012 or I just didn't get on with them.
I find the intellisense quicker than the built in version to.

If you are able to use SSMS 2012 then you can use the SSMS Executor add in as mentioned by st-stoqnov in his answer to a similar question.
An Alpha release is also available for SSMS 2014/2016/2017.

In SQL after concluding a statement and as along as your cursor is at the end of the line all you have to do it hit SHIFT+HOME and it will highlight the entire statement and you can then proceed to press f5....

For keyboard users:
I found going down with the cursor to the end of the query line, or the line bellow if it is empty, and then using "SHIFT + arrow up" to select the full query. After selection hit f5

The new SQL Prompt has this feature. You press SHIFT+F5 and the statement that your cursor is currently on will be executed. That's a big time saver and a feature that should have been there from the start in the first place.

I just installed Devart's Sql complete express that is free of charge. With ctrl-shift-e it does what you want.
Now I just need to swap, to make ctrl-e execute current and ctrl-shift-e everything...

Related

Is there a way to set SSMS only allows to run when code is selected

I am pretty new to SSMS and I am starting to make scripts. Sometimes I click on Run without selecting my code and you can imagine that it has consequences on the database.
I wanted to ask you if there is a possible configuration on SSMS so that the run button is not accessible when we have code selected?
Kind Regards
Setting SET NOEXEC ON before the query guaranties that the SQL Server engine will check the syntax and object reference errors (during compilation), but it will not execute the actual query.
If you want prevent distract F5 or EXEC without have checked if you're executing something dangerous, put it before each script that you are making.

SSMS 2012 - IntelliSense Complete Word

I use SSMS 2012 with IntelliSense and it is usually fine. However, yesterday, the "complete word" function has turned itself on and is forcing my code to change according to what it wants.
For example, if I'm writing a multi table script and I know my first table will have an alias of "a", I will start by writing
Select a.*
But now, as soon as I hit the full stop button, the a changes to ABS
Select ABS.*
I like having IntelliSense on as I do use it, but I am not used to it overwriting what I type. I can't see any options to change this in the IntelliSense part of the Transact-SQL options.
Can anyone help, please?
Edit: I got a fresh install of SSMS2014 and am fine now, but in case anyone can answer this, it would be a handy resource for others.

SSMS - scripting data on change

Does anyone know of a way of scripting the data changes made via SSMS, e.g. update a table row and it shows the update SQL for that change, likewise for inserts & deletes?
I'm aware of being able to script out the entire changes using publishing wizard or using redgate software & I know you can switch on scripting for schema changes. However, I'm looking for something along the lines of: I do something in SSMS and I get a instant SQL statement telling me what I've done. I remember SQLYog doing something like this for MYSQL.
I was just looking for the same thing on SO with no luck, so clicked a few buttons in SSMS and found this:
"Generate Change Script" can be clicked after you've made changes in the SSMS designer. Upon clicking this button, a dialog appears that lets you view the SQL required to be run on your database for those changes.
If you check "Automatically generate change script on every save", then the same dialog will appear each time you click the save button.
You'll note that sometimes SSMS generates some ridiculously long SQL statements for seemingly simple changes. Unfortunately, even simple things like reordering/renaming columns cannot be expressed in standard SQL DDL statement - all SSMS can do is drop and recreate the table.

Ctrl+F and Ctrl+H doesn't work in SQL management studio

I cannot use the Ctrl+F and Ctrl+H in my SQL Management studio. Even if I use the menu items it doesn't work. Haven't installed anything new or changed anything recently. Any ideas?
Have you recently used multi-monitor? Is it possible that it is opening off-screen? I get this problem a lot when disconnecting my laptop from an external monitor...
(edit) There is a Window -> Reset Window Layout menu option in SSMS 2008, that should fix it.
Perfect! multi-monitor causes this.. Just minimize VS. Put to the other monitor.
You'll see opened window when you Ctrl+F
Irina
I currently have this issue also, I am using two monitors but this appears not to be the cause. I say this as the instance of management studio that I have open has two queries - both are connected to the same Server and Instance. On one query, Ctrl+F works fine, on the other query it won't work at all.
I think this is in some way related to debugging - the query which does not allow Ctrl+F currently I mistakenly debugged (as opposed to running) and after this the find/find replace functionality does not work!

Editing SQL query with Visual Studio 2008

Would you recommend me the best approach to edit SQL query with Visual Studio 2008 Professional, please?
I know I can open Query window from context menu in Server Explorer and edit text in SQL Pane. But unfortunately I am not allowed to save query to a file and Find and Replace commands are not working there.
Alternatively I can open text file with extension .SQL in Visual Studio editor obtaining syntax highlighting and full editing capabilities but losing possibility to execute the script.
Now I copy query text from one window to another and back but I hope there is better solution.
Many thanks for suggestions!
When I have to connect to Sql Server, I use NetBeans, as it has a number of features that make it much easier to use than Visual Studio. One of these is intellisense, which is very useful when you have an alias for a table name and lots of long field names. The general handling of connections and connection pools is also much cleaner in NetBeans. I could go on, but suggest trying it for yourself. You will almost certainly need the Sql Server jdbc driver, which can be downloaded from http://msdn.microsoft.com/en-us/data/aa937724.aspx
If you create a Database project within your solution in Visual Studio, then you can set up a default database connection for that project. Then any *.sql files that are included in the database project can be executed against that connection. What I usually do is select the text to be exectued and right-click it, then select "Run Selection".
You can set up any number of database connections under the "Database References" node in the solution explorer, and choose the one you want to run your query against.
Wow you are right, this is a real pain. Would it be acceptable for you to use a local copy of the SQL Management Studio (the name might be wrong)? You would be outside of VS but you could still edit your query and run it at the same time. Definitely not optimal but better than nothing.
Good luck.