Shortcut to duplicate line in SQL Server Studio Management?

15,900

Solution 1

I think that you can hit CTRL + C without any text selected and in clipboard you got full line after that hit enter and paste line.

Ill check in morning is it working in MGM2008 I use 2005.

Solution 2

If you're using SSMS 18.0 or above and don't use the shortcut for Results to Grid (which currently occupies CTRL+D), then you can update the key bindings in the Options menu.

  1. Go to Tools -> Options -> Environment -> Keyboard
  2. Under Show commands containing, search for Edit.Duplicate

Keyboard section of Options dialog box in SSMS showing Edit.Duplicate

  1. Select the Press shortcut keys box and press CTRL+D
  2. Now search for Query.ResultstoGrid
  3. Remove both of the shortcuts for CTRL+D.

When you click "OK" to leave Options, you should find that you can use the key binding straight away.

Edit: Added confirmation that this is only supported from SSMS 18.0 onwards (h/t @Darrin for confirming)

Solution 3

I use this AutoHotKey script to replicate the CTRL + D "duplicate line" functionality I'm used to from Visual Studio:

; make ctrl+d duplicate line in SQL
SetTitleMatchMode, 2
#IfWinActive, Microsoft SQL Server Management Studio
^d::    
    ; save clipboard
    SavedClipboard = %clipboard%
    Send {Home}
    Send +{End}
    Send ^c
    ClipWait
    Send {End}
    Send {Enter}
    Send ^v
    clipboard = %SavedClipboard%
    return

Solution 4

I like @Matt Kemp's AutoHotKey script solution, but I used this script instead:

; make ctrl+d duplicate line in SQL
SetTitleMatchMode, 2
#IfWinActive, Microsoft SQL Server Management Studio
^d::    
    ; save clipboard
    Send ^c
    ClipWait
    Send ^v
    Send ^v
    return

Solution 5

In SSMS 18.2 [edit.Duplicate] associated with [CTRL+E, V] and with [CTRL+D]. The easiest way is just remove association [CTRL+D] with [Query.ResultstoGrid]. Then this will state only for [edit.Duplicate]. After that you can use [CTRL+D] for duplicating rows. I think it is not often case when you change saving result into grid or into file. Option

Share:
15,900
zach
Author by

zach

Updated on June 06, 2022

Comments

  • zach
    zach about 2 years

    In Netbeans and Eclipse you can hit CTRL + Shift + Down (i think thats netbeans) and it will duplicate a line of code. Is that possible in SQL Server Management Studio? This is running with SQL Server 2008