Search

SSMS : SELECT TOP n ROWS should have correct database context by aaronbertrand

Resolved
as Won't Fix Help for as Won't Fix

10
0
Sign in
to vote
Type: Suggestion
ID: 684247
Opened: 8/15/2011 6:28:15 PM
Access Restriction: Public
0
Workaround(s)
If I right-click a table and choose "SELECT TOP n ROWS" I get a query window connected to master (or whatever my default database is) that reads like this:

SELECT TOP 1000
...cols...
FROM [database].[schema].[table]

Never mind that there is no ORDER BY or statement terminator (some long-term pet peeves of mine), but why can't it avoid the database prefix and put in the right database? It should come out as:

USE [database];
GO
SELECT TOP 1000
...cols...
FROM [schema].[table]

This is roughly what happens when I choose Script Table as > SELECT To > New Query Editor Window in Denali CTP3 (except it doesn't put the useless and ambiguous TOP in there) and in 2008 R2 SP1 (where the database prefix is still there, for some reason). Why can't these two functions share some code?

As it stands, if I generated the select using SELECT TOP n ROWS, I have to do a bunch of work to use that query as a starting point. I either need to change database context and/or add the database prefix to every new object I add to the query or, more likely, if I am developing a stored procedure or view, I am probably going to have to change database context *and* remove the database prefix from the table name.
Details (expand)

Product Language

English

Category

Tools (SSMS, Agent, Profiler, Migration, etc.)

Proposed Solution

Make the SELECT TOP n ROWS functionality behave more like the scripting option by launching the new query window with the correct database context and without the database prefix on the object name.

Also, can you make 2008 R2's script table option work like Denali's, where the database prefix isn't needlessly added to the object name? The database drop-down is set to the correct database and there is a USE statement; the object doesn't need to be 3-part named on top of all that.

Primary Benefit

Faster Development

Other Benefits

 
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 10/14/2011 at 2:16 AM
Hello,

Thanks for reporting this issue. We triaged this along with the other bugs for our next major release, but unfortunately it did not meet the bar for fixing. I'm resolving this bug as won't fix for now. However, the DCR suggestion will be kept in our bug DB, and will be revisited the next time we make investment in this feature.

Please feel free to get in touch with me if you have any concerns.

Thanks,
Prashant Choudhari
(prashant.choudhari@microsoft.com)
Posted by aaronbertrand on 8/15/2011 at 6:28 PM
This connect item inspired by the following StackOverflow question:

http://stackoverflow.com/questions/7072575/sql-server-management-studio-connection-defaults-to-master-when-selecting-a-dat/7072607#7072607
Sign in to post a workaround.