SQL Server Management Studio小技巧

SQL Server Troubleshooting Tips and Tricks

From SQLServerPedia:http://sqlserverpedia.com/wiki/SQL_Server_Troubleshooting_Tips_and_Tricks 

Jump to: navigation, search

SQL Server Tweaks and Tools That Make a DBA’s Life Easier

This article shares some of the tweaks and tools that can make the job of a SQL Server database administrator (DBA) easier. You’ll find tips for all of the following:

Contents

<script type="text/javascript"></script>

Indexes

If you use “included” columns, you know the frustration associated with figuring out which columns are included. The following stored procedures can help:

  • sp_helpindex – A system stored procedure that reports information about the indexes on a table or view
  • sp_helpindex2 – A rewrite of the sp_helpindex stored procedure, written by Kimberly Tripp
  • dba_indexLookup_sp – A custom, non-system stored procedure, written by Michelle Ufford

Take a look at all of these and use the one best meets your needs.

Keyboard Shortcuts

To choose a keyboard scheme, in SQL Server Management Studio (SSMS), select Tools | Options… | Environment | Keyboard.

Keyboard Shortcuts

Keyboard Shortcuts


The “Standard” keyboard scheme has the following shortcuts by default:

Alt+F1  sp_help
Ctrl+1   sp_who
Ctrl+1   sp_lock

Here are some suggestions for additional shortcuts:

Ctrl+3   Select Top 100 * From
Ctrl+4   sp_tables @table_owner = ‘dbo’
Ctrl+5   sp_columns
Ctrl+6   sp_stored_procedures @sp_owner = ‘dbo’
Ctrl+7   sp_spaceused
Ctrl+8   sp_helptext
Ctrl+9   dba_indexLookup_sp or sp_helpindex2

Please note that any changes you make to these settings will not take effect until you open a new query window. Here’s an example of how you could use these shortcuts:

  1. Use Ctrl+4 to find a list of tables.
  2. Copy one into your query window.
  3. Highlight the table name (I usually double-click on it) and press Ctrl+3 to view a sample of that table’s data.

You may want to remove or change the schema filters if you use schemas other than dbo.

Query Execution Settings

SMSS offers advanced settings to help prevent unintentional issues in production environments, such as a query that causes locking or blocking. To access these options in SSMS, choose Tools | Options… | Query Execution | SQL Server | Advanced.

Query Execution Settings

Query Execution Settings


Some suggestions include:

  • Change “SET TRANSACTION ISOLATION LEVEL” to “READ UNCOMMITTED.” This will minimize the impact of your ad-hoc queries by allowing dirty reads. While this can be beneficial for many production environments, make sure to understand the implications of this setting before implementing.
  • Change “SET DEADLOCK_PRIORITY” to “Low.” This will tell SQL Server to select your session as the victim in the event of a deadlock.
  • Change “SET LOCK TIMEOUT” to a smaller, defined value, such as 30000 milliseconds (30 seconds). By default, SQL Server will wait forever for a lock to be released. By specifying a value, SQL Server will abort after the specified timeout period when a lock is encountered.

You can also make these same setting changes in Visual Studio.

Copy Behavior

This tip is not specific to SQL Server; it’s useful for any Microsoft product. Holding down “Alt” while you drag your mouse will change your selection behavior to block selection. Block Selection

Block Selection

 

Object Detail Explorer

One of the great updates available in SQL Server 2008 is the Object Detail Explorer. For example, you can quickly find the table size and row counts of all the tables in a particular database. The Object Detail Explorer requires SQL 2008 Management Studio, but you can connect SQL 2008 SSMS to a 2005 instance. Note: If these options are not visible, right-click the column headers and add them to the display.

Object Detail Explorer

Object Detail Explorer

 

Missing Indexes

If you use SSMS 2008 to execute Display Estimated Query Plan (Ctrl+L), it will show whether you’re missing any indexes. This will even work if you connect SSMS 2008 to SQL 2005.

Missing Index

Missing Index

Author Credits

Michelle Ufford

This wiki article was adapted from a blog post by Michelle Ufford.

Michelle is a SQL Developer DBA for GoDaddy.com, where she works with high-volume, mission-critical databases. She has over a decade of experience in a variety of technical roles and has worked with SQL Server for the last 5 years. She enjoys performance tuning and maintains an active SQL Server blog.

Her online presences include:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值