Help: SQL Server

Sharing my knowlege about SQL Server Troubleshooting Skills

  • Blog Stats

    • 2,154,274 hits
  • Select GETDATE()

    January 2026
    M T W T F S S
     1234
    567891011
    12131415161718
    19202122232425
    262728293031  

Archive for the ‘SQL Server Management Studio’ Category

SSMS Tip: What happened to my keyboard shortcuts? Ctrl+R (Show/Hide Result) and Ctrl+E (Execute) not working!

Posted by blakhani on May 8, 2014


Long back I installed SQL Server 2014 to learn new features and of course share the knowledge. I started from CTP1, CTP2 and finally came to RTM. Earlier I was installing them on Virtual Machines and recently I installed SQL 2014 on my laptop which already has SQL Server 2012 installed.

While using SSMS of SQL Server 2014, I noticed that earlier keyboard shortcuts were not working as they used to work earlier (in SQL 2012 SSMS). Few examples are as below:

  • Ctrl + R should show/hide result pane.
  • Ctrl + E should execute the query.

If I use above, I was getting below message in the left bottom of SSMS. “(Ctrl+R) was pressed. Waiting for second key of chord…

image

Pressing Ctrl+R again I get message as “The key combination (Ctrl+R, Ctrl+R) is not a command

Same was the case with Ctrl+E command. “(Ctrl+E) was pressed. Waiting for second key of chord…” . If I take my mouse to “Execute” button, it guided me that shortcut to execute command is Ctrl+Shift+E. And it works as well.

image

But I always preferred to go back to earlier settings. There are multiple ways to achieve it.

Short Route

If you have not done any customization in SSMS and you are OK to reset all the settings then you can use this. In Management Studio menu, go to Tools –> Options –> Environment –> Keyboard –> Keyboard –> Apply the following additional keyboard mapping scheme” and choose “Reset”. You would get a confirmation pop-up, click OK there.

image

Long Route

This route would be preferred if you have done some customization with the settings and want to retain those setting. you can provide shortcuts to any action. Go to Management Studio Tools menu and Tools –> Options –> Environment –> Keyboard –> Keyboard Over there, you can choose the command and assign the “shortcuts for selected command”. The list of command can be searched. For example, I have entered “Window.ShowResultsPane” and assigned Ctrl+R to it as below. Make sure to click on “Assign” button before hitting OK.

image

In Same way , Ctrl+E can be assigned to “Query.Execute

Documentation: http://technet.microsoft.com/en-us/library/ms174205(v=sql.120).aspx (SQL Server Management Studio Keyboard Shortcuts)

More reading: http://blogs.msdn.com/b/managingsql/archive/2011/07/13/enhanced-keyboard-shortcuts-in-ssms-in-denali.aspx

Hope this helps! Please write comment and let me know your feedback.

Cheers,
Balmukund

Posted in SQL Server Management Studio, SSMS | Tagged: , , , , , , | 15 Comments »

SSMS Tip: Merging ERRORLOGs from different machines using Log File Viewer

Posted by blakhani on March 6, 2014


For those who don’t know what/where is SQL Server ERRORLOG, please read this

Log File Viewer is an interesting feature of Management Studio and I have been ignoring it (you too??). This tool as saved a lot of time for me so thought of sharing some cool features of this tool. This can load various logs including system event log, application event log, DB Mail Log and SQL Agent log.

As a part of my regular work, I need to look at SQL Server ERRORLOG to look for various information about environment like SQL version and Edition, Processors and memory etc. If you want to know where ERRORLOG is located, then read here.

While working on a case on AlwaysOn Availability Group, customer provided us errorlog from two machines. To complete my analysis, I have to merge the file from both servers so that I can look at series of event happening across the server. Since customer was not having access to physical machine, he used management studio to “export” the errorlog.

Here are the steps to export the log using “Log File Viewer”

image

Once the viewer is opened, it opens current ERRORLOG file from the server. If we want to see more we can select checkbox on the left hand tree as highlighted below.

image

Export button can be used to Save the content on local machine. This is useful when we don’t have access to physical server to get file.

To demonstrate “merge”, I have exported current ERRORLOG from three servers and saved them as ERRORLOG_SQLPAPA, ERRORLOG_SRV1 and ERRORLOG_SRV2. I have kept all files in same machine and launched SSMS there. First, we need  to load the log as shown below.

image

One all are loaded, we can see them on left hand tree. Select the checkbox if it has to be loaded on right side grid.

image

I have selected all three files. Now, in the grid there is one interesting column, Log Source which shows the file which is loaded. I have dragged the column header and moved to visible location.

image

If we sort by date column, we can easily see the series of message in errorlog based of time. Since we have “Log Source” column, it possible to find server name as well. That’s why I have given File Name which is meaningful. In above screenshot I can see that top 3 messages are from different servers and I know the time as well.

You can be more creative and use “Filter” to load only specific data which you are interested.

Hope you liked this cool feature. Please provide feedback via comments.

  • Cheers,
  • Balmukund Lakhani
  • Twitter @blakhani
  • Author: SQL Server 2012 AlwaysOnPaperback, Kindle
  • Posted in SQL Server Management Studio, SSMS | Tagged: , , , | 1 Comment »

    Did you know? You can generate Insert Statement with data using Management Studio!!!

    Posted by blakhani on December 13, 2013


    I must confess that at least I didn’t know about that option till I saw an internal email thread. And my first reaction was – Damn! all these years and never spotted that! Yes, we can get all of the INSERT statements for the data straight out of SSMS. Another hidden feature of SSMS.

    Earlier, I used to search on internet and get some stored procedure to get the insert statements generated for me. Here were few search strings which used to give me proper results “SQL Generate Insert Script”, “SQL Server Generate Insert Script”, "SQL Server Script Insert Statements", "Create Insert Script SQL Server", "Generate Insert Script from Table"

    Now I can avoid all those searches and do that right from the Management Studio. For demo purpose I would create a small database and show that option. Please note that I am using SQL Server 2012 Management Studio (SSMS 2012)

    CREATE DATABASE [myAppDB]
    go
    Use myAppDB
    go
    Create table HelloSQL (iID int, vFname varchar(100), vLName varchar(100))
    go
    insert into HelloSQL values 
    (1, 'Balmukund', 'Lakhani'),
    (2, 'Vinod', 'Kumar M'),
    (3, 'Pinal', 'Dave'),
    (4, 'Sourabh', 'Agarwal'),
    (5, 'Amit', 'Banerjee')
    go
    Select * from HelloSQL
    go
    
    

     

    To achieve our insert statements with script use Object Explorer and connect to an instance of the SQL Server. Expand Databases folder, Choose the database for which we want the script, right click, Tasks > Generate Scripts.

    Once Wizard is launched, its self-explanatory to navigate through screen.

    image

    After welcome screen, we need to choose the object (table HelloSQL in our case) for which we want script to be generated.

    image

    In next screen, we need to choose the destination of script. I have selected “Save to new query window”

    image

    In the same screen, we have a magical button called “Advanced”. That’s where we have many options about scripting.

    image

    I have selected “Schema and Data” under “Type of data to script” and hit OK. Hit Next on previous screen

    image

    hit Next and Finish.

    image

    … and we have what we needed. Schema creation as well as Insert Statement for the data in table.

    image

    There are many other options in advanced tab. Play with them and get the desired script. I have learned this and it was new to me. Hope this is useful to you also. SQL Server generate script with data is a powerful SQL Server tool in order to create SQL script to move data from one database to another database. SQL programmers can export data as sql script by using one of the existing SQL Server tools, SQL Server Generate Script Wizard.

     

    Cheers,

    Balmukund Lakhani

    Twitter @blakhani

    Author: SQL Server 2012 AlwaysOnPaperback, Kindle

    Posted in Screenshot, SQL Server, SQL Server Management Studio, SSMS, Step by Step | Tagged: , , , , , , , | 10 Comments »