Resultset column width in Management Studio

2019-06-15 03:26发布

Is there any way to alter the column width of a resultset in SQL Server 2005 Management Studio?

I have a column which contains a sentence, which gets cut off although there is screen space.

| foo | foo2 | description |          | foo | foo2 | description         |
|--------------------------|    TO    |----------------------------------|
|  x  |  yz  | An Exampl.. |          |  x  |  yz  | An Example sentence |

I would like to be able to set the column size via code so this change migrates to other SSMS instances with the code.

5条回答
何必那么认真
2楼-- · 2019-06-15 04:03

If you are only concerned about increasing the column width on the screen to view complete text within that column, you can do the following: -

1.) In the result set

2.) take your mouse over the column heading of the column you want to widen

3.) Using your left mouse button simply hold the line that divides two columns ( right one for the column you want to expand), and you will see your mouse cursor will change to adjustment mode (vertical black line with arrows moving out towards left and right). drag it towards the the right or left to increase or decrease the width respectively.

Just like we do it in excel, hold and drag.

查看更多
干净又极端
3楼-- · 2019-06-15 04:07

No, the width of each column is determined at runtime, and there is no way to override this in any version of Management Studio I've ever used. In fact I think the algorithm got worse in SQL Server 2008, and has been essentially the same ever since - you can run the same resultset twice, and the grid is inconsistent in the same output (this is SQL Server 2014 CTP2):

enter image description here

I reported this bug in 2008, and it was promptly closed as "Won't Fix":

Connect #356926 : SSMS : Grid alignment, column width seems arbitrary

If you want control over this, you will either have to create an add-in for Management Studio that can manhandle the results grid, or you'll have to write your own query tool.

Update 2016-01-12: This grid misalignment issue should be fixed in the latest builds of SQL Server 2016 (but the Connect item hasn't been updated yet).

查看更多
家丑人穷心不美
4楼-- · 2019-06-15 04:09

What you can do is alias the selected field like this:

SELECT name as [name        .] FROM ...

The spaces and the dot will expand the column width.

查看更多
Rolldiameter
5楼-- · 2019-06-15 04:17

How are you outputting - to text or to grid?

If to text, try this - In SSMS, go to Tools, then Options...

In Options, go to Query Results, then SQL Server. Select Results to Text and look at the Maximum Number of Characters Displayed in Each Column

See if that's set low, and if expanding it helps. You'll need to start a new query window when you make your change. Existing windows don't seem to pick up the changes.

查看更多
等我变得足够好
6楼-- · 2019-06-15 04:24

I also had this issue. My solution was to change the font that was displayed in the results grid from the default sans-serif non-monospace font to one that was monospace.

One may change the font used on the results grid this way:

  1. Navigate to the Tools -> Options... menu.
  2. Within the environment cascading menu, select "Fonts and Colors". A corresponding menu is displayed to the right.
  3. In the "Show Settings For" dropdown, select "Grid Results".
  4. Select a new font and font size that is monospace. I used consolas.
  5. Save your queries and exit Microsoft SQL Management Studio.
  6. Execute a query that outputs to the grid. Monospace fonts will have column widths generated properly.
查看更多
登录 后发表回答