user4547600
user4547600

Reputation:

How to comment & uncomment multiple line SQL code in DataGrip IDE

I would like to comment out queries with a keyboard shortcut, like so

 SELECT * 
   FROM Academics
   WHERE Academic_id = 1

To become

--SELECT * 
   --FROM Academics
   --WHERE Academic_id = 1

Upvotes: 22

Views: 100467

Answers (6)

Raja Mali
Raja Mali

Reputation: 41

You are using SSMS, then you can go to:

1).use for single line

--

shortcut CTRL + K, CTRL + C.

2).use for multiline for /*

here your selected text

*/

Thanks

Upvotes: 1

Rahid Axundzadə
Rahid Axundzadə

Reputation: 49

You are using SSMS, you can go to:

Tools - Options - Keyboard JUST change keyboard mapping scheme to Vs Code

then Ctrl + / works

enter image description here

Upvotes: 4

Kemal Cholovich
Kemal Cholovich

Reputation: 181

  1. Select SQL code

    SELECT TOP 3 * FROM CUSTOMER WHERE Customerid ='4de3092d03b742f3b2b88cf6fe0b09d0'

  2. Press CTRL + / (or CMD + / on Mac) on the keyboard

  3. Code will be commented

    --SELECT TOP 3 * --FROM CUSTOMER --WHERE Customerid ='4de3092d03b742f3b2b88cf6fe0b09d0'

  4. If you need to uncomment it, you need to mark commented code and press the same keyboard combination CTRL + / (or CMD + / on Mac) on the keyboard Code will become uncommented again:

    SELECT TOP 3 * FROM CUSTOMER WHERE Customerid ='4de3092d03b742f3b2b88cf6fe0b09d0'

Upvotes: 16

Kai
Kai

Reputation: 37

If you are using SSMS, you can go to:

Tools - Options - Keyboard (under Environment)

  • type in 'comment' in the 'Show Commands containing:"
  • select Edit.CommentSelection
  • select 'Text Editor' under "Use new shortcut in:"
  • Assign a shortcut key that you like (ex: Ctrl + /) --> Assign --> Click Okay

If you want to uncomment then choose Edit.UncommentSelection and follow the step above, but it will need to be assigned to a different key other than Ctrl + /, may be use Ctrl+'

Step to change CommentSelection shortcut key

Upvotes: 2

Dircar V.
Dircar V.

Reputation: 393

/*
 SELECT * 
   FROM Academics
   WHERE Academic_id = 1
*/

Same as:

--SELECT * 
   --FROM Academics
   --WHERE Academic_id = 1

If you're working with SSMS, use CTRL + K, then press C for "comment" or U for "uncomment"

Upvotes: 23

IronAces
IronAces

Reputation: 1883

Documentation for how to comment out queries can be found Here.

But in short, press Ctrl + slash (/) together to toggle between commented/uncommented on highlight lines.

Ctrl + Shift + Slash can be used to comment/uncomment blocks of queries.

Upvotes: 3

Related Questions