SQL SERVER – SELECT TOP Shortcut in SQL Server Management Studio (SSMS)

This is tool is pretty old, yet always comes as a handy tip. I had a great trip at TechEd in India. And, during one of my presentations, I was asked if there are any shortcuts to SELECT only TOP 100 records from SSMS.

I immediately told him that if he explores the table in SSMS, he can just right click on it and SELECT TOP 1000 records. If he wanted only 100 records, then he could edit that 1000 to 100 by means of going to Options.

SQL SERVER - SELECT TOP Shortcut in SQL Server Management Studio (SSMS) shortcut1

Go to Options, then hover the mouse over the SQL Server Object Explorer, then proceed to Commands. Afterwards, change the Value for Select Top <n> Audit Records.

After narrating the steps, he told me that he was not looking for the right click option; rather he was asking if there is any kind of keyboard shortcut for convenience’s sake.

Actually, a keyboard shortcut is also possible. SQL Server Management Studio (SSMS) lets you configure the settings you want using a shortcut. Here is how you can do it.

Go to Options, then to Environment. Proceed to Keyboard, and from there, configure your T-SQL with the desired keyword.

SQL SERVER - SELECT TOP Shortcut in SQL Server Management Studio (SSMS) shortcut2

Now, open SSMS New Query Window, and then click and type in any table name.  After that, just hit the shortcut you just made earlier. Doing this should display TOP 100 records in the Result window.

SQL SERVER - SELECT TOP Shortcut in SQL Server Management Studio (SSMS) shortcut3

I am sure this trick is quite old, but it is still helpful to many.

Reference: Pinal Dave (https://blog.sqlauthority.com)

Previous Post
SQL SERVER – What is Spatial Database? – Developing with SQL Server Spatial and Deep Dive into Spatial Indexing
Next Post
SQL SERVER – Find Most Active Database in SQL Server – DMV dm_io_virtual_file_stats

Related Posts

No results found.

30 Comments. Leave new

  • Akash Bavlecha
    April 17, 2010 9:21 am

    Thanks Pinal,

    This is what i was looking for.

    Reply
  • Thats help full. Thanks.

    Question:
    In ssms, I saw that for some of the clients there is a option to create a project but for some there isn’t? I am not sure if there is a edition difference. If so what are all the editions provides us an option to create a solution.

    Thanks for all the help.

    Reply
  • Excellent short cut.

    I know about Alt + F1 only. and was believe that this is only by default option.

    Thanks for sharing this info.

    Tejas

    Reply
  • Nice tip, this would be really helpful if one needs to frequently audit/check a certain table for records.

    Reply
  • This is great! Thanks for sharing this. I am a big fan of tips like this.

    Reply
  • Pinal,
    It was fantastic…I have implemented it…

    Keep posting these tricks..

    Thanks,
    Niitn Sharma

    Reply
  • Does anyone know how to edit the statement? I would like to get the top 1000 rows , but ordered by the primary key descending. This way, the newest records will be displayed first. This would be especially handy for history tables.

    Thanks
    curio

    Reply
  • Nice tip.Keep posting these tricks..

    Reply
  • Can this be down in SSMS 2005 as well? I don’t have the SQL Server Object Explorer Node when I go to options. Thanks!

    Reply
  • Yaa !! really nice

    Reply
  • Yeah, I dont see SQL Server Object Explorer Node when I go to options in SSMS 2005…..How do we proceed in this case??

    Reply
  • I also can’t see the SQL Server Object Explorer option in options – also in SSMS 2005. Any updates on this? Thanks

    Reply
  • Depend on what sql version you using..

    Reply
  • sorry i mean edition of sql server. Its available in 2005 and 2008 as well if its developer or enterprise(these two I am using)

    Reply
  • Hi curio,
    to get the top 1000 rows , ordered by the primary key descending

    Type the below in query window and Click Cntrl + 3
    AgreementTable order by AgreementID desc

    Reply
  • Great Tip, Thank U very much

    Reply
  • Hi
    How is the selected text is passed to the SP
    ex:
    I have this SP
    ALTER PROC [dbo].[sp_MyQuickQueries] @QryId VARCHAR(30), @tbl VARCHAR (128)
    and different CTRL-? use different @QryId so that I only have ONE proc instead of having one proc per shortcut key.

    For CTRL-5 I assigned
    dbo.sp_MyQuickQueries ‘COLUMNS_ORDERBY_NAME’, <– notice comma at end. I expected that SSMS would add the selected text after the comma but no.

    In my SP I have several IF like this
    IF @QryId = 'COLUMNS_ORDERBY_NAME' Begin

    The SP works well when called directly.
    But not from a shortcut key.
    I get error

    Msg 102, Level 15, State 1, Line 1
    Incorrect syntax near 'MYTABLE'.
    MYTABLE beeing the selected text when i hit CTRL-5

    Any idea ?

    Reply
  • Ronaldo Brisola
    May 25, 2012 1:03 am

    Hi!
    This is a very useful tip.

    But I’m trying to find a way to create a shortcut to open a script file.
    Does anybody know a tip for this?

    Thank you.

    Reply
  • nice bolg dear … it is beneficiary for people …

    Reply
  • Thank you for the useful tip Pinal.

    Reply

Leave a Reply

Menu