How do I change the default SELECT TOP 1000 query to use * instead of each field?
In SSMS 2008 R2, we have the default Select top 1000 and Edit top 200 queries from the right click menu. I've seen where you can change the # of rows it returns in the options.
What I'm after is, can I tell it to do a SELECT * instead of expanding and including every field?
It's not a performance issue or anything, just an annoyance when querying tables with more than about 5 fields, I'd like do a select *.
For example, if I have a table with the following fields:
- FirstName
- LastName
- Birthday
- City 开发者_JS百科
- State
- Zip
When I right click on this Persons table and choose the "SELECT TOP 1000 ROWS" Menu, I'd like the query that is run to be
SELECT TOP 1000 * FROM People
and NOT
SELECT TOP 1000 FirstName, LastName, Birthday, City, State, Zip FROM People
EDIT I suspect there isn't really an answer to this, but thought I'd see if anyone figured it out.
I don't believe there is any way of customising the native SSMS functionality. However you can use the SSMS tools pack addin "Custom Scripts" for this type of thing.
(Though to be honest Selecting the columns and typing *
might be as quick as navigating the menu)
Why would the developers of SSMS want to encourage a poor practice. Since select * is a very poor practice indeed, why would they want to encourage it?
I can see not wanting to write all the fields in a quick non-production query but since it is doing that for you, why would you not want it do do it correctly?
It's against best practice so SSMS won't do it.
Your best bet is either to delete the specific columns and replace with *
, or just leave it as it is considering the default is to select all the columns for you anyway...
Putting the cursor after the TOP n
and doing Ctrl-Shift-End
, Shift-Up
, *
doesn't take ages, but I do understand that when you're testing it makes very little difference to use *
over the full column specification and it keeps everything tidier.
If you combine SSMS Tools Pack with SSMS IntelliSense you could probably make it quicker to type than to scroll, right-click and select.
精彩评论