Productivity Keyboard Shortcuts 2

  • a shortcut to a proc you might find useful, a quick way to show index details for a table, including rowcount, size etc:

    USE [master]

    go

    create procedure [dbo].[sp_gettableindexinfo]

    @objname nvarchar(776) = NULL

    as

    begin

    set nocount on

    SELECT s.name AS 'schema',

    o.name AS 'table',

    i.name AS indexname,

    i.type_desc,

    p.data_compression_desc,

    fg.name as FileGroup,

    replace(CONVERT(varchar, CAST(p.rows AS money), 1),'.00','') as rows,

    i.is_unique,

    i.is_primary_key,

    i.is_unique_constraint,

    i.is_disabled,

    i.has_filter,

    i.filter_definition,

    CASE

    WHEN ps.usedpages > ps.pages THEN ( ps.usedpages - ps.pages )

    ELSE 0

    END * 8 indexsizekb,

    CASE

    WHEN ps.usedpages > ps.pages THEN ( ps.usedpages - ps.pages )

    ELSE 0

    END * 8 / 1024 indexsizemb

    FROM sys.indexes i (nolock)

    left JOIN sys.data_spaces ds (nolock)

    ON ds.data_space_id = i.data_space_id

    LEFT OUTER JOIN sys.filegroups fg (nolock)

    ON fg.data_space_id = ds.data_space_id

    INNER JOIN sys.objects o (nolock)

    ON o.object_id = i.object_id

    LEFT JOIN sys.schemas s (nolock)

    ON o.schema_id = s.schema_id

    LEFT JOIN sys.partitions p (nolock)

    ON i.index_id = p.index_id

    AND i.object_id = p.object_id

    INNER JOIN (SELECT object_id,

    index_id,

    SUM (used_page_count) usedpages,

    SUM (CASE

    WHEN ( index_id < 2 ) THEN (

    in_row_data_page_count + lob_used_page_count

    +

    row_overflow_used_page_count )

    ELSE lob_used_page_count +

    row_overflow_used_page_count

    END) pages

    FROM sys.dm_db_partition_stats (nolock)

    GROUP BY object_id,

    index_id) ps

    ON i.index_id = ps.index_id

    AND i.object_id = ps.object_id

    WHERE 1 = 1

    AND o.type not in ( 's' , 'it')

    and o.object_id =object_id(@objname)

    order by CASE

    WHEN ps.usedpages > ps.pages THEN ( ps.usedpages - ps.pages )

    ELSE 0

    END * 8 desc

    ;

    end

    create SSMS shortcut to sp_gettableindexinfo

  • Hi hdt

    I will try to add it under ctrl+7 as i didn't have idea for it.

    Thanks,

  • ---

  • Latest version here:https://goo.gl/ggCkh7

  • This will be quite handy but I am getting error when I try any of the shortcuts for one of my existing tables:

    Msg 102, Level 15, State 1, Line 1

    Incorrect syntax near '.'.

    Any Idea ?

  • If you are including schema in the selection it has to be in quotes, also make sure at the end of shortcut you have comma.

  • Thanks ! Works with the quotes.

  • Thanks for the additional shortcuts.

  • Does the SP need to executed on every server for these shortcuts to work?

  • Yes it does

  • Got this last year from you. Still a great set of shortcuts.

  • Iwas Bornready (8/11/2016)


    Got this last year from you. Still a great set of shortcuts.

    Thank you Iwas,

    Really appreciate the feedback 🙂 I've updated it recently fixing some minor things.

  • This is an excellent set of scripts that I use daily!

    I'm having problems with CTRL+8 finding a column name that contains an underscore which is a wildcard character.  Is there a way to modify this so that I can search for column names containing an underscore?

    Thanks,

    Greg

  • In case anyone wants to use this for Azure Data Studio, you just have to follow the below steps.

    File | Preferences | Settings

    Type "shortcut" into the search bar to show Shortcut3 thru Shortcut9.

    Paste the below line for each shortcut swapping out the 3 with whichever shortcut# you're on

    So, for "SQL > Query: Shortcut3" paste the following:

    DECLARE @DB NVARCHAR(500) SET @DB = DB_NAME() EXEC master.dbo.Shortcuts 3, @DB,

    After Shortcuts 3 thru 9 are done then go to

    File | Preferences | Keyboard Shortcuts

    1. Type “ctrl 3” and then right-click the stock “workbench.action.focusThirdEditorGroup” item and “Remove Keybinding
    2. Type “shortcut3” and then right-click the (just-created) “workbench.action.query.shortcut3” item and “Add Keybinding” then type “CTRL + 3” and hit enter
    3. Repeat for CTRL+4, CTRL+5,…,CTRL+9

    You may want to backup your settings.json file in case you want to do this again on a new computer.

  • In case anyone wants to use this for Azure Data Studio, you just have to follow the below steps.

    File | Preferences | Settings

    Type "shortcut" into the search bar to show Shortcut3 thru Shortcut9.

    Paste the below line for each shortcut swapping out the 3 with whichever shortcut# you're on

    So, for "SQL > Query: Shortcut3" paste the following:

    DECLARE @DB NVARCHAR(500) SET @DB = DB_NAME() EXEC master.dbo.Shortcuts 3, @DB,

    After Shortcuts 3 thru 9 are done then go to

    File | Preferences | Keyboard Shortcuts

    1. Type “ctrl 3” and then right-click the stock “workbench.action.focusThirdEditorGroup” item and “Remove Keybinding
    2. Type “shortcut3” and then right-click the (just-created) “workbench.action.query.shortcut3” item and “Add Keybinding” then type “CTRL + 3” and hit enter
    3. Repeat for CTRL+4, CTRL+5,…,CTRL+9

    You may want to backup your settings.json file in case you want to do this again on a new computer.

Viewing 15 posts - 16 through 30 (of 31 total)

You must be logged in to reply to this topic. Login to reply