How can I change the Select Top <N> Rows command in SQL SMS 2008

Posted on 2010-03-25
Medium Priority
Last Modified: 2012-06-21
How can I change the Select Top <N> Rows command in SQL SMS 2008.  I know that I can change the amount or rows that it returns under tools - options - SQL Server Object Explorer, but what I would like to do is instead of it running the script and putting in all the column names, just simply put a * in instead.  Like this:
/****** Script for SelectTopNRows command from SSMS  ******/
SELECT TOP 1000 * FROM etc etc

This way I dont get a whole list of column names running down my page.  All and any help is as always much appreciated.
Question by:sedwardson
  • 2
  • 2

Expert Comment

ID: 28602456
Try using row_number instead of TOP:

select *, row_number() over( order by MyID) MyRowNumber
from MyTable
) T1
WHERE T1.MyRowNumber <= 1000

Author Comment

ID: 28603132
thanks for the reply rbeadie but I obviously didnt make my self clear.  The function comes from right clicking on the table and it automatically writes the query for you.  I want to edit this automated query so that it still pulls all the columns into the query but does not display them like this:
/****** Script for SelectTopNRows command from SSMS  ******/
  FROM [Jobs].[dbo].[tJob]

I want the query to output like this:
SELECT TOP 1000 * FROM [Jobs].[dbo].[tJob]

Expert Comment

ID: 28603890
Ah -- sorry.  I understand your question now.  I'm not sure that you can change that functionality.  You can change the number of rows that is your default, but there are limited changes you can make to the ssms generated scripts.
LVL 41

Accepted Solution

Sharath earned 750 total points
ID: 28607036
You cannot change that. Thats a functionality provided to get the top 1000 records.

Author Closing Comment

ID: 31707293
Guess I'll just have to put up with it then :-)  Thanks for the replies

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.

593 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question