?
Solved

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

Posted on 2010-03-25
5
Medium Priority
?
1,950 Views
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.
0
Comment
Question by:sedwardson
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:rbeadie
ID: 28602456
Try using row_number instead of TOP:

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

Author Comment

by:sedwardson
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  ******/
SELECT TOP 1000 [JobID]
      ,[MarketID]
      ,[CountryCode]
      ,[AccountNumber]
      ,[IssueNumber]
      ,[Status]
      ,[KeyRef]
      ,[Reference]
      ,[Position]
      ,[Skills]
      ,[Location]
      ,[StartDate]
      ,[Duration]
      ,[Contact]
      ,[Telephone]
      ,[Fax]
      ,[Email]
      ,[KeyLocations]
      ,[JobType]
      ,[Rate]
      ,[DatePosted]
      ,[URL]
      ,[JBEIssueNumber]
  FROM [Jobs].[dbo].[tJob]

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

Expert Comment

by:rbeadie
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.
0
 
LVL 41

Accepted Solution

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

Author Closing Comment

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

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