<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8086266974135964284</id><updated>2024-09-26T21:20:53.371-04:00</updated><category term="SQL Server 2005"/><category term="SQL Server 2008"/><category term="SQL Server"/><category term="Aggregate Function"/><category term="Examples"/><category term="HRESULT: 0xC0010014"/><category term="Triggers"/><category term="using sp_spaceused"/><title type='text'>T-SQL &amp;amp; SQL Server</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://sqlserverrevolution.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8086266974135964284/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://sqlserverrevolution.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>10</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8086266974135964284.post-1257093915746084162</id><published>2011-06-22T22:08:00.001-04:00</published><updated>2011-06-22T22:19:21.309-04:00</updated><title type='text'>Suppressing/Bypassing Triggers in SQL Server 2005 onwards</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;Sometimes being DBA you need to perform&amp;nbsp;certain&amp;nbsp;activities where we do not want that triggers should fire. for example in most of the cases where we are doing some kind of datafix we do not want unnecessary audit data generated. When we are not working in 24/7 environment its very easy we can drop/disable&amp;nbsp;the trigger in off hours and then do the operation, but in 24/7 environment you do not have this luxury. So we need a mechanism to bypass the trigger action. In SQL server this action can be performed by utilizing CONTEXT_INFO session level setting. Let&#39;s take a UPDATE trigger example from one of my &lt;a href=&quot;http://sqlserverrevolution.blogspot.com/2011/06/performing-unit-tests-on-triggers.html&quot;&gt;previous&lt;/a&gt;&amp;nbsp;post.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;We can modify the update trigger as shown below.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ALTER TRIGGER update_trigger&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ON trigger_test1&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FOR UPDATE AS&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;BEGIN&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;IF CONTEXT_INFO() = 0x545&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;          &lt;/span&gt;RETURN&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;UPDATE a&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;SET value2= i.value1*2&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;FROM trigger_test1 a&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;JOIN INSERTED i&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;ON a.id = i.id&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;END&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;GO&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;Now If I want to perform UPDATE on the trigger_test1 table and I do not want trigger to fire, the only thing I need to do is to put SET CONTEXT_INFO statement in the beginning.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SET CONTEXT_INFO 0x545&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; UPDATE trigger_test1 SET value1 = 30 WHERE ID = 5&lt;br /&gt;
&lt;br /&gt;
If You want to know how to perform testing on triggers then go through this &lt;a href=&quot;http://sqlserverrevolution.blogspot.com/2011/06/performing-unit-tests-on-triggers.html&quot;&gt;article&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverrevolution.blogspot.com/feeds/1257093915746084162/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverrevolution.blogspot.com/2011/06/suppressingbypassing-triggers-in-sql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8086266974135964284/posts/default/1257093915746084162'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8086266974135964284/posts/default/1257093915746084162'/><link rel='alternate' type='text/html' href='http://sqlserverrevolution.blogspot.com/2011/06/suppressingbypassing-triggers-in-sql.html' title='Suppressing/Bypassing Triggers in SQL Server 2005 onwards'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8086266974135964284.post-7813075649960794086</id><published>2011-06-22T21:50:00.001-04:00</published><updated>2011-06-22T22:21:02.605-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2005"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2008"/><category scheme="http://www.blogger.com/atom/ns#" term="Triggers"/><title type='text'>Performing Unit Tests on Triggers</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;Testing triggers from DB side or how to do unit testing of triggers without even going on the&amp;nbsp;front-end.&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;People often ask me that without having real world data, how can we test these. The answer is that for performing any kind of unit testing we do not require to actually commit the data that we are playing with.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;So in this article I will talk about how to perform a unit test for INSERT, DELETE and UPDATE triggers without even actually creating extra data/modifying existing data. For achieving the end result I am going to use TRANSACTION CONTROL (BEGINTRAN /ROLLBACK) and NOLOCK dirty read concept. Also I here I am just talking about method so my test cases very straight forward; but how much complicated the triggers are these&amp;nbsp;approaches&amp;nbsp;would work.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;To explain how to perform unit test case for each action, I am going to use below two tables and trigger scripts. I have also included the script to populate the data.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;-- main table&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;CREATE TABLE trigger_test1&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;(&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;        &lt;/span&gt;id int primary key,&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;        &lt;/span&gt;value1 int,&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;        &lt;/span&gt;value2 int&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;)&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;-- audit table&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&amp;nbsp; &amp;nbsp;CREATE TABLE trigger_test2&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;(&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;        &lt;/span&gt;id int,&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;        &lt;/span&gt;value1 int,&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;       &lt;/span&gt;value2 int&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;)&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;-- INSERT trigger&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;CREATE TRIGGER insert_trigger&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;ON trigger_test1&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;FOR INSERT AS&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;BEGIN&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;UPDATE a&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;SET value2= i.value1*2&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;FROM trigger_test1 a&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;JOIN INSERTED i&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;ON a.id = i.id&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;END&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;GO&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;-- UPDATE trigger&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;CREATE TRIGGER update_trigger&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;ON trigger_test1&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;FOR UPDATE AS&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;BEGIN&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;UPDATE a&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;SET value2= i.value1*2&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;FROM trigger_test1 a&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;JOIN INSERTED i&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;ON a.id = i.id&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;END&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;GO&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;-- DELETE trigger&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;CREATE TRIGGER delete_trigger&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;ON trigger_test1&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;FOR DELETE AS&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;BEGIN&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;INSERT INTO trigger_test2&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;SELECT * FROM DELETED&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;END&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;GO&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;--inserting test values&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;INSERT INTO trigger_test1 (id, value1) SELECT 1,10&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;INSERT INTO trigger_test1 (id, value1) SELECT 2,10&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;INSERT INTO trigger_test1 (id, value1) SELECT 3,10&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;INSERT INTO trigger_test1 (id, value1) SELECT 4,10&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;INSERT INTO trigger_test1 (id, value1) SELECT 5,10&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;GO&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;b&gt;INSERT trigger test method&lt;/b&gt;:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;Following script can be used for performing INSERT test case.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
BEGIN TRAN&lt;br /&gt;
&lt;br /&gt;
/* to check initial state of the data&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;(you can have where condition as per your requirement)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;HERE having &quot;nolock&quot; is important to make&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;a dirty read within transaction&lt;br /&gt;
*/&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;SELECT * FROM trigger_test1 with (nolock) WHERE ID = 6&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;INSERT INTO trigger_test1 (id, value1) SELECT 6,60&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;SELECT * FROM trigger_test1 with (nolock) WHERE ID = 6&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
ROLLBACK&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;b&gt;DELETE trigger test method&lt;/b&gt;:&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;Following script can be used for performing DELETE test case.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;BEGIN TRAN&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;SELECT &#39;trigger_test1&#39;,* FROM trigger_test1 with (nolock) WHERE ID = 5&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;SELECT &#39;trigger_test2&#39;,* FROM trigger_test2 with (nolock) WHERE ID = 5&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;DELETE FROM trigger_test1 &amp;nbsp;WHERE ID = 5&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;SELECT &#39;trigger_test1&#39;,* FROM trigger_test1 with (nolock) WHERE ID = 5&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;SELECT &#39;trigger_test2&#39;,* FROM trigger_test2 with (nolock) WHERE ID = 5&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;ROLLBACK&lt;/div&gt;&lt;div style=&quot;font-size: x-large;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;b&gt;UPDATE trigger test method&lt;/b&gt;:&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;Following script can be used for performing UPDATE test case.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;BEGIN TRAN&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;SELECT * FROM trigger_test1 with (nolock) WHERE ID = 5&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;UPDATE trigger_test1 SET value1 = 30 WHERE ID = 5&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;SELECT * FROM trigger_test1 with (nolock) WHERE ID = 5&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;ROLLBACK&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;Finally suppose if we happen to have &lt;b&gt;both INSERT and DELETE&lt;/b&gt; triggers implemented then these both can be tested through one SQL as depicted below. This approach is also has two more benefits that you can use existing data sitting within same table for INSERT trigger testing. The trick is to USE temporary table.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;BEGIN TRAN&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;SELECT &#39;trigger_test1&#39;,* FROM trigger_test1 with (nolock) WHERE ID = 5&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;SELECT &#39;trigger_test2&#39;,* FROM trigger_test2 with (nolock) WHERE ID = 5&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;SELECT * INTO #tmp FROM trigger_test1 &amp;nbsp;WHERE ID = 5&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;DELETE FROM trigger_test1 &amp;nbsp;WHERE ID = 5&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;INSERT INTO trigger_test1 &amp;nbsp;SELECT * FROM #tmp&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;SELECT &#39;trigger_test1&#39;,* FROM trigger_test1 with (nolock) WHERE ID = 5&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;SELECT &#39;trigger_test2&#39;,* FROM trigger_test2 with (nolock) WHERE ID = 5&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;DROP TABLE #tmp&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;ROLLBACK&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverrevolution.blogspot.com/feeds/7813075649960794086/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverrevolution.blogspot.com/2011/06/performing-unit-tests-on-triggers.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8086266974135964284/posts/default/7813075649960794086'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8086266974135964284/posts/default/7813075649960794086'/><link rel='alternate' type='text/html' href='http://sqlserverrevolution.blogspot.com/2011/06/performing-unit-tests-on-triggers.html' title='Performing Unit Tests on Triggers'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8086266974135964284.post-3752978221803836376</id><published>2011-06-13T22:48:00.000-04:00</published><updated>2011-06-13T22:48:27.225-04:00</updated><title type='text'>RESTORE Arguments - SQL Server Backup</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;b&gt;RESTORE HEADERONLY&lt;/b&gt;. This statement provides details regarding the backup&amp;nbsp;database and returns all the backup&#39;s header information.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;b&gt;RESTORE LABELONLY&lt;/b&gt;. This statement returns a result set containing&amp;nbsp;information about the backup media on which the backup is stored. The output of this statement includes only&amp;nbsp;partial header information.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;b&gt;RESTORE VERIFYONLY&lt;/b&gt;. This statement verifies whether the backup&amp;nbsp;data is complete.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;b&gt; RESTORE FILELISTONLY&lt;/b&gt;. This statement returns a list of data files and log&amp;nbsp;files in the backup.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverrevolution.blogspot.com/feeds/3752978221803836376/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverrevolution.blogspot.com/2011/06/restore-arguments-sql-server-backup.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8086266974135964284/posts/default/3752978221803836376'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8086266974135964284/posts/default/3752978221803836376'/><link rel='alternate' type='text/html' href='http://sqlserverrevolution.blogspot.com/2011/06/restore-arguments-sql-server-backup.html' title='RESTORE Arguments - SQL Server Backup'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8086266974135964284.post-307199002096898251</id><published>2011-05-13T22:28:00.001-04:00</published><updated>2011-06-13T22:35:44.899-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2005"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2008"/><title type='text'>sp_help_jobactivity - Check Run Time Job Activity</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;sp_help_jobactivity system stored&amp;nbsp;procedure provides information about the runtime state of SQL Server Agent jobs. This SP can be executed to check state of particular Job by passing value to either @job_id or @job_name parameter.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;This SP has following parameters&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoNormalTable&quot; style=&quot;border-collapse: collapse; margin-left: 4.65pt; width: 281px;&quot;&gt;&lt;tbody&gt;
&lt;tr style=&quot;height: 15.75pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;&quot;&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border: solid windowtext 1.0pt; height: 15.75pt; mso-border-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 128.0pt;&quot; valign=&quot;bottom&quot; width=&quot;171&quot;&gt;   &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; mso-ascii-font-family: Calibri; mso-bidi-font-family: Calibri; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-hansi-font-family: Calibri;&quot;&gt;Parameter_name&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-left: none; border: solid windowtext 1.0pt; height: 15.75pt; padding: 0in 5.4pt 0in 5.4pt; width: 83.0pt;&quot; valign=&quot;bottom&quot; width=&quot;111&quot;&gt;   &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; mso-ascii-font-family: Calibri; mso-bidi-font-family: Calibri; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-hansi-font-family: Calibri;&quot;&gt;Type&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;height: 15.0pt; mso-yfti-irow: 1;&quot;&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-top: none; border: solid windowtext 1.0pt; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 128.0pt;&quot; valign=&quot;bottom&quot; width=&quot;171&quot;&gt;   &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; mso-ascii-font-family: Calibri; mso-bidi-font-family: Calibri; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-hansi-font-family: Calibri;&quot;&gt;@job_id&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 83.0pt;&quot; valign=&quot;bottom&quot; width=&quot;111&quot;&gt;   &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; mso-ascii-font-family: Calibri; mso-bidi-font-family: Calibri; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-hansi-font-family: Calibri;&quot;&gt;uniqueidentifier&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;height: 15.0pt; mso-yfti-irow: 2;&quot;&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-top: none; border: solid windowtext 1.0pt; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 128.0pt;&quot; valign=&quot;bottom&quot; width=&quot;171&quot;&gt;   &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; mso-ascii-font-family: Calibri; mso-bidi-font-family: Calibri; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-hansi-font-family: Calibri;&quot;&gt;@job_name&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 83.0pt;&quot; valign=&quot;bottom&quot; width=&quot;111&quot;&gt;   &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; mso-ascii-font-family: Calibri; mso-bidi-font-family: Calibri; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-hansi-font-family: Calibri;&quot;&gt;sysname&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;height: 15.0pt; mso-yfti-irow: 3; mso-yfti-lastrow: yes;&quot;&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-top: none; border: solid windowtext 1.0pt; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 128.0pt;&quot; valign=&quot;bottom&quot; width=&quot;171&quot;&gt;   &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; mso-ascii-font-family: Calibri; mso-bidi-font-family: Calibri; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-hansi-font-family: Calibri;&quot;&gt;@session_id&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 83.0pt;&quot; valign=&quot;bottom&quot; width=&quot;111&quot;&gt;   &lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black; mso-ascii-font-family: Calibri; mso-bidi-font-family: Calibri; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-hansi-font-family: Calibri;&quot;&gt;int&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;This SP can be used along with &lt;a href=&quot;http://sqlserverrevolution.blogspot.com/2011/06/sphelpjobhistory-check-failing-jobs.html&quot;&gt;sp_help_jobhistory&lt;/a&gt; to implement generic notification process for all Jobs.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverrevolution.blogspot.com/feeds/307199002096898251/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverrevolution.blogspot.com/2011/05/sphelpjobactivity-check-run-time-job.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8086266974135964284/posts/default/307199002096898251'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8086266974135964284/posts/default/307199002096898251'/><link rel='alternate' type='text/html' href='http://sqlserverrevolution.blogspot.com/2011/05/sphelpjobactivity-check-run-time-job.html' title='sp_help_jobactivity - Check Run Time Job Activity'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8086266974135964284.post-3287503653326365152</id><published>2011-05-13T22:21:00.000-04:00</published><updated>2011-06-13T22:22:02.823-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2005"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2008"/><title type='text'>sp_help_jobhistory - Check failing Jobs</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;sp_help_jobhistory system stored procedure is used to view the history of jobs. For checking the history of all&amp;nbsp;Jobs&amp;nbsp;we can execute below script.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
USE msdb;&lt;br /&gt;
GO&lt;br /&gt;
EXEC dbo.sp_help_jobhistory&lt;br /&gt;
GO&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;We can also execute this SP to check for only failing Jobs by providing @run_status parameter. Below SP call would provide the list of Jobs with steps details which failed to get execute.&amp;nbsp;Specifying a value of 0 for the @run_status parameter returns history for all failed jobs.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
USE msdb;&lt;br /&gt;
GO&lt;br /&gt;
EXEC dbo.sp_help_jobhistory&lt;br /&gt;
@run_status = 0;&lt;br /&gt;
GO&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;Specifying a value of 1 for the @run_status parameter returns history for all jobs that completed successfully.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;Specifying a value of 2 for the @run_status parameter returns history for all jobs steps that have a retry status.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;Specifying a value of 3 for the @run_status parameter returns history for all jobs that were canceled.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;This SP can also be executed with @Job_id /@Job_name parameters too to check for particular Job&#39;s history. If we do not pass any value to these parameters this SP runs for all Jobs.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;There are more parameters to this SP, which I don&#39;t think are that much handy then the above 3 described though I have provided the list of all parameters below.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoNormalTable&quot; style=&quot;border-collapse: collapse; margin-left: 4.65pt; width: 281px;&quot;&gt;&lt;tbody&gt;
&lt;tr style=&quot;height: 15.75pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;&quot;&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border: solid windowtext 1.0pt; height: 15.75pt; mso-border-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 128.0pt;&quot; valign=&quot;bottom&quot; width=&quot;171&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;Parameter_name&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-left: none; border: solid windowtext 1.0pt; height: 15.75pt; padding: 0in 5.4pt 0in 5.4pt; width: 83.0pt;&quot; valign=&quot;bottom&quot; width=&quot;111&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;Type&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;height: 15.0pt; mso-yfti-irow: 1;&quot;&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-top: none; border: solid windowtext 1.0pt; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 128.0pt;&quot; valign=&quot;bottom&quot; width=&quot;171&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;@job_id&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 83.0pt;&quot; valign=&quot;bottom&quot; width=&quot;111&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;uniqueidentifier&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;height: 15.0pt; mso-yfti-irow: 2;&quot;&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-top: none; border: solid windowtext 1.0pt; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 128.0pt;&quot; valign=&quot;bottom&quot; width=&quot;171&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;@job_name&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 83.0pt;&quot; valign=&quot;bottom&quot; width=&quot;111&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;sysname&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;height: 15.0pt; mso-yfti-irow: 3;&quot;&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-top: none; border: solid windowtext 1.0pt; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 128.0pt;&quot; valign=&quot;bottom&quot; width=&quot;171&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;@step_id&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 83.0pt;&quot; valign=&quot;bottom&quot; width=&quot;111&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;int&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;height: 15.0pt; mso-yfti-irow: 4;&quot;&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-top: none; border: solid windowtext 1.0pt; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 128.0pt;&quot; valign=&quot;bottom&quot; width=&quot;171&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;@sql_message_id&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 83.0pt;&quot; valign=&quot;bottom&quot; width=&quot;111&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;int&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;height: 15.0pt; mso-yfti-irow: 5;&quot;&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-top: none; border: solid windowtext 1.0pt; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 128.0pt;&quot; valign=&quot;bottom&quot; width=&quot;171&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;@sql_severity&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 83.0pt;&quot; valign=&quot;bottom&quot; width=&quot;111&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;int&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;height: 15.0pt; mso-yfti-irow: 6;&quot;&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-top: none; border: solid windowtext 1.0pt; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 128.0pt;&quot; valign=&quot;bottom&quot; width=&quot;171&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;@start_run_date&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 83.0pt;&quot; valign=&quot;bottom&quot; width=&quot;111&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;int&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;height: 15.0pt; mso-yfti-irow: 7;&quot;&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-top: none; border: solid windowtext 1.0pt; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 128.0pt;&quot; valign=&quot;bottom&quot; width=&quot;171&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;@end_run_date&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 83.0pt;&quot; valign=&quot;bottom&quot; width=&quot;111&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;int&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;height: 15.0pt; mso-yfti-irow: 8;&quot;&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-top: none; border: solid windowtext 1.0pt; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 128.0pt;&quot; valign=&quot;bottom&quot; width=&quot;171&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;@start_run_time&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 83.0pt;&quot; valign=&quot;bottom&quot; width=&quot;111&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;int&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;height: 15.0pt; mso-yfti-irow: 9;&quot;&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-top: none; border: solid windowtext 1.0pt; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 128.0pt;&quot; valign=&quot;bottom&quot; width=&quot;171&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;@end_run_time&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 83.0pt;&quot; valign=&quot;bottom&quot; width=&quot;111&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;int&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;height: 15.0pt; mso-yfti-irow: 10;&quot;&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-top: none; border: solid windowtext 1.0pt; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 128.0pt;&quot; valign=&quot;bottom&quot; width=&quot;171&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;@minimum_run_duration&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 83.0pt;&quot; valign=&quot;bottom&quot; width=&quot;111&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;int&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;height: 15.0pt; mso-yfti-irow: 11;&quot;&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-top: none; border: solid windowtext 1.0pt; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 128.0pt;&quot; valign=&quot;bottom&quot; width=&quot;171&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;@run_status&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 83.0pt;&quot; valign=&quot;bottom&quot; width=&quot;111&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;int&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;height: 15.0pt; mso-yfti-irow: 12;&quot;&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-top: none; border: solid windowtext 1.0pt; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 128.0pt;&quot; valign=&quot;bottom&quot; width=&quot;171&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;@minimum_retries&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 83.0pt;&quot; valign=&quot;bottom&quot; width=&quot;111&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;int&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;height: 15.0pt; mso-yfti-irow: 13;&quot;&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-top: none; border: solid windowtext 1.0pt; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 128.0pt;&quot; valign=&quot;bottom&quot; width=&quot;171&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;@oldest_first&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 83.0pt;&quot; valign=&quot;bottom&quot; width=&quot;111&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;int&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;height: 15.0pt; mso-yfti-irow: 14;&quot;&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-top: none; border: solid windowtext 1.0pt; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 128.0pt;&quot; valign=&quot;bottom&quot; width=&quot;171&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;@server&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 15.0pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext 1.0pt; padding: 0in 5.4pt 0in 5.4pt; width: 83.0pt;&quot; valign=&quot;bottom&quot; width=&quot;111&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;sysname&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style=&quot;height: 15.75pt; mso-yfti-irow: 15; mso-yfti-lastrow: yes;&quot;&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-top: none; border: solid windowtext 1.0pt; height: 15.75pt; mso-border-bottom-alt: solid windowtext 1.0pt; mso-border-left-alt: solid windowtext 1.0pt; mso-border-right-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 128.0pt;&quot; valign=&quot;bottom&quot; width=&quot;171&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;@mode&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td nowrap=&quot;&quot; style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; height: 15.75pt; padding: 0in 5.4pt 0in 5.4pt; width: 83.0pt;&quot; valign=&quot;bottom&quot; width=&quot;111&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;varchar&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverrevolution.blogspot.com/feeds/3287503653326365152/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverrevolution.blogspot.com/2011/06/sphelpjobhistory-check-failing-jobs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8086266974135964284/posts/default/3287503653326365152'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8086266974135964284/posts/default/3287503653326365152'/><link rel='alternate' type='text/html' href='http://sqlserverrevolution.blogspot.com/2011/06/sphelpjobhistory-check-failing-jobs.html' title='sp_help_jobhistory - Check failing Jobs'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8086266974135964284.post-1706402587200944592</id><published>2011-05-09T21:20:00.002-04:00</published><updated>2011-06-13T21:47:20.392-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="HRESULT: 0xC0010014"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server"/><title type='text'>Exception from HRESULT: 0xC0010014(Microsoft.SqlServer.DTSRuntimeWrap)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;I was working on setting up&amp;nbsp;Maintenance&amp;nbsp;Plan for backup on newly installed  SQL Server 2005. On this server we installed only database engine services  originally but not Integration Services (SSIS), and then later decided to add  this service too. While editing backup task on this new Server, I was facing  issue with &lt;i&gt;Exception from HRESULT:  0xC0010014(Microsoft.SqlServer.DTSRuntimeWrap)&lt;/i&gt; as shown below.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhY7RHsj38OvQr6FpGyetXBeShOtfDXygtwI164PXei4c7L_2DRefy8r4eq0ptyw5n2TkiiWq3BESw4bVyf6_iBHyzzq9xv659j9JX9P71oZDHv96JJIwRjlYWEK0ae1Dln6Wy0vDlOB5U/s1600/Capture.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;153&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhY7RHsj38OvQr6FpGyetXBeShOtfDXygtwI164PXei4c7L_2DRefy8r4eq0ptyw5n2TkiiWq3BESw4bVyf6_iBHyzzq9xv659j9JX9P71oZDHv96JJIwRjlYWEK0ae1Dln6Wy0vDlOB5U/s640/Capture.JPG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;To resolve this issue for 32-bit installation, you can perform below steps  (basically register couple dll&#39;s which got messed up due to sequence  of&amp;nbsp;installation)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;indent&quot;&gt;&lt;b&gt;%windir%\syswow64\regsvr32 &quot;%ProgramFiles(x86)%\Microsoft SQL  Server\90\dts\binn\dts.dll&quot;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;&lt;b&gt;%windir%\syswow64\regsvr32 &quot;%ProgramFiles(x86)%\Microsoft SQL  Server\90\dts\binn\MsDtsSrvrUtil.dll&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;and for 64 bit installation&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;indent&quot;&gt;&lt;b&gt;%windir%\system32\regsvr32 &quot;%ProgramFiles%\Microsoft SQL  Server\90\dts\binn\dts.dll&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;indent&quot;&gt;&lt;b&gt;%windir%\system32\regsvr32 &quot;%ProgramFiles%\Microsoft SQL  Server\90\dts\binn\MsDtsSrvrUtil.dll&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverrevolution.blogspot.com/feeds/1706402587200944592/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverrevolution.blogspot.com/2011/05/exception-from-hresult.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8086266974135964284/posts/default/1706402587200944592'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8086266974135964284/posts/default/1706402587200944592'/><link rel='alternate' type='text/html' href='http://sqlserverrevolution.blogspot.com/2011/05/exception-from-hresult.html' title='Exception from HRESULT: 0xC0010014(Microsoft.SqlServer.DTSRuntimeWrap)'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhY7RHsj38OvQr6FpGyetXBeShOtfDXygtwI164PXei4c7L_2DRefy8r4eq0ptyw5n2TkiiWq3BESw4bVyf6_iBHyzzq9xv659j9JX9P71oZDHv96JJIwRjlYWEK0ae1Dln6Wy0vDlOB5U/s72-c/Capture.JPG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8086266974135964284.post-6682516552058384229</id><published>2010-06-08T08:37:00.003-04:00</published><updated>2011-06-13T21:46:44.595-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Aggregate Function"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2005"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2008"/><title type='text'>Aggregates... Some Times they become brain teasers...</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;One Day ... I was sitting with one of my team mate.. He just asked me casually what could be the value of SUM aggregate on a table containing no row...&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;to confuse me more he ran ....&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
SELECT COUNT(1) FROM @tmp&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;The result was zero (0)...&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;Then he changed the SQL to...&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
SELECT SUM(1) FROM @tmp&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;I was little confused; Can any body be able to solve my confusion... make sure you guess the answer without executing the above query...&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverrevolution.blogspot.com/feeds/6682516552058384229/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverrevolution.blogspot.com/2008/06/aggregates-some-times-they-become-brain.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8086266974135964284/posts/default/6682516552058384229'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8086266974135964284/posts/default/6682516552058384229'/><link rel='alternate' type='text/html' href='http://sqlserverrevolution.blogspot.com/2008/06/aggregates-some-times-they-become-brain.html' title='Aggregates... Some Times they become brain teasers...'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8086266974135964284.post-1279978985952807272</id><published>2009-03-19T06:30:00.006-04:00</published><updated>2011-06-13T21:46:08.435-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2005"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2008"/><category scheme="http://www.blogger.com/atom/ns#" term="using sp_spaceused"/><title type='text'>USING sp_spaceused FOR Multiple tables</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;Using sp_spaceused we can only find&amp;nbsp;statistics for&amp;nbsp;particular&amp;nbsp;table within database in&amp;nbsp;SQL Server. But there is way by which we can USE sp_spaceused for multiple tables too. Actually the fact&amp;nbsp;is that it can be used for all tables and for multiple/all databases. Following script can help you to get space used by all tables in particular database.&amp;nbsp;I will update this script for all/multiple databases soon (hint: use sp_foreachdb along with this scipt to achieve the result) .&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;-- Declare variables&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;DECLARE @Table_Size TABLE&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;(&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;[Table_Name] NVARCHAR(200)&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;, [Number_of_Rows] NVARCHAR(100)&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;, [Reserved_Space] NVARCHAR(100)&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;, [Data_Space] NVARCHAR(100)&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;, [Index_Size] NVARCHAR(100)&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;, [Unused_Space] NVARCHAR(100)&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;)&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;DECLARE @Table_Name NVARCHAR(200)&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;-- Select first table&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;SELECT TOP 1 @Table_Name = (TABLE_SCHEMA + &#39;.&#39; + TABLE_NAME)&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = &#39;BASE TABLE&#39;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;ORDER BY (TABLE_SCHEMA + &#39;.&#39; + TABLE_NAME)&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;-- loop thorugh rest of the tables&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;WHILE ( @@ROWCOUNT != 0 )&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;BEGIN&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;INSERT INTO @Table_Size&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;EXEC sp_spaceused @objname = @Table_Name&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;PRINT @Table_Name&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;SELECT TOP 1 @Table_Name = (TABLE_SCHEMA + &#39;.&#39; + TABLE_NAME )&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;FROM INFORMATION_SCHEMA.TABLES&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;WHERE TABLE_TYPE = &#39;BASE TABLE&#39; AND @Table_Name &amp;lt; (TABLE_SCHEMA + &#39;.&#39; + TABLE_NAME)&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;ORDER BY (TABLE_SCHEMA + &#39;.&#39; + TABLE_NAME)&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;END&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;-- Display end results&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;SELECT * FROM @Table_Size ORDER BY Table_Name&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverrevolution.blogspot.com/feeds/1279978985952807272/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverrevolution.blogspot.com/2009/03/using-spspaceused-for-multiple-tables.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8086266974135964284/posts/default/1279978985952807272'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8086266974135964284/posts/default/1279978985952807272'/><link rel='alternate' type='text/html' href='http://sqlserverrevolution.blogspot.com/2009/03/using-spspaceused-for-multiple-tables.html' title='USING sp_spaceused FOR Multiple tables'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8086266974135964284.post-7566305381094456825</id><published>2009-02-18T07:36:00.002-05:00</published><updated>2011-06-20T20:44:21.062-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Examples"/><title type='text'>OPENROWSET Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;A simple example for using OPENROWSET in SQL Server 2005 to access another SQL Server is goes as .....&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SELECT * FROM OPENROWSET(&#39;SQLOLEDB&#39;,&lt;br /&gt;
&#39;&lt;server&gt;&#39;;&lt;user&gt;;&#39;&lt;pwd&gt;&#39;,&lt;br /&gt;
&#39;SELECT *&lt;br /&gt;
FROM &lt;db_name&gt;.dbo.&lt;table_name&gt;&#39;)&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt; The SELECT within OPENROWSET can have where clause also. There is benefit associated also, sometimes you can access same data using Linked server strategy also; but in that case WHERE gets applied only when data is tranferred to destination. WHEREAS in case of OPENROWSET where gets applied on SOURCE itself.&lt;/span&gt;&lt;/table_name&gt;&lt;/db_name&gt;&lt;/pwd&gt;&lt;/user&gt;&lt;/server&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlserverrevolution.blogspot.com/feeds/7566305381094456825/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverrevolution.blogspot.com/2009/02/openrowset-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8086266974135964284/posts/default/7566305381094456825'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8086266974135964284/posts/default/7566305381094456825'/><link rel='alternate' type='text/html' href='http://sqlserverrevolution.blogspot.com/2009/02/openrowset-example.html' title='OPENROWSET Example'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8086266974135964284.post-5712444576197899278</id><published>2008-06-05T07:43:00.000-04:00</published><updated>2008-06-05T07:48:31.911-04:00</updated><title type='text'>Sharing My SQL Experience - The way to learn more</title><content type='html'>I would be sharing my knowledge about SQL Server in this place. The Knowledge that i have acquired over the span of last 4-5 years. I would be sharing solutions to the problems I faced over these years. Would be writing about topics that I like.&lt;br /&gt;Would try to server SQl commnuity as much as I can. Over the time period I would add new authors who can write on SQL Server topics.&lt;br /&gt;I am going to start this because I know when you share your thoughts it increases your knowledge, changes your though process. Lets hope serving the community brings out the best from my side.</content><link rel='replies' type='application/atom+xml' href='http://sqlserverrevolution.blogspot.com/feeds/5712444576197899278/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlserverrevolution.blogspot.com/2008/06/sharing-my-sql-experience-way-to-learn.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8086266974135964284/posts/default/5712444576197899278'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8086266974135964284/posts/default/5712444576197899278'/><link rel='alternate' type='text/html' href='http://sqlserverrevolution.blogspot.com/2008/06/sharing-my-sql-experience-way-to-learn.html' title='Sharing My SQL Experience - The way to learn more'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>