SQL SERVER – Demo Script – Keeping CPU Busy

Posted by pinaldave on SQL Authority See other posts from SQL Authority or by pinaldave
Published on Thu, 03 Mar 2011 01:30:33 +0000 Indexed on 2011/03/03 7:27 UTC
Read the original article Hit count: 545

Recently face very interesting situation, during presentations at event, I was asked very famous questions:

“My CPU is very high all the time, how can I reduce it?”

This is very interesting question and there are many answers and a single blog post is not good enough to justify this subject. I presented few situation to the person who asked the question. The member of the audience who asked question came to me afterwords and asked me few detailed questions. To answer him, I quickly wrote query which simulate high CPU. Here is the script which I wrote which increased CPU from 10% to 80%. I was wondering if there is any similar script which can simulate high CPU usage. If you have share with me and I will publish with due credit.

Here is my script for the same:

USE AdventureWorks
GO
DECLARE @Flag INT
SET
@Flag = 1
WHILE(@Flag < 1000)
BEGIN
ALTER INDEX
[PK_SalesOrderDetail_SalesOrderID_SalesOrderDetailID]
ON [Sales].[SalesOrderDetail] REBUILD
SET @Flag = @Flag + 1
END
GO

 

Reference: Pinal Dave (http://blog.SQLAuthority.com)


Filed under: Pinal Dave, PostADay, SQL, SQL Authority, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, T SQL, Technology

© SQL Authority or respective owner

Related posts about Pinal Dave

Related posts about PostADay