<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;DEYBSHcyeyp7ImA9WhRUF0w.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983</id><updated>2012-01-28T07:32:39.993+05:30</updated><category term="SQL Server Errors" /><category term="Denali" /><category term="SQL Scripts" /><category term="#sql Server" /><category term="Performance" /><category term="installation" /><category term="SQL Server Agent" /><category term="SQL" /><category term="tsql" /><category term="Errors" /><category term="SQL Server Denali" /><category term="Replication" /><category term="SQL Server" /><category term="SQL CLR" /><category term="pivot" /><category term="CTP" /><category term="event" /><category term="Security" /><category term="SQL Server Problems" /><category term="Enhancements" /><category term="ms sql" /><category term="query" /><category term="new features" /><category term="t-sql" /><category term="zoom" /><category term="restore" /><category term="SQL Server Code Named Denali" /><category term="encryption" /><category term="Task List" /><category term="hint" /><category term="download" /><category term="Exception" /><category term="retention" /><category term="SQL Server General" /><category term="top" /><category term="SQL SERVER 2005 Certification" /><category term="SET" /><category term="Pagination" /><category term="SSIS" /><category term="SSDT" /><category term="database" /><category term="backup" /><category term="debug" /><category term="Clipboard" /><category term="SQL Server 11" /><category term="variable" /><category term="Versions" /><category term="SQL Server 2008" /><category term="ranking functions" /><category term="login" /><category term="lock" /><category term="#sql" /><category term="azure" /><category term="sql errors" /><category term="Role" /><category term="CTD" /><category term="blog" /><category term="Maintenance" /><category term="user" /><category term="blog view" /><category term="JustLearned" /><category term="SQL SERVER 2005" /><category term="Order By" /><category term="CTE" /><category term="Agent" /><category term="ms sql server" /><category term="identity" /><category term="datatype" /><category term="SQL new features" /><category term="SQL Server 2011" /><category term="index" /><category term="statistics" /><category term="microsoft event" /><category term="Sequence" /><category term="Service Broker" /><category term=".NET" /><title>sqlIdeas</title><subtitle type="html">Towards the innovative SQL ideas</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://paresh-sqldba.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>188</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/SqlDbaPosts" /><feedburner:info uri="sqldbaposts" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>SqlDbaPosts</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><entry gd:etag="W/&quot;DEYCQX46cSp7ImA9WhRUF0w.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-234999470774302266</id><published>2012-01-28T07:32:00.000+05:30</published><updated>2012-01-28T07:32:40.019+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-28T07:32:40.019+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Errors" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server General" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server Errors" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql" /><category scheme="http://www.blogger.com/atom/ns#" term="Exception" /><category scheme="http://www.blogger.com/atom/ns#" term="login" /><category scheme="http://www.blogger.com/atom/ns#" term="Security" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server Problems" /><title>Alter failed for Login sa. Cannot set a credential for principal 'sa'. - Error encountered in SQL Server</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
Recently when i worked with SQL Server security, i encountered with one error while trying to modify 'SA' account properties.&amp;nbsp;The exception details looks following,&lt;br /&gt;
&lt;blockquote class="tr_bq"&gt;
&lt;span style="color: red;"&gt;Alter failed for Login sa. Cannot set a credential for principal 'sa'.&lt;/span&gt;&lt;/blockquote&gt;
Also you can see the image below for the same.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-cs5kvqxb5wE/Txabq6UMTiI/AAAAAAAABZE/xWGnVRabAAw/s1600/SaEnable1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="576" src="http://1.bp.blogspot.com/-cs5kvqxb5wE/Txabq6UMTiI/AAAAAAAABZE/xWGnVRabAAw/s640/SaEnable1.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
The &lt;span style="font-size: large;"&gt;&lt;b&gt;fix&lt;/b&gt; &lt;/span&gt;for the error is the option "&lt;span style="color: #0b5394;"&gt;&lt;b&gt;Map to Credential&lt;/b&gt;&lt;/span&gt;" is checked in the "General" tab of the Login Properties Page as mentioned below,&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-S1n5xSqGTsU/TxabcOPkHuI/AAAAAAAABY8/EeYQzhpnXKo/s1600/SaEnable2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="574" src="http://3.bp.blogspot.com/-S1n5xSqGTsU/TxabcOPkHuI/AAAAAAAABY8/EeYQzhpnXKo/s640/SaEnable2.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Hope this help you.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-234999470774302266?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/OBakgmhUkVmgk_ReOlyzSkYFgwo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/OBakgmhUkVmgk_ReOlyzSkYFgwo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/OBakgmhUkVmgk_ReOlyzSkYFgwo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/OBakgmhUkVmgk_ReOlyzSkYFgwo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/LfQevHplKGc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/234999470774302266/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2012/01/alter-failed-for-login-sa-cannot-set.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/234999470774302266?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/234999470774302266?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/LfQevHplKGc/alter-failed-for-login-sa-cannot-set.html" title="Alter failed for Login sa. Cannot set a credential for principal 'sa'. - Error encountered in SQL Server" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-cs5kvqxb5wE/Txabq6UMTiI/AAAAAAAABZE/xWGnVRabAAw/s72-c/SaEnable1.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://paresh-sqldba.blogspot.com/2012/01/alter-failed-for-login-sa-cannot-set.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkIGRXo4cSp7ImA9WhRUEEs.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-2979515485618525511</id><published>2012-01-20T19:29:00.000+05:30</published><updated>2012-01-20T19:38:44.439+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-20T19:38:44.439+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="t-sql" /><category scheme="http://www.blogger.com/atom/ns#" term="login" /><category scheme="http://www.blogger.com/atom/ns#" term="Security" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server General" /><category scheme="http://www.blogger.com/atom/ns#" term="query" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql" /><title>Application Role in SQL Server</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
In last post we have seen &lt;a href="http://paresh-sqldba.blogspot.com/2012/01/custom-database-role-in-sql-server.html" target="_blank"&gt;&lt;b&gt;custom database roles&lt;/b&gt;&lt;/a&gt; as how can we create it and assign required access to users. We also noticed that we can add multiple members with same role. That was the security with database roles and members comes into the picture. Now here we will study of Application Role. This is the security for the application level and no such members comes into the picture.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #0b5394;"&gt;Application Role :&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
As per msdn, An application role is a database principal that enables an application to run with its own, user-like permissions. You can use application roles to enable access to specific data to only those users who connect through a particular application.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0b5394;"&gt;&lt;b&gt;Workaround:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
We can implement application role and take into effect with following steps, I am going to here with some of examples, so like create those required objects, so we can set them with application role.&lt;br /&gt;
&lt;br /&gt;
1. &lt;u&gt;Create required objects&lt;/u&gt;&lt;br /&gt;
&lt;div&gt;
&lt;pre class="brush:sql"&gt;USE demo
GO

CREATE TABLE SampleTable1
(
Id int,
Name varchar(10)
)
GO

CREATE TABLE SampleTable2
(
Id int,
Name varchar(10)
)
GO

CREATE PROCEDURE SampleSP1
AS 
BEGIN
SET NOCOUNT ON
SELECT * FROM SampleTable1
End
GO

CREATE PROCEDURE SampleSP2
AS 
BEGIN
SET NOCOUNT ON
SELECT * FROM SampleTable2
End
GO
&lt;/pre&gt;
&lt;br /&gt;
Here we have created same required objects as we created in earlier post for database role.&lt;br /&gt;
&lt;br /&gt;
2. &lt;u&gt;Create an application role&lt;/u&gt;&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE demo
GO

-- sp_addapprole [@rolename = ] 'rolename', [@password = ] 'password'

EXEC sp_addapprole 'AppRole', 'AppPwd'
GO
&lt;/pre&gt;
&lt;br /&gt;
3. &lt;u&gt;Add permission to this application role&lt;/u&gt;&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE demo
GO

GRANT SELECT ON SampleTable1 to AppRole;
GRANT SELECT, INSERT,UPDATE ON SampleTable2 to AppRole;
GRANT EXEC ON SampleSP1 to AppRole;
GO
&lt;/pre&gt;
&lt;br /&gt;
You can see we have assigned same access to application role as we did in earlier post for the custom database role.&amp;nbsp;Application role is created here now, You can also create/view with expanding Roles inside security tab for&amp;nbsp;particular&amp;nbsp;database and inside it you can find Application Role tab.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-meP0V-Xs5EE/TxAhc_aVgkI/AAAAAAAABXE/4mpBh4sI9BY/s1600/Approle_1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="574" src="http://2.bp.blogspot.com/-meP0V-Xs5EE/TxAhc_aVgkI/AAAAAAAABXE/4mpBh4sI9BY/s640/Approle_1.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
4. &lt;u&gt;Connecting database and activating application role&lt;/u&gt;&lt;br /&gt;
Application roles are enabled/activated by &lt;b style="color: #0b5394;"&gt;sp_settapprole &lt;/b&gt;system stored procedure and it has required password.So application can be connected to SQL Server with this application role with scope of&amp;nbsp;particular&amp;nbsp;session and required password to&amp;nbsp;authenticate&amp;nbsp;it to connect SQL Server. To authenticate application roles and activate it it should be required to use in .Net connection code or other application database connection method code. You can refer the link &lt;span style="font-size: large;"&gt;&lt;span style="color: #0b5394;"&gt;&lt;a href="http://www.codeproject.com/KB/database/AppRole.aspx" target="_blank"&gt;here&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;to use application role in application code.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0b5394;"&gt;sp_settapprole&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;system stored procedure activate the application role for the specific connection while connecting with application and the syntax is as following,&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE demo
GO

-- sp_setapprole [@rolename = ] 'rolename', [@password = ] 'password'

EXEC sp_setapprole 'AppRole', 'AppPwd'
GO
&lt;/pre&gt;
&lt;br /&gt;
We can change the password&amp;nbsp;for the&amp;nbsp;application&amp;nbsp;role with&amp;nbsp;following,&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE demo
GO

-- sp_approlepassword [@rolename = ] 'rolename', [@password = ] 'new password'

EXEC sp_approlepassword 'AppRole', 'AppChangedPwd'
GO
&lt;/pre&gt;
&lt;br /&gt;
Hope these all the steps are enough to implement application role. Stay tuned for more.&lt;/div&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-2979515485618525511?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/iuokkzvjrTTW390wRsJXrHuDHjw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/iuokkzvjrTTW390wRsJXrHuDHjw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/iuokkzvjrTTW390wRsJXrHuDHjw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/iuokkzvjrTTW390wRsJXrHuDHjw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/h-GlBzSlwxo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/2979515485618525511/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2012/01/application-role-in-sql-server.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/2979515485618525511?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/2979515485618525511?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/h-GlBzSlwxo/application-role-in-sql-server.html" title="Application Role in SQL Server" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-meP0V-Xs5EE/TxAhc_aVgkI/AAAAAAAABXE/4mpBh4sI9BY/s72-c/Approle_1.png" height="72" width="72" /><thr:total>1</thr:total><georss:featurename>Chenpur, Kali Gaam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.1035767 72.5620452</georss:point><georss:box>23.0962742 72.5521747 23.110879200000003 72.5719157</georss:box><feedburner:origLink>http://paresh-sqldba.blogspot.com/2012/01/application-role-in-sql-server.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUUNRXs_eyp7ImA9WhRVFEs.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-851871465064319291</id><published>2012-01-13T19:31:00.000+05:30</published><updated>2012-01-13T19:31:34.543+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-13T19:31:34.543+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Maintenance" /><category scheme="http://www.blogger.com/atom/ns#" term="query" /><category scheme="http://www.blogger.com/atom/ns#" term="Role" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server General" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="user" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server" /><category scheme="http://www.blogger.com/atom/ns#" term="login" /><category scheme="http://www.blogger.com/atom/ns#" term="Security" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><title>Custom Database Role in SQL Server</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
Recently while working with database security, I learned database roles as how the each role used. Apart from the server level roles if we need to require to assign access/rights to particular databases level then we need to go through database level roles.&lt;br /&gt;
&lt;br /&gt;
Following are the fixed database level roles as per &lt;a href="http://msdn.microsoft.com/en-us/library/ms189121.aspx" target="_blank"&gt;MSDN&lt;/a&gt;,&lt;br /&gt;
&lt;b&gt;db_owner :&lt;/b&gt;
Members of the db_owner fixed database role can perform all configuration and maintenance activities on the database, and can also drop the database.&lt;br /&gt;
&lt;b&gt;db_securityadmin :&lt;/b&gt;
Members of the db_securityadmin fixed database role can modify role membership and manage permissions. Adding principals to this role could enable unintended privilege escalation.&lt;br /&gt;
&lt;b&gt;db_accessadmin :&lt;/b&gt;
Members of the db_accessadmin fixed database role can add or remove access to the database for Windows logins, Windows groups, and SQL Server logins.&lt;br /&gt;
&lt;b&gt;db_backupoperator :&lt;/b&gt;
Members of the db_backupoperator fixed database role can back up the database.&lt;br /&gt;
&lt;b&gt;db_ddladmin :&lt;/b&gt;
Members of the db_ddladmin fixed database role can run any Data Definition Language (DDL) command in a database.&lt;br /&gt;
&lt;b&gt;db_datawriter :&lt;/b&gt;
Members of the db_datawriter fixed database role can add, delete, or change data in all user tables.&lt;br /&gt;
&lt;b&gt;db_datareader :
&lt;/b&gt;Members of the db_datareader fixed database role can read all data from all user tables.&lt;br /&gt;
&lt;b&gt;db_denydatawriter :&lt;/b&gt;
Members of the db_denydatawriter fixed database role cannot add, modify, or delete any data in the user tables within a database.&lt;br /&gt;
&lt;b&gt;db_denydatareader :
&lt;/b&gt;Members of the db_denydatareader fixed database role cannot read any data in the user tables within a database.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-zaQtyTnHKZ8/Tw_SsTYDWEI/AAAAAAAABW0/n9RI--LrhQo/s1600/DBroles_1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="574" src="http://4.bp.blogspot.com/-zaQtyTnHKZ8/Tw_SsTYDWEI/AAAAAAAABW0/n9RI--LrhQo/s640/DBroles_1.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
You can see the image for all above fixed database roles.&amp;nbsp;Now we will see how can we use the roles and bind with users. Let's create a small demo with example.&lt;br /&gt;
&lt;br /&gt;
Here i am creating required objects used for demo, So let's do that.&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE demo
GO

CREATE TABLE SampleTable1
(
Id int,
Name varchar(10)
)
GO

CREATE TABLE SampleTable2
(
Id int,
Name varchar(10)
)
GO

CREATE PROCEDURE SampleSP1
AS 
BEGIN
SET NOCOUNT ON
SELECT * FROM SampleTable1
End
GO

CREATE PROCEDURE SampleSP2
AS 
BEGIN
SET NOCOUNT ON
SELECT * FROM SampleTable2
End
GO
&lt;/pre&gt;
&lt;br /&gt;
Now here i want assigned to the access to user as following,&lt;br /&gt;
1. User can see the data from SampleTable2 table.&lt;br /&gt;
2. User can perform select/insert/update operation on&amp;nbsp;SampleTable1 table, not delete operation.&lt;br /&gt;
3. Can execute stored procedure&amp;nbsp;SampleSP1.&lt;br /&gt;
4. Can not execute stored procedure&amp;nbsp;SampleSP2.
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #0b5394;"&gt;Workaround 1:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
If we assigned fixed database roles to User like db_datareader and db_datawriter for&amp;nbsp;particular&amp;nbsp;database, then user can perform all DML operation on all tables, views for the database. Even if we assigned EXECUTE permission to user then user can execute all the stored procedures.&lt;br /&gt;
&lt;br /&gt;
After all these permission we need to deny permission from the user for some of the tables and stored procedures which are not required to be&amp;nbsp;accessed.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #0b5394;"&gt;Workaround 2:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
Instead of doing above such stuffs, We will create a new custom database level roles and assigned requited access to user for the objects.&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE demo
GO

CREATE LOGIN [SupportUser] 
WITH PASSWORD=N'SupportUser', 
 DEFAULT_DATABASE=[master], 
 DEFAULT_LANGUAGE=[us_english], 
 CHECK_EXPIRATION=OFF, 
 CHECK_POLICY=OFF
GO

CREATE USER [SupportUser] FOR LOGIN [SupportUser]
GO

CREATE ROLE [SupportRole] 
Go

GRANT SELECT ON SampleTable2 TO [SupportRole];
GRANT SELECT,INSERT,UPDATE ON SampleTable1 to [SupportRole];
GRANT EXEC ON SampleSP1 to [SupportRole]
GO

EXEC sp_addrolemember N'SupportRole', N'SupportUser'
GO
&lt;/pre&gt;
&lt;br /&gt;
Let's connect the SQL Server instance with this newly created user and see the access rights,&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE demo
GO

PRINT 'Inserting in SampleTable1'
GO
INSERT INTO SampleTable1
 (
 Id, 
 Name
 )
SELECT 
 1,
 'Sample1'
GO

PRINT 'Inserting in SampleTable2'
GO
INSERT INTO SampleTable2
 (
 Id, 
 Name
 )
SELECT 
 1,
 'Sample2'
GO

PRINT 'Deleting from SampleTable1'
GO
DELETE FROM SampleTable1
GO

PRINT 'Viewing from SampleTable1'
GO
SELECT * FROM SampleTable2
GO
SELECT * FROM SampleTable1
GO


PRINT 'Executing SampleSP11'
GO
EXEC SampleSP1
GO
PRINT 'Executing SampleSP2'
GO
EXEC SampleSP2
GO
&lt;/pre&gt;
&lt;br /&gt;
You can see the below image to see the access of running user,&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-EyaFnrKGH_Q/Tw_TNLhMiKI/AAAAAAAABW8/Nn8gEh5v23s/s1600/DBroles_2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="518" src="http://1.bp.blogspot.com/-EyaFnrKGH_Q/Tw_TNLhMiKI/AAAAAAAABW8/Nn8gEh5v23s/s640/DBroles_2.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Main benefit of the custom database role is role can be assigned to multiple users. You can see below script where i have assigned same role to different user. So once role created it can &amp;nbsp;be assigned to multiple users.&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE demo
GO

CREATE LOGIN [DBAUser] 
WITH PASSWORD=N'DBAUser', 
 DEFAULT_DATABASE=[master], 
 DEFAULT_LANGUAGE=[us_english], 
 CHECK_EXPIRATION=OFF, 
 CHECK_POLICY=OFF
GO

CREATE USER [DBAUser] FOR LOGIN [DBAUser]
GO

EXEC sp_addrolemember N'SupportRole', N'DBAUser'
GO
&lt;/pre&gt;
&lt;br /&gt;
Hope you liked this post.
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-851871465064319291?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/S7fg8fCkKqHP3dZ9dkTsoaOWR5M/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/S7fg8fCkKqHP3dZ9dkTsoaOWR5M/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/S7fg8fCkKqHP3dZ9dkTsoaOWR5M/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/S7fg8fCkKqHP3dZ9dkTsoaOWR5M/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/8KtY66slXVg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/851871465064319291/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2012/01/custom-database-role-in-sql-server.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/851871465064319291?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/851871465064319291?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/8KtY66slXVg/custom-database-role-in-sql-server.html" title="Custom Database Role in SQL Server" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-zaQtyTnHKZ8/Tw_SsTYDWEI/AAAAAAAABW0/n9RI--LrhQo/s72-c/DBroles_1.png" height="72" width="72" /><thr:total>0</thr:total><georss:featurename>Chenpur, Kali Gaam, Ahmedabad, Gujarat, India</georss:featurename><georss:point>23.1035767 72.5620452</georss:point><georss:box>23.088972700000003 72.5423042 23.1181807 72.5817862</georss:box><feedburner:origLink>http://paresh-sqldba.blogspot.com/2012/01/custom-database-role-in-sql-server.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CU8ER307eCp7ImA9WhRWGUk.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-5469455992192981694</id><published>2012-01-07T19:13:00.000+05:30</published><updated>2012-01-07T19:13:26.300+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-07T19:13:26.300+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2008" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL SERVER 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server General" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server Denali" /><category scheme="http://www.blogger.com/atom/ns#" term="tsql" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server" /><category scheme="http://www.blogger.com/atom/ns#" term="t-sql" /><category scheme="http://www.blogger.com/atom/ns#" term="pivot" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2011" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql" /><title>Changing Rows to Columns Using PIVOT - SQL Server</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;br /&gt;
During working with one logic, i got chance to work with PIVOT operation.&amp;nbsp;Sometime we need do require rowdata as column in our custom logic, then we can use some temp table and then populate agreegate data in temp table.&amp;nbsp;But With PIVOT we can do it very easily.&amp;nbsp;Let me prepare small example and explain as how how can we use PIVOT and get row data as column.&lt;br /&gt;
&lt;br /&gt;
Before go ahead to run the script of Pivot, we will create database and table objects.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;CREATE DATABASE DEMO
GO

USE DEMO
GO

-- Creating table for demo
IF (object_id('TblPivot','U') &amp;gt; 0)
DROP TABLE TblPivot

CREATE TABLE TblPivot
(
ItemCode int,
ItemName varchar(100),
ItemColour varchar(50)
)

GO

-- Inerting some sample records

INSERT INTO TblPivot
SELECT 1,'Samsung Mobile','Red'
UNION ALL
SELECT 2,'Nokia Mobile','Blue'
UNION ALL
SELECT 3,'Nokia Mobile','Green'
UNION ALL
SELECT 4,'Motorola Mobile','Red'
UNION ALL
SELECT 5,'Samsung Mobile','Green'
UNION ALL
SELECT 2,'Nokia Mobile','Blue'
UNION ALL
SELECT 1,'Samsung Mobile','Red'
UNION ALL
SELECT 2,'Nokia Mobile','Blue'

GO
&lt;/pre&gt;
&lt;br /&gt;
Now we will check the original table data and aggregated data using Pivot.&lt;br /&gt;
So we will run both script for the same.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;-- Getting table data
SELECT 
ItemCode, 
ItemName, 
ItemColour
from TblPivot
GO

-- Getting agreegated data using Pivot and converted rows to column
SELECT
*
 FROM
 (
    SELECT 
 ItemCode, 
 ItemName, 
 ItemColour
    FROM TblPivot
 ) AS P
PIVOT
(
  Count(ItemName) FOR ItemColour IN (Red, Blue, Green)
) AS pv

GO
&lt;/pre&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-nFQHUhQ1NaY/Tc5AtviktiI/AAAAAAAAAfo/yubOdwUfieA/s1600/Pivot_1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://3.bp.blogspot.com/-nFQHUhQ1NaY/Tc5AtviktiI/AAAAAAAAAfo/yubOdwUfieA/s640/Pivot_1.png" width="512" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
You can review here and see how the PIVOT is working. Let me share your experience with PIVOT operation.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-5469455992192981694?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/YI2Eg8G4AXVpJKNjb3mUZXN4-9I/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/YI2Eg8G4AXVpJKNjb3mUZXN4-9I/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/YI2Eg8G4AXVpJKNjb3mUZXN4-9I/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/YI2Eg8G4AXVpJKNjb3mUZXN4-9I/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/Ki6TqPvulRM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/5469455992192981694/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2011/05/changing-rows-to-columns-using-pivot.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/5469455992192981694?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/5469455992192981694?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/Ki6TqPvulRM/changing-rows-to-columns-using-pivot.html" title="Changing Rows to Columns Using PIVOT - SQL Server" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-nFQHUhQ1NaY/Tc5AtviktiI/AAAAAAAAAfo/yubOdwUfieA/s72-c/Pivot_1.png" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://paresh-sqldba.blogspot.com/2011/05/changing-rows-to-columns-using-pivot.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0YHSHw4eip7ImA9WhRWEkg.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-6746347659891047599</id><published>2011-12-30T19:55:00.000+05:30</published><updated>2011-12-30T19:55:39.232+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-30T19:55:39.232+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="retention" /><category scheme="http://www.blogger.com/atom/ns#" term="SSIS" /><category scheme="http://www.blogger.com/atom/ns#" term="SSDT" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server General" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql" /><title>Delete files older than retention period from folder with parameter using Script Task in SQL Server - SSIS</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;After using some of the ways to delete the files from the&amp;nbsp;particular&amp;nbsp;folder like&amp;nbsp;&lt;a href="http://paresh-sqldba.blogspot.com/2011/12/delete-files-from-specified-folder_14.html" target="_blank"&gt;&lt;b&gt;Delete file using Script Task&lt;/b&gt;&lt;/a&gt; and &amp;nbsp;&lt;a href="http://paresh-sqldba.blogspot.com/2011/12/delete-files-from-specified-folder.html" target="_blank"&gt;&lt;b&gt;File System Task&lt;/b&gt;&lt;/a&gt; in SSIS. We have seen such methods and used&amp;nbsp;logic to get the files from the loop container and process to delete them and same thing applied for the scripts as well.&amp;nbsp;we also looked for the files deletion which are older than some&lt;b&gt;&lt;u&gt;&amp;nbsp;&lt;a href="http://paresh-sqldba.blogspot.com/2011/12/delete-files-older-than-retention.html" target="_blank"&gt;Retention&amp;nbsp;period with Script Task&lt;/a&gt;&lt;/u&gt;&lt;/b&gt; also.&lt;br /&gt;
&lt;br /&gt;
In earlier posts we have not used any parameters in the scripts and directly applied folder path and retention period values there. But here i would like to use parameters for the folder path and&amp;nbsp;retention&amp;nbsp;period and pass through the scripts and delete them as per condition.&lt;br /&gt;
&lt;br /&gt;
1. Let check the files from the target folder.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-U4Ss7HEZyvU/TvM69jF50NI/AAAAAAAABMA/U40LUTPZo9g/s1600/deletefile4_0.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="312" src="http://1.bp.blogspot.com/-U4Ss7HEZyvU/TvM69jF50NI/AAAAAAAABMA/U40LUTPZo9g/s640/deletefile4_0.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
2. Create parameters and set the values. Here it is going to be delete the files which are older then 3 days from the&amp;nbsp;E:\ImagesBackup folder in this case.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-FcJ1ygMy1mE/TvM7sJR_jII/AAAAAAAABM0/3ErvmvY1XrE/s1600/deletefile4_1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="140" src="http://2.bp.blogspot.com/-FcJ1ygMy1mE/TvM7sJR_jII/AAAAAAAABM0/3ErvmvY1XrE/s640/deletefile4_1.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
3. Drag and drop File System Task&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-CyTAkEEkW1M/TvM76LwEgnI/AAAAAAAABNA/ajEwKxBt9Nk/s1600/deletefile4_2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="270" src="http://3.bp.blogspot.com/-CyTAkEEkW1M/TvM76LwEgnI/AAAAAAAABNA/ajEwKxBt9Nk/s640/deletefile4_2.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Put the parameters as ReadOnlyVariables&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-YVP1uU7witM/TvM8bOuAVCI/AAAAAAAABNM/Vj-O9qZ8lXk/s1600/deletefile4_3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="542" src="http://3.bp.blogspot.com/-YVP1uU7witM/TvM8bOuAVCI/AAAAAAAABNM/Vj-O9qZ8lXk/s640/deletefile4_3.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
6. Apply attached script in editor which have additional logic with condition to check the file lat&amp;nbsp;modified&amp;nbsp;date and check if older than specified retention period or not. Here you can see the parameters used in the script.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-AnTo_WNfcOQ/TvM8rjPMM5I/AAAAAAAABNY/0RjlglyP5Xw/s1600/deletefile4_4.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="368" src="http://1.bp.blogspot.com/-AnTo_WNfcOQ/TvM8rjPMM5I/AAAAAAAABNY/0RjlglyP5Xw/s640/deletefile4_4.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;Please note here we need to import system.IO namespace.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
7. Turn on final step and run package. Files older than specified retention period&amp;nbsp;get deleted.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-sc_dCAhT6mY/TvM8xEHV6LI/AAAAAAAABNk/bk-yUwdhK8k/s1600/deletefile4_5.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="430" src="http://2.bp.blogspot.com/-sc_dCAhT6mY/TvM8xEHV6LI/AAAAAAAABNk/bk-yUwdhK8k/s640/deletefile4_5.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;
You &amp;nbsp;can use the script below for the same as mentioned in above image,&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;--// You need to apply below one line in "namespaces" region.
using System.IO;

--//You need to apply below lines inplace of &amp;nbsp;// TODO: Add your code here
int RetentionPeriod = Convert.ToInt32(Dts.Variables["User::Period"].Value.ToString());
string directoryPath = Dts.Variables["User::BackupFolder"].Value.ToString();
string[] oldFiles = System.IO.Directory.GetFiles(directoryPath, "*.*");

foreach (string currFile in oldFiles)
  {
         FileInfo currFileInfo = new FileInfo(currFile);
              
            if (currFileInfo.LastWriteTime &amp;lt; (DateTime.Now.AddDays(-RetentionPeriod)))
                {
                    currFileInfo.Delete();
                }
            }
&lt;/pre&gt;Hope you liked this post. Stay tuned for more.  &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-6746347659891047599?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/pVXG4jwGRHe85TSxbznX5D-O92E/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pVXG4jwGRHe85TSxbznX5D-O92E/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/pVXG4jwGRHe85TSxbznX5D-O92E/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pVXG4jwGRHe85TSxbznX5D-O92E/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/2xOiqoXKDGg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/6746347659891047599/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2011/12/delete-files-older-than-retention_30.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/6746347659891047599?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/6746347659891047599?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/2xOiqoXKDGg/delete-files-older-than-retention_30.html" title="Delete files older than retention period from folder with parameter using Script Task in SQL Server - SSIS" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-U4Ss7HEZyvU/TvM69jF50NI/AAAAAAAABMA/U40LUTPZo9g/s72-c/deletefile4_0.png" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://paresh-sqldba.blogspot.com/2011/12/delete-files-older-than-retention_30.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0MGQX06cCp7ImA9WhRXFkk.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-3642197522191165027</id><published>2011-12-23T19:40:00.000+05:30</published><updated>2011-12-23T19:40:20.318+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-23T19:40:20.318+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="retention" /><category scheme="http://www.blogger.com/atom/ns#" term="SSIS" /><category scheme="http://www.blogger.com/atom/ns#" term="SSDT" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server General" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql" /><title>Delete files older than retention period from specified folder using Script Task in SQL Server - SSIS</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Earlier we have seen for the &lt;a href="http://paresh-sqldba.blogspot.com/2011/12/delete-files-from-specified-folder_14.html" target="_blank"&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Delete file using Script Task&lt;/span&gt;&lt;/a&gt; and&amp;nbsp;&lt;a href="http://paresh-sqldba.blogspot.com/2011/12/delete-files-from-specified-folder.html" target="_blank"&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;files deletion using File System Task&lt;/span&gt;&lt;/a&gt; in SSIS. We have directly wrote the logic to get the files and delete from specified folder in the script for the Script Task. For File System Task we have Used Foreach Loop Container and variables to hold file names which are passed from earlier stage one by one and then finally used with File System Task to delete it.&lt;br /&gt;
&lt;br /&gt;
Here we have same but not to delete all the files inside passed folder but get deleted files which are older than specified days. This is nothing but minor change in script where we pass the folder path and retention period. Lets start the steps as following,&lt;br /&gt;
&lt;br /&gt;
1. Let check the files from the target folder.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-FlO0C9E5IFU/TushRopSsMI/AAAAAAAABKs/T-AdTCQUUdA/s1600/deletefile3_0.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="272" src="http://2.bp.blogspot.com/-FlO0C9E5IFU/TushRopSsMI/AAAAAAAABKs/T-AdTCQUUdA/s640/deletefile3_0.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
2. Drag and drop Script Task.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-gOKw4ZrAsfQ/TushcJrTheI/AAAAAAAABK0/shWADAXV0FM/s1600/deletefile3_1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="346" src="http://1.bp.blogspot.com/-gOKw4ZrAsfQ/TushcJrTheI/AAAAAAAABK0/shWADAXV0FM/s640/deletefile3_1.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
3. Open script editor from the properties.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-SP5FhW40Ls8/TushiqK2JbI/AAAAAAAABK8/pOUQM8wHuSE/s1600/deletefile3_2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="544" src="http://2.bp.blogspot.com/-SP5FhW40Ls8/TushiqK2JbI/AAAAAAAABK8/pOUQM8wHuSE/s640/deletefile3_2.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
3. Apply attached script in editor which have additional logic with condition to check the file lat&amp;nbsp;modified&amp;nbsp;date and check if older than specified retention period or not.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-tCKDdklF7Po/TusiAyYl62I/AAAAAAAABLE/9G62pdnrnG0/s1600/deletefile3_3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="378" src="http://4.bp.blogspot.com/-tCKDdklF7Po/TusiAyYl62I/AAAAAAAABLE/9G62pdnrnG0/s640/deletefile3_3.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;Please note here we need to import system.IO namespace.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
4. Turn on final step and run package. Files older than specified retention period&amp;nbsp;get deleted.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-8QOxRoVrpAw/TusiMIb3b3I/AAAAAAAABLM/RXWA8Oe3Vm8/s1600/deletefile3_4.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="472" src="http://4.bp.blogspot.com/-8QOxRoVrpAw/TusiMIb3b3I/AAAAAAAABLM/RXWA8Oe3Vm8/s640/deletefile3_4.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
You can also find script code here,&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;--// You need to apply below one line in "namespaces" region.
using System.IO;

--//You need to apply below lines inplace of &amp;nbsp;// TODO: Add your code here
int RetentionPeriod = 3;
string directoryPath = @"E:\ImagesBackup";
string[] oldFiles = System.IO.Directory.GetFiles(directoryPath, "*.png");
     foreach (string currFile in oldFiles)
            {
                FileInfo currFileInfo = new FileInfo(currFile);
                if (currFileInfo.LastWriteTime &amp;lt; (DateTime.Now.AddDays(-RetentionPeriod)))
                {
                    currFileInfo.Delete();
                }
            }
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Hope you liked this post. Stay tuned for more.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-3642197522191165027?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/0AJkdmPTa-52xKFw2vfvYZyQtI4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0AJkdmPTa-52xKFw2vfvYZyQtI4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/0AJkdmPTa-52xKFw2vfvYZyQtI4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0AJkdmPTa-52xKFw2vfvYZyQtI4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/v7NXMYhwbis" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/3642197522191165027/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2011/12/delete-files-older-than-retention.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/3642197522191165027?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/3642197522191165027?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/v7NXMYhwbis/delete-files-older-than-retention.html" title="Delete files older than retention period from specified folder using Script Task in SQL Server - SSIS" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-FlO0C9E5IFU/TushRopSsMI/AAAAAAAABKs/T-AdTCQUUdA/s72-c/deletefile3_0.png" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://paresh-sqldba.blogspot.com/2011/12/delete-files-older-than-retention.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Dk4EQX45eCp7ImA9WhRXEEk.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-5005313808510526753</id><published>2011-12-16T19:43:00.002+05:30</published><updated>2011-12-16T19:45:00.020+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-16T19:45:00.020+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Maintenance" /><category scheme="http://www.blogger.com/atom/ns#" term="query" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server General" /><category scheme="http://www.blogger.com/atom/ns#" term="tsql" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server" /><category scheme="http://www.blogger.com/atom/ns#" term="t-sql" /><category scheme="http://www.blogger.com/atom/ns#" term="backup" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql" /><title>Archive old database backup files using TSQL Script - SQL Server</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I experienced into one issues for database backups were failed. And this was due to space issues on disk drive. This disk drive is spacific to allocated for the database backups only.&lt;br /&gt;
&lt;br /&gt;
The space was eaten by this database backups and this drive contains so many old backups. I have manually deleted all files and continue this activity so many days.If you create a&amp;nbsp;maintenance&amp;nbsp;plans then it have option to delete old backups files.&amp;nbsp;But i have the stored procedure for the database backups. So i do not have option to delete old and unused database backup files.&lt;br /&gt;
&lt;br /&gt;
Finally, I have created a script to clean those old backups. I have created one stored procedure in which you need to pass there parameters,&amp;nbsp;One is Backup type as want to delete full, differential or transaction log backups.&amp;nbsp;Second is From days and third one is End day.&lt;br /&gt;
&lt;br /&gt;
Please make sure XP_CMDSHELL is enabled in database instance as thisis require to enable it to delete database backup files to be deleted physically.&lt;br /&gt;
Here id query to enable it.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE MASTER
GO

EXEC SP_CONFIGURE 'show advanced options',1
GO
EXEC SP_CONFIGURE 'XP_CMDSHELL',1
GO
RECONFIGURE
GO
&lt;/pre&gt;&lt;br /&gt;
I have already told you as i have created script to delete the old DATABASEPROPERTY backups, please find below SP for the same.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[DeleteDBBackupOldFiles]
@BackupType char(1) = 'D', -- 'D'-Full, 'I'-Differential, 'L'-Log backup type
@StartDayFromToday int,
@EndDayFromToday int
AS
BEGIN
SET NOCOUNT ON

DECLARE @IsFileExists int
DECLARE @DeletedFile VARCHAR(500)
DECLARE @OldFiles VARCHAR(500)

DECLARE OldFiles CURSOR FAST_FORWARD  FOR
SELECT 
bmf.physical_device_name
from msdb.dbo.backupset bs 
INNER JOIN msdb.dbo.backupmediafamily bmf
ON (bs.media_set_id=bmf.media_set_id)
WHERE DEVICE_TYPE = 2 
AND TYPE = @BackupType 
AND BACKUP_START_DATE &amp;lt; = GETDATE() - @StartDayFromToday
AND BACKUP_START_DATE &amp;gt; = GETDATE() - @EndDayFromToday
-- AND DATEDIFF(DAY,BACKUP_START_DATE,GETDATE()) &amp;gt; BETWEEN @StartDayFromToday and @EndDayFromToday 

OPEN OldFiles

FETCH NEXT FROM OldFiles INTO @OldFiles

WHILE @@FETCH_STATUS =0
BEGIN

EXEC XP_FILEEXIST @OldFiles,@IsFileExists OUTPUT
IF @IsFileExists=1
BEGIN

PRINT 'Deleted File : ' + @DeletedFile

SET @DeletedFile = 'DEL ' + @OldFiles

EXEC XP_CMDSHELL @DeletedFile

END
FETCH NEXT FROM OldFiles INTO @OldFiles
END
CLOSE OldFiles
DEALLOCATE OldFiles
END
&lt;/pre&gt;&lt;br /&gt;
Finally after creating a stored procedures , it is time to run and clean the old database backups. After running it will remove all the old database baclups as per specified parameters. Like we have passed 'D',3 and 10 with SP, So i will delete Full database backups whicl are older then 3 days ago and 10 days before created.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;EXEC [DeleteDBBackupOldFiles] 
  @BackupType  = 'D',
  @StartDayFromToday = 3,
  @EndDayFromToday = 10
&lt;/pre&gt;&lt;br /&gt;
Which method you are using for old databsee backup&amp;nbsp;maintenance?&amp;nbsp;You can read my earlier posts for delete files using &lt;a href="http://paresh-sqldba.blogspot.com/2011/12/delete-files-from-specified-folder.html" target="_blank"&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;File System Task&lt;/span&gt;&lt;/a&gt; and &lt;a href="http://paresh-sqldba.blogspot.com/2011/12/delete-files-from-specified-folder.html" target="_blank"&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Script Task&lt;/span&gt;&lt;/a&gt; in SSIS.&lt;br /&gt;
&lt;br /&gt;
&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=pareshsqldba-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0130622982&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="align: left; height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-5005313808510526753?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/lDP9L5v3LDyfEVsNq5GPJRba1nE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lDP9L5v3LDyfEVsNq5GPJRba1nE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/lDP9L5v3LDyfEVsNq5GPJRba1nE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lDP9L5v3LDyfEVsNq5GPJRba1nE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/--QJOpmp7OA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/5005313808510526753/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2011/12/archive-old-database-backup-files-using.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/5005313808510526753?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/5005313808510526753?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/--QJOpmp7OA/archive-old-database-backup-files-using.html" title="Archive old database backup files using TSQL Script - SQL Server" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://paresh-sqldba.blogspot.com/2011/12/archive-old-database-backup-files-using.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkIEQXc7fSp7ImA9WhRXEE8.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-6491598387858256500</id><published>2011-12-14T19:47:00.002+05:30</published><updated>2011-12-16T15:11:40.905+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-16T15:11:40.905+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SSIS" /><category scheme="http://www.blogger.com/atom/ns#" term="SSDT" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server General" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql" /><title>Delete files from specified folder using Script Task in SQL Server - SSIS</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Earlier we have seen for the &lt;a href="http://paresh-sqldba.blogspot.com/2011/12/delete-files-from-specified-folder.html" target="_blank"&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;files deletion using File System Task&lt;/span&gt;&lt;/a&gt; in SSIS. We have used it with Foreach Loop Container. Used a variable to hold file names which are passed from earlier stage one by one and then finally used with File System Task to delete it.&lt;br /&gt;
&lt;br /&gt;
Now i am going to use Script Task to delete all files from specified folder. Here i have added script to get each files from specified folder and then delete them as you can see in the following steps. Lets start to follow them.&lt;br /&gt;
&lt;br /&gt;
1. Drag and drop Script Task.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-nVX-crqx8u4/Tuit4tft8KI/AAAAAAAABHk/D85VIUUVYqs/s1600/deletefile2_0.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="219" src="http://2.bp.blogspot.com/-nVX-crqx8u4/Tuit4tft8KI/AAAAAAAABHk/D85VIUUVYqs/s640/deletefile2_0.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
2. Open script editor from the properties.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-J4NnKAdqkxg/Tuit_WzHs4I/AAAAAAAABHs/baZbcqfdYaE/s1600/deletefile2_4.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="542" src="http://1.bp.blogspot.com/-J4NnKAdqkxg/Tuit_WzHs4I/AAAAAAAABHs/baZbcqfdYaE/s640/deletefile2_4.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
3. Apply attached script in editor and save it.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-7u5qT_scahg/TuiuGa30jMI/AAAAAAAABH0/1L415i0up_g/s1600/deletefile2_1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="307" src="http://1.bp.blogspot.com/-7u5qT_scahg/TuiuGa30jMI/AAAAAAAABH0/1L415i0up_g/s640/deletefile2_1.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;Please note here we need to import system.IO namespace.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
4. Turn on final step and run package. Files get deleted.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-qC85bqr5Iio/TuiuZhS80mI/AAAAAAAABH8/wpbWRWtpBFc/s1600/deletefile2_3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="428" src="http://4.bp.blogspot.com/-qC85bqr5Iio/TuiuZhS80mI/AAAAAAAABH8/wpbWRWtpBFc/s640/deletefile2_3.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
You can also find script code here,&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;--// You need to apply below one line in "namespaces" region.
using System.IO;

--//You need to apply below lines inplace of &amp;nbsp;// TODO: Add your code here

&amp;nbsp;string directoryPath = @"E:\TestFolder";
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; string[] oldFiles = System.IO.Directory.GetFiles(directoryPath, "*.txt");
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; foreach (string currFile in oldFiles)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FileInfo currFileInfo = new FileInfo(currFile);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; currFileInfo.Delete();
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }
&lt;/pre&gt;&lt;br /&gt;
Hope you liked this post. Stay tuned for more.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-6491598387858256500?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/MmV75tX678KH2ia-oedG8c_Q394/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MmV75tX678KH2ia-oedG8c_Q394/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/MmV75tX678KH2ia-oedG8c_Q394/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MmV75tX678KH2ia-oedG8c_Q394/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/N_i1BvZCO9o" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/6491598387858256500/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2011/12/delete-files-from-specified-folder_14.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/6491598387858256500?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/6491598387858256500?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/N_i1BvZCO9o/delete-files-from-specified-folder_14.html" title="Delete files from specified folder using Script Task in SQL Server - SSIS" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-nVX-crqx8u4/Tuit4tft8KI/AAAAAAAABHk/D85VIUUVYqs/s72-c/deletefile2_0.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://paresh-sqldba.blogspot.com/2011/12/delete-files-from-specified-folder_14.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUYMQn45eSp7ImA9WhRXEE4.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-1162775868849608700</id><published>2011-12-10T18:58:00.002+05:30</published><updated>2011-12-16T16:29:43.021+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-16T16:29:43.021+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="t-sql" /><category scheme="http://www.blogger.com/atom/ns#" term="SSIS" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server General" /><category scheme="http://www.blogger.com/atom/ns#" term="tsql" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql" /><title>Delete files from specified folder using File System Task in SQL Server - SSIS</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;We know all the various methods to delete the particular or all files from the specified folder using some of the methods like &lt;a href="http://beyondrelational.com/justlearned/posts/347/sql-server-to-delete-old-backup-db-files.aspx"&gt;xp_delete_file&lt;/a&gt;,&amp;nbsp;&lt;a href="http://beyondrelational.com/justlearned/posts/841/delete-files-using-ole-automation-procedures-in-sql-server.aspx" target="_blank"&gt;Ole Automation Procedures&lt;/a&gt;&amp;nbsp;and with xp_cmdshell&amp;nbsp;command line&amp;nbsp;utility which we used for the old files archive or cleanup purpose.&lt;br /&gt;
&lt;br /&gt;
Here i am going to share some of the screens which delete the files with SSIS using&amp;nbsp;File System Task. Let me share them one by one.&lt;br /&gt;
&lt;br /&gt;
1. Folder having some test files.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-r6HQtgHLuJk/TuNIn73mKFI/AAAAAAAABGc/KYjnv3JXtFg/s1600/deletefile1_0.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="145" src="http://1.bp.blogspot.com/-r6HQtgHLuJk/TuNIn73mKFI/AAAAAAAABGc/KYjnv3JXtFg/s640/deletefile1_0.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
2. Drag and drop Foreach Loop Container and File System Task. &amp;nbsp;Foreach Loop Container used to get all the files inside that folder one by one and process with File System Task.&amp;nbsp;Open the&amp;nbsp;Foreach Loop Container properties, goto Collection tab and select Foreach File Enumerator as specified in screen below.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-nNurwAREGlY/TuNI3kNlT_I/AAAAAAAABGk/F90wjygLZWA/s1600/deletefile1_2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="337" src="http://4.bp.blogspot.com/-nNurwAREGlY/TuNI3kNlT_I/AAAAAAAABGk/F90wjygLZWA/s640/deletefile1_2.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
3. Select the folder from where need to delete the files. Also apply extension if you need.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-F7Qvx85m79Q/TuNJLejQXSI/AAAAAAAABGs/WeaI-6aUi5s/s1600/deletefile1_3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="440" src="http://1.bp.blogspot.com/-F7Qvx85m79Q/TuNJLejQXSI/AAAAAAAABGs/WeaI-6aUi5s/s640/deletefile1_3.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-5a8ZF2vrD5o/TuNJQihbuvI/AAAAAAAABG0/w25Zy8dbdkI/s1600/deletefile1_4.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="409" src="http://3.bp.blogspot.com/-5a8ZF2vrD5o/TuNJQihbuvI/AAAAAAAABG0/w25Zy8dbdkI/s640/deletefile1_4.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;4. For the file assignment we need one variable and the values allocated from&amp;nbsp;Foreach Loop Container process. So assign it from variable mapping as per shot taken below.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-psuEqXV2HiQ/TuNJb877eII/AAAAAAAABG8/TI2iF8i2fxY/s1600/deletefile1_5.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="376" src="http://1.bp.blogspot.com/-psuEqXV2HiQ/TuNJb877eII/AAAAAAAABG8/TI2iF8i2fxY/s640/deletefile1_5.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-8DoALKnzBqQ/TuNJcRobRcI/AAAAAAAABHE/Vj6sFu3zG58/s1600/deletefile1_6.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="323" src="http://1.bp.blogspot.com/-8DoALKnzBqQ/TuNJcRobRcI/AAAAAAAABHE/Vj6sFu3zG58/s640/deletefile1_6.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
5. Drag File System Task, select Delete File operation and define Source Connection.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-8EJQ-aV1TWg/TuNJq9f6PZI/AAAAAAAABHM/AKwdMOjo9HM/s1600/deletefile1_8.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="371" src="http://4.bp.blogspot.com/-8EJQ-aV1TWg/TuNJq9f6PZI/AAAAAAAABHM/AKwdMOjo9HM/s640/deletefile1_8.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-VW8UoSXSvnA/TuNJrRpoVHI/AAAAAAAABHU/g-3i2FQX8fg/s1600/deletefile1_9.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="451" src="http://3.bp.blogspot.com/-VW8UoSXSvnA/TuNJrRpoVHI/AAAAAAAABHU/g-3i2FQX8fg/s640/deletefile1_9.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
6. Finally run package and files will get deleted.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-Ds3Ap6ej5sw/TuNJzXNyiTI/AAAAAAAABHc/x6C2VZlZL9U/s1600/deletefile1_10.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="465" src="http://4.bp.blogspot.com/-Ds3Ap6ej5sw/TuNJzXNyiTI/AAAAAAAABHc/x6C2VZlZL9U/s640/deletefile1_10.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-1162775868849608700?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/7LSkdvQsP6HrDvXhaLqxcgSx9vE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/7LSkdvQsP6HrDvXhaLqxcgSx9vE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/7LSkdvQsP6HrDvXhaLqxcgSx9vE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/7LSkdvQsP6HrDvXhaLqxcgSx9vE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/fXRecej_vuQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/1162775868849608700/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2011/12/delete-files-from-specified-folder.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/1162775868849608700?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/1162775868849608700?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/fXRecej_vuQ/delete-files-from-specified-folder.html" title="Delete files from specified folder using File System Task in SQL Server - SSIS" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-r6HQtgHLuJk/TuNIn73mKFI/AAAAAAAABGc/KYjnv3JXtFg/s72-c/deletefile1_0.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://paresh-sqldba.blogspot.com/2011/12/delete-files-from-specified-folder.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEQBRng_eip7ImA9WhRRGU0.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-8521853271296751737</id><published>2011-12-02T20:33:00.002+05:30</published><updated>2011-12-03T14:22:37.642+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-03T14:22:37.642+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server General" /><category scheme="http://www.blogger.com/atom/ns#" term="query" /><category scheme="http://www.blogger.com/atom/ns#" term="JustLearned" /><category scheme="http://www.blogger.com/atom/ns#" term="tsql" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="new features" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server" /><category scheme="http://www.blogger.com/atom/ns#" term="t-sql" /><category scheme="http://www.blogger.com/atom/ns#" term="Enhancements" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL new features" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql" /><title>My recent blog posts and just learned tips - SQL Server</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Recently I have posted some of the articles and some just learned from the month of&amp;nbsp;October. This article just summarize all the posts which recently published. You can find the links below to go in the details.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;&lt;b&gt;Blog Posts:&lt;/b&gt;&lt;/span&gt;&lt;/u&gt;&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;&lt;li&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/10/database-owner-sid-recorded-in-master.html" target="_blank"&gt;The database owner SID recorded in the master database differs from the database owner SID recorded in database&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/10/database-backup-files-verification-and.html" target="_blank"&gt;Database Backup files Verification and Details&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/10/grouping-sets-vs-native-method-of-group.html" target="_blank"&gt;Grouping Sets vs Native method of Group By - Performance review&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/05/multi-server-query-with-central.html" target="_blank"&gt;Multi server Query with Central Management Servers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/09/how-to-reset-sql-server-all-default.html" target="_blank"&gt;How to reset SQL Server all default settings in SQL Server Denali CTP3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/09/stored-procedure-internal-activation-in.html" target="_blank"&gt;Stored Procedure Internal Activation in Service Broker&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/09/new-logical-functions-coming-in-sql.html" target="_blank"&gt;New Logical functions coming in SQL Server Denali CTP3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/09/rollback-transaction-request-has-no.html" target="_blank"&gt;The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/09/new-string-functions-arrived-by-sql.html" target="_blank"&gt;New String functions arrived by SQL Server Denali CTP3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/09/service-broker-conversation-between.html" target="_blank"&gt;Service Broker - Conversation between Databases&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/11/backup-statistics-and-history-sql.html" target="_blank"&gt;Backup Statistics and History&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/05/nolock-hint-read-uncommitted-isolation.html" target="_blank"&gt;NOLOCK Hint &amp;amp; READ UNCOMMITTED Isolation level On table and Query/Session level&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/11/can-not-add-shared-registered-server.html" target="_blank"&gt;Can not add a shared registered server with the same name as configuration Server&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/11/database-backup-compression-amazing.html" target="_blank"&gt;Database Backup Compression, Amazing feature for DBA&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/11/review-of-some-replication-issues-and.html" target="_blank"&gt;Review of some replication issues and workaround&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/11/multi-monitor-support-of-ssms-new.html" target="_blank"&gt;Multi Monitor Support of SSMS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div&gt;&lt;u&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;&lt;b&gt;Just Learned tips:&lt;/b&gt;&lt;/span&gt;&lt;/u&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;&lt;a href="http://beyondrelational.com/justlearned/posts/813/script-to-download-file-via-ftp-in-sql-server.aspx" target="_blank"&gt;Script to download file via FTP in SQL Server&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://beyondrelational.com/justlearned/posts/791/perform-database-backup-using-sqlcmd-utility-in-sql-server.aspx" target="_blank"&gt;Perform database backup using SQLCMD utility in SQL Server&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://beyondrelational.com/justlearned/posts/785/sql-server-could-not-connect-to-server-remoteserver-because-localserver-is-not-defined-as-a-remote-server-in-sql-server-error-during-updating-data-in-remote-server.aspx" target="_blank"&gt;Could not connect to server 'RemoteServer' because 'LocalServer' is not defined as a remote server in sql server&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://beyondrelational.com/justlearned/posts/773/could-not-find-stored-procedure-spmsinstablename-in-replication-in-sql-server-replication-log-reader-agent-error-in-sql-server.aspx" target="_blank"&gt;Could not find stored procedure 'sp_MSins_TableName' in replication in sql server&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://beyondrelational.com/justlearned/posts/768/sql-server-there-is-insufficient-system-memory-to-run-this-query-error-encountered-for-subscriber-database-in-replicarion.aspx" target="_blank"&gt;There is insufficient system memory to run this query&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://beyondrelational.com/justlearned/posts/760/change-sql-server-instance-name-sql-server.aspx" target="_blank"&gt;Change SQL Server instance name&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://beyondrelational.com/justlearned/posts/747/adding-the-transactional-pull-subscriptions-to-a-publication-in-replication-sql-server.aspx" target="_blank"&gt;Adding a transactional pull subscriptions to a publication in replication&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://beyondrelational.com/justlearned/posts/736/adding-indexed-views-in-publication-for-transactional-replication-sql-server.aspx" target="_blank"&gt;Adding Indexed views in publication for transactional replication&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://beyondrelational.com/justlearned/posts/730/adding-the-transactional-publication-in-replication-sql-server.aspx" target="_blank"&gt;Adding the transactional publication in Replication&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://beyondrelational.com/justlearned/posts/724/enabling-the-replication-database-in-sql-server.aspx" target="_blank"&gt;Enabling the replication database&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://beyondrelational.com/justlearned/posts/714/.aspx" target="_blank"&gt;Add Functions in publication for transactional replication using tsql script&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://beyondrelational.com/justlearned/posts/709/add-stored-procedures-in-publication-in-transactional-replication-using-script-sql-server.aspx" target="_blank"&gt;Add Stored Procedures in publication for transactional replication using script&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://beyondrelational.com/justlearned/posts/701/.aspx" target="_blank"&gt;Script to add views in existing publication in transactional replication&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://beyondrelational.com/justlearned/posts/692/script-to-add-table-in-existing-publication-in-replication-sql-server.aspx" target="_blank"&gt;Script to add table in existing publication in transactional replication&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;Hope these posts help you.&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-8521853271296751737?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/oRcxc8Qsjqro_xVSxwXS47Md0mU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/oRcxc8Qsjqro_xVSxwXS47Md0mU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/oRcxc8Qsjqro_xVSxwXS47Md0mU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/oRcxc8Qsjqro_xVSxwXS47Md0mU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/uWAJyZdweBQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/8521853271296751737/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2011/12/my-recent-blog-posts-and-just-learned.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/8521853271296751737?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/8521853271296751737?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/uWAJyZdweBQ/my-recent-blog-posts-and-just-learned.html" title="My recent blog posts and just learned tips - SQL Server" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><thr:total>1</thr:total><feedburner:origLink>http://paresh-sqldba.blogspot.com/2011/12/my-recent-blog-posts-and-just-learned.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEINRXg7fSp7ImA9WhRRFks.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-6877206388048005372</id><published>2011-11-30T19:46:00.000+05:30</published><updated>2011-11-30T19:46:34.605+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-30T19:46:34.605+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2008" /><category scheme="http://www.blogger.com/atom/ns#" term="statistics" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL SERVER 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server General" /><category scheme="http://www.blogger.com/atom/ns#" term="tsql" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql" /><category scheme="http://www.blogger.com/atom/ns#" term="t-sql" /><category scheme="http://www.blogger.com/atom/ns#" term="backup" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2011" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql" /><title>Backup Statistics and History - SQL Server</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Every DBA has a daily activity review or monitor database backups as these database backups used for the&amp;nbsp;restoration at other place and using for the database restore which used for reporting purpose or used in log shipping purpose. Because database backups are most important factor and first option in case of&amp;nbsp;disaster&amp;nbsp;recovery even whatever types of them because in this case transaction logs can reduce the data loses.&lt;br /&gt;
&lt;br /&gt;
You can read my earlier posts for&amp;nbsp;&lt;b&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/11/database-backup-compression-amazing.html" target="_blank"&gt;Database Backup Compression&lt;/a&gt;,&amp;nbsp;&lt;a href="http://paresh-sqldba.blogspot.com/2011/10/database-backup-files-verification-and.html" target="_blank"&gt;Database Backup files Verification&lt;/a&gt; &lt;/b&gt;,&amp;nbsp;&lt;b&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/08/automated-all-databases-backups-script.html" target="_blank"&gt;Automated All Databases Backups Script&lt;/a&gt;&amp;nbsp;&lt;/b&gt;and&amp;nbsp;&lt;b&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/08/split-database-full-backup-to-mupltiple.html" target="_blank"&gt;Split Database Full Backup to Multiple files&lt;/a&gt;.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
I would like share the script which help us to show the database backups status,&amp;nbsp;history of their when they are done based on schedule, at where are taking and when, backup types&amp;nbsp;, backups physical device and size of the database backups and time to perform backup and all other related backup statistics.&amp;nbsp;Here is the script to collect the database backup statistics and status information.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE MSDB
GO

SELECT 
bs.server_name AS Server, -- Server name
bs.database_name AS DatabseName , -- Database name
CASE bs.compatibility_level 
 WHEN 80 THEN 'SQL Server 2000'
 WHEN 90 THEN 'SQL Server 2005 '
 WHEN 100 THEN 'SQL Server 2008'
 WHEN 110 THEN 'SQL Server 2011'
END AS CompatibilityLevel , -- Return backup compatibility level
recovery_model AS Recoverymodel , -- Database recovery model
CASE bs.type 
 WHEN 'D' THEN 'Full' 
 WHEN 'I' THEN 'Differential' 
 WHEN 'L' THEN 'Log' 
 WHEN 'F' THEN 'File or filegroup' 
 WHEN 'G' THEN 'Differential file' 
 WHEN 'P' THEN 'P' 
 WHEN 'Q' THEN 'Differential partial' 
 END AS BackupType, -- Type of database baclup
bs.backup_start_date AS BackupstartDate, -- Backup start date
bs.backup_finish_date AS BackupFinishDate,  -- Backup finish date
bmf.physical_device_name AS PhysicalDevice, -- baclup Physical localtion
CASE device_type
 WHEN 2 THEN 'Disk - Temporary'
 WHEN 102  THEN 'Disk - Permanent'
 WHEN 5  THEN 'Tape - Temporary'
 WHEN 105  THEN 'Tape - Temporary'
 else 'Other Device'
END AS DeviceType, -- Device type
bs.backup_size AS  [BackupSize(In bytes)],  -- Normal backup size (In bytes)
compressed_backup_size AS [ConmpressedBackupSize(In bytes)] -- Compressed backup size (In bytes)
FROM msdb.dbo.backupset bs 
INNER JOIN msdb.dbo.backupmediafamily bmf
ON (bs.media_set_id=bmf.media_set_id)
ORDER BY bs.backup_start_date DESC

GO
&lt;/pre&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-j1Yk4mkvcFs/TdhyJLO__XI/AAAAAAAAAlk/WdzopuNjIT4/s1600/Backup_Status_History.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="325" src="http://2.bp.blogspot.com/-j1Yk4mkvcFs/TdhyJLO__XI/AAAAAAAAAlk/WdzopuNjIT4/s640/Backup_Status_History.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
The transact-SQL for backupmediafamily and backupset are accordingly are http://msdn.microsoft.com/en-us/library/ms190284.aspx and http://msdn.microsoft.com/en-us/library/ms186299.aspx&lt;br /&gt;
&lt;br /&gt;
Hope you liked this post.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-6877206388048005372?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Z5pempQj3vopjZG_LEh6v788iK4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Z5pempQj3vopjZG_LEh6v788iK4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Z5pempQj3vopjZG_LEh6v788iK4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Z5pempQj3vopjZG_LEh6v788iK4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/gGOTW3Byx6Y" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/6877206388048005372/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2011/11/backup-statistics-and-history-sql.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/6877206388048005372?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/6877206388048005372?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/gGOTW3Byx6Y/backup-statistics-and-history-sql.html" title="Backup Statistics and History - SQL Server" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-j1Yk4mkvcFs/TdhyJLO__XI/AAAAAAAAAlk/WdzopuNjIT4/s72-c/Backup_Status_History.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://paresh-sqldba.blogspot.com/2011/11/backup-statistics-and-history-sql.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEAHQX46fCp7ImA9WhRQGEo.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-5455637831414636454</id><published>2011-11-25T19:33:00.002+05:30</published><updated>2011-12-14T19:55:30.014+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-14T19:55:30.014+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2008" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL SERVER 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server Denali" /><category scheme="http://www.blogger.com/atom/ns#" term="tsql" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="lock" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql" /><category scheme="http://www.blogger.com/atom/ns#" term="t-sql" /><category scheme="http://www.blogger.com/atom/ns#" term="hint" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server Code Named Denali" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2011" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql" /><title>NOLOCK Hint &amp; READ UNCOMMITTED Isolation level on table and Query/Session level - SQL Server</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;When we created a new database it will be created with default isolation level and that is "READ COMMITTED".&amp;nbsp;If some update transactions are running in with table rows under READ COMMITTED isolation level, How can we get data from table in another session while running update transaction?&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;u&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;How can ?&lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
NOLOCK hint or READ UNCOMMITTED isolatino level help for the same as ther are operating same. we have some another options other than this.&amp;nbsp;But i am going to present the NOLOCK hint and READ UNCOMMITTED&amp;nbsp;isolation&amp;nbsp;level here.&lt;br /&gt;
&lt;br /&gt;
For &lt;u&gt;NOLOCK&lt;/u&gt; , we need to put this hint on table level, so it is require to put for every tables level which are used in update transaction. So it is very lengthy and time consuming to put it everywhere tables refers in query.&amp;nbsp;For &lt;u&gt;READ UNCOMMITTED&lt;/u&gt;, We do not need to put it every tables level, just put at session level or query level and can be written at top of the query or stored procedure.&lt;br /&gt;
&lt;br /&gt;
Let us look on small demo to elaborate it. First checking here database default isolation level&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: blue;"&gt;USE DEMO&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: blue;"&gt;GO&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: blue;"&gt;DBCC USEROPTIONS&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-cPHq4f1xrgw/Tc5OA94gJVI/AAAAAAAAAgY/KoUXN20L1to/s1600/NoLock-3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="http://4.bp.blogspot.com/-cPHq4f1xrgw/Tc5OA94gJVI/AAAAAAAAAgY/KoUXN20L1to/s400/NoLock-3.png" width="344" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Starting with creating database and table objects.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;IF (OBJECT_ID('TrnTable','U') &amp;gt; 0)
DROP TABLE TrnTable

CREATE TABLE TrnTable
(
TrnId INT ,
TrnData VARCHAR(100),
TrnDate DATETIME
)

GO

-- Inserting some sample records in table

INSERT INTO TrnTable(TrnId,TrnData,TrnDate)
SELECT 1,'TrnData-1',GETDATE()
UNION ALL
SELECT 2,'TrnData-2',GETDATE()
UNION ALL
SELECT 3,'TrnData-3',GETDATE()
UNION ALL
SELECT 4,'TrnData-4',GETDATE()
UNION ALL
SELECT 5,'TrnData-5',GETDATE()

GO
&lt;/pre&gt;&lt;br /&gt;
Now for the demo we will run the below script with session 1&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;-- Script in session 1
-- Running query with transaction named TRAN1
BEGIN TRANSACTION TRAN1

UPDATE TrnTable
SET TrnData = 'Changed TrnData'
WHERE TrnId = 3
-- Not Committed/Rollback this transaction
&lt;/pre&gt;&lt;br /&gt;
After that we will get the same rows which are updating in above session which are not committed yet in another session. It will be go on waiting to release the lock held by session 1.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-ziIzVDw-nA0/Tc5PZ5FWRUI/AAAAAAAAAgg/V_MmrJw47xA/s1600/nolock-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="331" src="http://2.bp.blogspot.com/-ziIzVDw-nA0/Tc5PZ5FWRUI/AAAAAAAAAgg/V_MmrJw47xA/s400/nolock-1.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
We are not closing this transacrion here , and created a new session and run following scripts having NOLOCK hint on table level&amp;nbsp;and READ UNCOMMITTED isolation level on query level.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;-- Script in session 3
-- With NOLOCK hint
SELECT 
TrnId,
TrnData,
TrnDate
FROM TrnTable (NOLOCK)
WHERE TrnId = 3

GO

-- With READ UNCOMMITTED isolation level 
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED 

SELECT 
TrnId,
TrnData,
TrnDate
FROM TrnTable
WHERE TrnId = 3

GO
&lt;/pre&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-bvvoHSTa8qk/Tc5PhyaOnhI/AAAAAAAAAgo/B9w-AeND5yM/s1600/nolock-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="262" src="http://2.bp.blogspot.com/-bvvoHSTa8qk/Tc5PhyaOnhI/AAAAAAAAAgo/B9w-AeND5yM/s400/nolock-2.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Do not forget to commit or rollback transaction TRAN1&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: blue;"&gt;Commit Transaction TRAN1&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
I hope you liked this post. Please let me know what you are using among them or else something?&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-5455637831414636454?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/3ZnSKfnik1XUl3jekaxETrbZpg8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3ZnSKfnik1XUl3jekaxETrbZpg8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/3ZnSKfnik1XUl3jekaxETrbZpg8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3ZnSKfnik1XUl3jekaxETrbZpg8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/43R3M3LZHBs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/5455637831414636454/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2011/05/nolock-hint-read-uncommitted-isolation.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/5455637831414636454?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/5455637831414636454?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/43R3M3LZHBs/nolock-hint-read-uncommitted-isolation.html" title="NOLOCK Hint &amp; READ UNCOMMITTED Isolation level on table and Query/Session level - SQL Server" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-cPHq4f1xrgw/Tc5OA94gJVI/AAAAAAAAAgY/KoUXN20L1to/s72-c/NoLock-3.png" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://paresh-sqldba.blogspot.com/2011/05/nolock-hint-read-uncommitted-isolation.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkcGQXo7fyp7ImA9WhRSF0w.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-5346468733716995191</id><published>2011-11-19T19:10:00.000+05:30</published><updated>2011-11-19T19:10:20.407+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-19T19:10:20.407+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2008" /><category scheme="http://www.blogger.com/atom/ns#" term="sql errors" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server General" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server Denali" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server" /><category scheme="http://www.blogger.com/atom/ns#" term="Enhancements" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL new features" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2011" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server Problems" /><title>"Can not add a shared registered server with the same name as configuration Server" - Central Management Servers register error in SQL Server 2008</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;You may know how can we register SQL Server instances with Central Management Servers (CMS) and also how can we &lt;b&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/05/multi-server-query-with-central.html" target="_blank"&gt;perform multi server query&lt;/a&gt;&lt;/b&gt; will all of instances of registered SQL Server instances.&lt;br /&gt;
&lt;br /&gt;
There you can see i have registered one shared SQL Server 2011 instance under CMS and named it Denali.&amp;nbsp;Under Shared instance i have registered SQL Server 2008 and same SQL Server instance of Denali which i already registered.&lt;br /&gt;
&lt;br /&gt;
Here SQL server 2008 successfully registered but SQL Server 2011 has encountered error. But how i have registered it which i am going to explain here.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-93mnez5Z9kw/TcUT_5LdqRI/AAAAAAAAAdc/MIBj44UTRKk/s1600/cms_3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="140" src="http://4.bp.blogspot.com/-93mnez5Z9kw/TcUT_5LdqRI/AAAAAAAAAdc/MIBj44UTRKk/s400/cms_3.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
This is because same SQL instance already registered as shared SQL server.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;u&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;How can i register same SQL Server Denali or 2011 instance again?&lt;/span&gt;&lt;/b&gt;&lt;/u&gt;&lt;b&gt;&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
I have changed the port and applied static port as following from SQL Server TCP/IP properties which we will available at SQL Server Configuration Monitor.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-i6XHNGBXnEQ/TcUUjrXRueI/AAAAAAAAAdk/RxlPyn9i8YE/s1600/cms_4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="http://3.bp.blogspot.com/-i6XHNGBXnEQ/TcUUjrXRueI/AAAAAAAAAdk/RxlPyn9i8YE/s400/cms_4.png" width="358" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Then please see the screen shot below as i have register SQL Server Denali instance with port.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-0OFrO0bzeqQ/TcUU8xTX2AI/AAAAAAAAAds/TBirujPsSk4/s1600/cms_5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="http://2.bp.blogspot.com/-0OFrO0bzeqQ/TcUU8xTX2AI/AAAAAAAAAds/TBirujPsSk4/s400/cms_5.png" width="317" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Now both SQL Server registered successfully.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-vcSqQThWAMw/TcUahNZ4ZlI/AAAAAAAAAeU/-6tjhy5yMhg/s1600/cms_1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="330" src="http://4.bp.blogspot.com/-vcSqQThWAMw/TcUahNZ4ZlI/AAAAAAAAAeU/-6tjhy5yMhg/s400/cms_1.png" width="234" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Did you get it earlier? How did you resolved?&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-5346468733716995191?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/TA-oM4q5MRFs7BIFsJc1PRvDQLE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/TA-oM4q5MRFs7BIFsJc1PRvDQLE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/TA-oM4q5MRFs7BIFsJc1PRvDQLE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/TA-oM4q5MRFs7BIFsJc1PRvDQLE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/93EielRPqrQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/5346468733716995191/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2011/11/can-not-add-shared-registered-server.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/5346468733716995191?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/5346468733716995191?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/93EielRPqrQ/can-not-add-shared-registered-server.html" title="&quot;Can not add a shared registered server with the same name as configuration Server&quot; - Central Management Servers register error in SQL Server 2008" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-93mnez5Z9kw/TcUT_5LdqRI/AAAAAAAAAdc/MIBj44UTRKk/s72-c/cms_3.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://paresh-sqldba.blogspot.com/2011/11/can-not-add-shared-registered-server.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUcERH4yeip7ImA9WhRRFks.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-8306826666661411627</id><published>2011-11-16T19:44:00.001+05:30</published><updated>2011-11-30T19:53:25.092+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-30T19:53:25.092+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2008" /><category scheme="http://www.blogger.com/atom/ns#" term="tsql" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server" /><category scheme="http://www.blogger.com/atom/ns#" term="Performance" /><category scheme="http://www.blogger.com/atom/ns#" term="Enhancements" /><category scheme="http://www.blogger.com/atom/ns#" term="t-sql" /><category scheme="http://www.blogger.com/atom/ns#" term="backup" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL new features" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql" /><title>Database Backup Compression, Amazing feature for DBA - SQL Server 2008</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;
Production Database servers may have databases which are&amp;nbsp;heavily&amp;nbsp;in size. For the&amp;nbsp;maintenance&amp;nbsp;of those database backups are very hard and lengthy as the backups of those&amp;nbsp;heavily&amp;nbsp;databases take more tome to execute and very CPU, memory and IO consumptive.&amp;nbsp;And important thing is backups activity should be&amp;nbsp;completed&amp;nbsp;with in down time or pick time when more users are not connected with databases.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;&lt;i&gt;What is solution?&lt;/i&gt;&lt;/span&gt;&lt;/u&gt;&lt;br /&gt;
We have alternative ways to use the some backup tool that can help to use in this matter. &lt;br /&gt;
But SQL Server itself provide the best feature and supported SQL Server 2008 or newer version. &lt;br /&gt;
That is "Backup Compression". You can read my earlier posts for&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/08/automated-all-databases-backups-script.html" target="_blank"&gt;&amp;nbsp;Automated All Databases Backups&lt;/a&gt;&lt;/span&gt;, &lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/10/database-backup-files-verification-and.html" target="_blank"&gt;Database Backup files Verification and Details&lt;/a&gt;&lt;/span&gt; and &lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/08/split-database-full-backup-to-mupltiple.html" target="_blank"&gt;Split Database Full Backup to Multiple files&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Using this feature , we can take a database backups with compression option. And will really reduce time required to backup it, reduce server IO and less CPU and memory consumptive.&lt;br /&gt;
It is veryfull feature for the DBA.&lt;br /&gt;
&lt;br /&gt;
Let us look on below example which will clear you the difference between the noncompressed and compressed backups.We will first perform&amp;nbsp;non-compressed&amp;nbsp;backups for the database which have 4 GB size.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;Using Management Studio&lt;/span&gt;&lt;/b&gt;&lt;/i&gt; :&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-coXOxaUhtZk/Tdepeo03IiI/AAAAAAAAAkQ/SdtARMjf6sM/s1600/Compression_1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="361" src="http://3.bp.blogspot.com/-coXOxaUhtZk/Tdepeo03IiI/AAAAAAAAAkQ/SdtARMjf6sM/s400/Compression_1.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;&lt;b&gt;&lt;i&gt;Using TSQL:&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;#1. Performing noncompressed backup.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;SET STATISTICS IO ON
SET STATISTICS TIME ON

BACKUP DATABASE ReportServer TO  
DISK = N'D:\DBBackups\Compressed\ReportServer_NonCompressedBackup.bak' 
WITH NAME = N'ReportServer-Full NonCompressed Database Backup',
NO_COMPRESSION -- Specifying option here

SET STATISTICS IO OFF
SET STATISTICS TIME OFF
&lt;/pre&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-9HZh331QBSQ/TdepnoUM3HI/AAAAAAAAAkY/CdTAPDjdNxk/s1600/Compression_2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="198" src="http://4.bp.blogspot.com/-9HZh331QBSQ/TdepnoUM3HI/AAAAAAAAAkY/CdTAPDjdNxk/s640/Compression_2.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;i&gt;#2. Performing compressed backup.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;SET STATISTICS IO ON
SET STATISTICS TIME ON

BACKUP DATABASE ReportServer TO  
DISK = N'D:\DBBackups\Compressed\ReportServer_CompressedBackup.bak' 
WITH NAME = N'ReportServer-Full Compressed Database Backup',
COMPRESSION -- Specifying option here

SET STATISTICS IO OFF
SET STATISTICS TIME OFF
&lt;/pre&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-gYlf9TxlGv0/TdepuYCZX2I/AAAAAAAAAkg/SE-tIArIufI/s1600/Compression_3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="195" src="http://4.bp.blogspot.com/-gYlf9TxlGv0/TdepuYCZX2I/AAAAAAAAAkg/SE-tIArIufI/s640/Compression_3.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
From the result oputput , you can view the time for the backup execution, CPU usage.&lt;br /&gt;
Here you have screen for the both of the backups size.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-t_inp93TKnM/Tdep1tXZ2DI/AAAAAAAAAko/NnGYF5NzX7Q/s1600/Compression_4.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="192" src="http://1.bp.blogspot.com/-t_inp93TKnM/Tdep1tXZ2DI/AAAAAAAAAko/NnGYF5NzX7Q/s640/Compression_4.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
You can use below query to get the backup statistics,&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;SELECT 
bs.database_name AS DatabaseName , -- Database name
backup_size/compressed_backup_size as CompressionRatio, 
CASE bs.type 
 WHEN 'D' THEN 'Full' 
 WHEN 'I' THEN 'Differential' 
 WHEN 'L' THEN 'Log' 
 WHEN 'F' THEN 'File or filegroup' 
 WHEN 'G' THEN 'Differential file' 
 WHEN 'P' THEN 'P' 
 WHEN 'Q' THEN 'Differential partial' 
 END AS BackupType, -- Type of database baclup
bs.backup_start_date AS BackupstartDate, -- Backup start date
bs.backup_finish_date AS BackupFinishDate,  -- Backup finish date
bmf.physical_device_name AS PhysicalDevice, -- baclup Physical localtion
bs.backup_size AS  [BackupSize(In bytes)],  -- Normal backup size (In bytes)
compressed_backup_size AS [ConmpressedBackupSize(In bytes)] -- Compressed backup size (In bytes)
FROM msdb.dbo.backupset bs 
INNER JOIN msdb.dbo.backupmediafamily bmf
ON (bs.media_set_id=bmf.media_set_id)
and database_name = 'ReportServer'
ORDER BY bs.backup_start_date DESC
&lt;/pre&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-ZzURZgwnYiU/Tdep9g4LNCI/AAAAAAAAAkw/C2W4B3LcBXA/s1600/Compression_5.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="51" src="http://3.bp.blogspot.com/-ZzURZgwnYiU/Tdep9g4LNCI/AAAAAAAAAkw/C2W4B3LcBXA/s640/Compression_5.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
You can set the default backup setting to Compressed as following,&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;&lt;i&gt;By TSQL&lt;/i&gt;&lt;/span&gt; :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE MASTER
GO

EXEC SP_CONFIGURE 'backup compression default', 1
GO
RECONFIGURE WITH OVERRIDE;
GO
&lt;/pre&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;From UI&lt;/span&gt;&lt;/i&gt; :&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-YD2YSabDO0w/TdeqFfAQwmI/AAAAAAAAAk4/q1CewkFZ3WQ/s1600/Compression_6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="360" src="http://3.bp.blogspot.com/-YD2YSabDO0w/TdeqFfAQwmI/AAAAAAAAAk4/q1CewkFZ3WQ/s400/Compression_6.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
I hope you liked this feature..&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-8306826666661411627?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/hfdEjPzyB6x5DXypMt6Ncgy8WXE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hfdEjPzyB6x5DXypMt6Ncgy8WXE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/hfdEjPzyB6x5DXypMt6Ncgy8WXE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hfdEjPzyB6x5DXypMt6Ncgy8WXE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/VTsKRmBGQG4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/8306826666661411627/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2011/11/database-backup-compression-amazing.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/8306826666661411627?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/8306826666661411627?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/VTsKRmBGQG4/database-backup-compression-amazing.html" title="Database Backup Compression, Amazing feature for DBA - SQL Server 2008" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-coXOxaUhtZk/Tdepeo03IiI/AAAAAAAAAkQ/SdtARMjf6sM/s72-c/Compression_1.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://paresh-sqldba.blogspot.com/2011/11/database-backup-compression-amazing.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUEBR3Y9cCp7ImA9WhRTFEQ.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-2435307700984892769</id><published>2011-11-05T18:24:00.000+05:30</published><updated>2011-11-05T18:24:16.868+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-05T18:24:16.868+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Maintenance" /><category scheme="http://www.blogger.com/atom/ns#" term="sql errors" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server General" /><category scheme="http://www.blogger.com/atom/ns#" term="query" /><category scheme="http://www.blogger.com/atom/ns#" term="JustLearned" /><category scheme="http://www.blogger.com/atom/ns#" term="tsql" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server" /><category scheme="http://www.blogger.com/atom/ns#" term="Replication" /><category scheme="http://www.blogger.com/atom/ns#" term="t-sql" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server Problems" /><title>Review of some replication issues and workaround - SQL Server</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;
After posting some snaps to configure &lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2010/01/setup-replication-from-management.html" target="_blank"&gt;transactional replication&lt;/a&gt;&lt;/span&gt; in sql server having publication server as distributor, i want to share some of the issue which i got during working with it.&lt;br /&gt;
&lt;br /&gt;
You may also faced the same issue and got resolved as well. You can comment if you faced any other replication issues and the solution for the same. I have shared some of them as Just learned on http://beyondrelational.com.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;1."There is insufficient system memory to run this query" - Log reader agent error for subscriber database :&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
During working with replication this is one of the error which i encountered and get resolved it. This is coming with log reader agent and it stopped working. It's due to the issue memory. i have flushed the unused memory consumed by Adhoc queries and system cache.&lt;br /&gt;
&lt;br /&gt;
The error looks, &lt;span class="Apple-style-span" style="color: red;"&gt;"Error messages:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: red;"&gt;There is insufficient system memory to run this query. (Source: MSSQL_REPL, Error number: MSSQL_REPL27453)"&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
To flush the memory use the below commands,&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: blue;"&gt;DBCC FREESESSIONCACHE&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: blue;"&gt;DBCC FREEPROCCACHE&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: blue;"&gt;DBCC FREESYSTEMCACHE('ALL')&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
You can read the same tips &lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;a href="http://beyondrelational.com/justlearned/posts/768/sql-server-there-is-insufficient-system-memory-to-run-this-query-error-encountered-for-subscriber-database-in-replicarion.aspx" target="_blank"&gt;here&lt;/a&gt;&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;2. "Could not find stored procedure 'sp_MSins_TableName' in replication in sql server" - Log reader agent error:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
It came after reinitialize all subscription for one publication and it stopped working with error,&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: red;"&gt;"Could not find stored procedure 'sp_MSins_TableName' in replication in sql server"&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
This is due to replication object was not created for insert and named like 'sp_MSins_TableName'. The solution for this issue, we need to create these missing replication objects using 'sp_scriptpublicationcustomprocs' which generates scripts the custom INSERT, UPDATE, and DELETE procedures for all table articles in a publication. Workaround for the solution is,&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: blue;"&gt;EXEC sp_scriptpublicationcustomprocs 'PublicationName'&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
After running generated scripts in subscriber database, log reader agent started to work. You may read same tip &lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;a href="http://beyondrelational.com/justlearned/posts/773/sql-server-replication-could-not-find-stored-procedure-spmsinstablename-in-replication-in-sql-server-log-reader-agent-error-and-workaround.aspx" target="_blank"&gt;here&lt;/a&gt;&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;3."The row was not found at the Subscriber when applying the replicated command" :&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
It encountered it with log reader agent and it was stopped due to error as,&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: red;"&gt;"Command attempted:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: red;"&gt;if @@trancount &amp;gt; 0 rollback tran&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: red;"&gt;(Transaction sequence number: 0x000CAB2A00038CB6003B00000000, Command ID: 2)&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: red;"&gt;Error messages:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: red;"&gt;The row was not found at the Subscriber when applying the replicated command. (Source: MSSQLServer, Error number: 20598)"&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Row conflict issue was occurred due to some of the tables which we can get the details with following query to reach towards solution.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;SELECT
*
FROM dbo.MSarticles m
WHERE EXISTS
(
SELECT mc.Article_id from MSrepl_commands mc
WHERE mc.xact_seqno = 0x000CAB2A00038CB6003B00000000
and mc.Article_id = m.article_id
)
&lt;/pre&gt;&lt;br /&gt;
You can read it in details &lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;a href="http://beyondrelational.com/justlearned/posts/613/row-conflict-issue-with-replication-in-sql-server.aspx" target="_blank"&gt;here&lt;/a&gt;&lt;/span&gt;. I will share more replication errors if will get in future.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-2435307700984892769?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/dItyQyoUOpvdGNDDPU8yLTveYiU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/dItyQyoUOpvdGNDDPU8yLTveYiU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/dItyQyoUOpvdGNDDPU8yLTveYiU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/dItyQyoUOpvdGNDDPU8yLTveYiU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/NlASUhRm3uo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/2435307700984892769/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2011/11/review-of-some-replication-issues-and.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/2435307700984892769?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/2435307700984892769?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/NlASUhRm3uo/review-of-some-replication-issues-and.html" title="Review of some replication issues and workaround - SQL Server" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://paresh-sqldba.blogspot.com/2011/11/review-of-some-replication-issues-and.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0IERX0yeCp7ImA9WhRTE04.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-569848384721867346</id><published>2011-11-03T21:18:00.001+05:30</published><updated>2011-11-03T21:21:44.390+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-03T21:21:44.390+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Denali" /><category scheme="http://www.blogger.com/atom/ns#" term="Enhancements" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server Denali" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server Code Named Denali" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL new features" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2011" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql" /><title>Multi Monitor Support of SSMS - A new feature of SQL Server Denali</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I have drafted all the new features and enhancements introduced by SQL Server denali &lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/04/whats-new-with-sql-server-code-named.html"&gt;CTP1&lt;/a&gt;&lt;/span&gt;&lt;/b&gt; and &lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/07/sql-server-denali-ctp3-whats-new.html"&gt;CTP3&lt;/a&gt;&lt;/span&gt;&lt;/b&gt;. &amp;nbsp;&lt;i&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;Multi Monitor Support&lt;/span&gt;&lt;/i&gt; is the new feature among them.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;span class="Apple-style-span" style="color: #134f5c;"&gt;We can do with this feature&lt;/span&gt;:&lt;/u&gt;&lt;br /&gt;
1. Using this feature we can use multi screen of query analyzer or editor.&lt;br /&gt;
2. You can monitor&amp;nbsp;separately&amp;nbsp;it and run the output individually.&lt;br /&gt;
3. You can resize all the screens.&lt;br /&gt;
4. You can drag and drop at the place you want.&lt;br /&gt;
5. You can use Registered servers and object explorer and it's details with multi screens.&lt;br /&gt;
&lt;br /&gt;
For more idea, You can see the below screen shows which i have captured during enjoyed with it.&lt;br /&gt;
&lt;br /&gt;
1. This screen shot have multi screens of query analyzer with SSMS.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-IsaAGfVWkIk/TdHRR56A-cI/AAAAAAAAAiY/Ly3cyce2Gxw/s1600/multimonitor_1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="166" src="http://3.bp.blogspot.com/-IsaAGfVWkIk/TdHRR56A-cI/AAAAAAAAAiY/Ly3cyce2Gxw/s400/multimonitor_1.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
2. This screen shot captured during docking/undocking the screens.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-wZW7OV40RAU/TdHRich3unI/AAAAAAAAAic/yaOx-ga6dw4/s1600/multimonitor_2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="195" src="http://1.bp.blogspot.com/-wZW7OV40RAU/TdHRich3unI/AAAAAAAAAic/yaOx-ga6dw4/s400/multimonitor_2.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Hope you liked this post.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-569848384721867346?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/zqzyr9aOiewpTHfOv85WgE-trAc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zqzyr9aOiewpTHfOv85WgE-trAc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/zqzyr9aOiewpTHfOv85WgE-trAc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zqzyr9aOiewpTHfOv85WgE-trAc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/m20JjRYY2yU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/569848384721867346/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2011/11/multi-monitor-support-of-ssms-new.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/569848384721867346?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/569848384721867346?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/m20JjRYY2yU/multi-monitor-support-of-ssms-new.html" title="Multi Monitor Support of SSMS - A new feature of SQL Server Denali" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-IsaAGfVWkIk/TdHRR56A-cI/AAAAAAAAAiY/Ly3cyce2Gxw/s72-c/multimonitor_1.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://paresh-sqldba.blogspot.com/2011/11/multi-monitor-support-of-ssms-new.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0IHRH89eip7ImA9WhRTFEU.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-688073346922932073</id><published>2011-10-27T05:08:00.001+05:30</published><updated>2011-11-05T16:08:55.162+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-05T16:08:55.162+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2008" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL CLR" /><category scheme="http://www.blogger.com/atom/ns#" term="sql errors" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL SERVER 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server General" /><category scheme="http://www.blogger.com/atom/ns#" term="tsql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server" /><category scheme="http://www.blogger.com/atom/ns#" term="t-sql" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2011" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server Problems" /><title>"The database owner SID recorded in the master database differs from the database owner SID recorded in database" - SQL CLR DLL Register error in SQL Server</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Recently while working with SQL CLR functionality and created DLL for the SQL CLR.&lt;br /&gt;
But while registering this DLL in the database i got one surprised error.&lt;br /&gt;
&lt;br /&gt;
Lt's show you the script so you have more idea.&amp;nbsp;We have a script to register DLL as following,&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;SP_CONFIGURE 'clr enabled',1
GO
RECONFIGURE
GO

USE SQLCLRDb 
GO

CREATE ASSEMBLY [SQLCLR_ASSEMBLY] 
FROM 'C:\SQLCLR_ASSEMBLY.dll' WITH permission_set = UNSAFE 

GO 
&lt;/pre&gt;&lt;br /&gt;
And the error is coming like&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;The database owner SID recorded in the master database differs from the database owner SID recorded in database.&lt;br /&gt;
You should correct this situation by resetting the owner of database using the ALTER AUTHORIZATION statement.&lt;br /&gt;
&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
The solution for this issue is which we have the script below. This script will change db owner of the running database and make it trust worthy on.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE SQLCLRDb 
GO

ALTER DATABASE SQLCLRDb SET TRUSTWORTHY ON
go

EXEC SP_CHANGEDBOWNER 'UserName'
GO
&lt;/pre&gt;&lt;br /&gt;
After running above query, i come out from the issue and registered SQL CLR DLL successfully.&lt;br /&gt;
&lt;br /&gt;
I think you also suffered same or different issues with SQL CLR. Please comment your issues and the solution for the same.&lt;br /&gt;
&lt;br /&gt;
&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=pareshsqldba-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=1890774510&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="align: left; height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-688073346922932073?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/c9nqXWA-ePfdSNPJcnJPyP722ZQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/c9nqXWA-ePfdSNPJcnJPyP722ZQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/c9nqXWA-ePfdSNPJcnJPyP722ZQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/c9nqXWA-ePfdSNPJcnJPyP722ZQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/xCSsuXVMtxQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/688073346922932073/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2011/10/database-owner-sid-recorded-in-master.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/688073346922932073?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/688073346922932073?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/xCSsuXVMtxQ/database-owner-sid-recorded-in-master.html" title="&quot;The database owner SID recorded in the master database differs from the database owner SID recorded in database&quot; - SQL CLR DLL Register error in SQL Server" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://paresh-sqldba.blogspot.com/2011/10/database-owner-sid-recorded-in-master.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEYFRn0-fCp7ImA9WhdaEkg.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-7789421631621594923</id><published>2011-10-22T09:31:00.000+05:30</published><updated>2011-10-22T09:31:57.354+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-22T09:31:57.354+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="t-sql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server General" /><category scheme="http://www.blogger.com/atom/ns#" term="tsql" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="backup" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><title>Database Backup files Verification and Details - SQL Server</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;As a best practice, &amp;nbsp;DBA need to verify each database backups are properly done or not, also make sure the backups are OK then is readable and can be restored.&amp;nbsp;Because so many databases are scheduled as FULL and differential backups weekly/daily and transaction log backups on every hours or whatever as per requirement performing to avoing data loss.&lt;br /&gt;
&lt;br /&gt;
You can read my earlier articles for script to &lt;u&gt;&lt;b&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/08/automated-all-databases-backups-script.html"&gt;automated all types of database backup&lt;/a&gt;&lt;/b&gt;&lt;/u&gt; and &lt;u&gt;&lt;b&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/08/split-database-full-backup-to-mupltiple.html"&gt;split database backup to multiple files&lt;/a&gt;&lt;/b&gt;&lt;/u&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;&lt;i&gt;&lt;b&gt;How can we verify the backup files?&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
SQL Server provide VERIFYONLY clause and we can use it with Restore command. Please see the below details for the same as how it works.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;#1. VERIFYONLY&lt;/b&gt;&lt;br /&gt;
Verify databse backup integrity and checking backups are currupted or not.&lt;br /&gt;
Per SQL Book online,&amp;nbsp;Verifies the backup but does not restore it, and checks to see that the backup set is complete and the entire backup is readable.&lt;br /&gt;
However, RESTORE VERIFYONLY does not attempt to verify the structure of the data contained in the backup volumes. In Microsoft SQL Server,&amp;nbsp;RESTORE VERIFYONLY has been enhanced to do additional checking on the data to increase the probability of detecting errors.&amp;nbsp;The goal is to be as close to an actual restore operation as practical. For more information, see the Remarks.&lt;br /&gt;
&lt;br /&gt;
If the backup is valid, the SQL Server Database Engine returns a success message. &lt;br /&gt;
&lt;br /&gt;
Let us run the query to verify FULL, Differential and Transactional log backups and will see the output come out from it.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;RESTORE VERIFYONLY FROM DISK =  'D:\DBBackups\Backups\ReportServer_Backup_20110517_182654.bak'
GO
RESTORE VERIFYONLY FROM DISK =  'D:\DBBackups\Backups\ReportServer_Backup_20110517_183348.bak'
GO
RESTORE VERIFYONLY FROM DISK =  'D:\DBBackups\Backups\ReportServer_Backup_20110517_183843.trn'
GO
&lt;/pre&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-GV1-Sf8XPT8/Tdetc1GJKbI/AAAAAAAAAlA/JWqW6GV8iRM/s1600/DatabaseBackupFileInfo_1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="100" src="http://1.bp.blogspot.com/-GV1-Sf8XPT8/Tdetc1GJKbI/AAAAAAAAAlA/JWqW6GV8iRM/s400/DatabaseBackupFileInfo_1.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;&lt;b&gt;How can we get the backup files details?&lt;/b&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
Using HEADERONLY with Restore command we have details for database backup files.&lt;br /&gt;
Let us run the query to verify FULL, Differential and Transactional log backups and will see the output come out from it.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;#2. HEADERONLY&lt;/b&gt;&lt;br /&gt;
Per SQL Book online, Returns a result set containing all the backup header information for all backup sets on a particular backup device. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;RESTORE HEADERONLY FROM DISK =  'D:\DBBackups\Backups\ReportServer_Backup_20110517_182654.bak'
GO
RESTORE HEADERONLY FROM DISK =  'D:\DBBackups\Backups\ReportServer_Backup_20110517_183348.bak'
GO
RESTORE HEADERONLY FROM DISK =  'D:\DBBackups\Backups\ReportServer_Backup_20110517_183843.trn'
GO
&lt;/pre&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-sqg4vi9Uwzk/Tdetp8NX0_I/AAAAAAAAAlE/k4WRkiQHoE4/s1600/DatabaseBackupFileInfo_2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="340" src="http://2.bp.blogspot.com/-sqg4vi9Uwzk/Tdetp8NX0_I/AAAAAAAAAlE/k4WRkiQHoE4/s640/DatabaseBackupFileInfo_2.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Here another command FILELISTONLY which will the logical file and physical files details of backup files.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;#3. FILELISTONLY&lt;/b&gt;&lt;br /&gt;
Per SQL Book online, Returns a result set containing a list of the database and log files contained in the backup set.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;RESTORE FILELISTONLY FROM DISK =  'D:\DBBackups\Backups\ReportServer_Backup_20110517_182654.bak'
GO
RESTORE FILELISTONLY FROM DISK =  'D:\DBBackups\Backups\ReportServer_Backup_20110517_183348.bak'
GO
RESTORE FILELISTONLY FROM DISK =  'D:\DBBackups\Backups\ReportServer_Backup_20110517_183843.trn'
GO
&lt;/pre&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-uHxE-SyO4wo/Tdet8jwl0_I/AAAAAAAAAlI/2-D6g3mBpiQ/s1600/DatabaseBackupFileInfo_3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="180" src="http://2.bp.blogspot.com/-uHxE-SyO4wo/Tdet8jwl0_I/AAAAAAAAAlI/2-D6g3mBpiQ/s640/DatabaseBackupFileInfo_3.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
What you are performing activity with backups?&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-7789421631621594923?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/bhpncLvFmhiPBgaFDgYog4HoB38/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/bhpncLvFmhiPBgaFDgYog4HoB38/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/bhpncLvFmhiPBgaFDgYog4HoB38/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/bhpncLvFmhiPBgaFDgYog4HoB38/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/aRB4JBC2fF8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/7789421631621594923/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2011/10/database-backup-files-verification-and.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/7789421631621594923?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/7789421631621594923?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/aRB4JBC2fF8/database-backup-files-verification-and.html" title="Database Backup files Verification and Details - SQL Server" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-GV1-Sf8XPT8/Tdetc1GJKbI/AAAAAAAAAlA/JWqW6GV8iRM/s72-c/DatabaseBackupFileInfo_1.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://paresh-sqldba.blogspot.com/2011/10/database-backup-files-verification-and.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0INQHgyfCp7ImA9WhdbF04.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-1959277348753299792</id><published>2011-10-16T08:56:00.000+05:30</published><updated>2011-10-16T08:56:31.694+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-16T08:56:31.694+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2008" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server General" /><category scheme="http://www.blogger.com/atom/ns#" term="tsql" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server" /><category scheme="http://www.blogger.com/atom/ns#" term="Performance" /><category scheme="http://www.blogger.com/atom/ns#" term="t-sql" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL new features" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql" /><title>Grouping Sets vs Native method of Group By - Performance review in SQL Server 2008</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Previously i have posted for the overview and usage of the &lt;a href="http://paresh-sqldba.blogspot.com/2011/07/group-by-with-grouping-sets-in-sql.html"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Grouping Sets&lt;/span&gt;&lt;/b&gt;&lt;/a&gt; as how&amp;nbsp;can we get the aggregate data of different group sets with GROPING SETS vs Native method of group by.&lt;br /&gt;
&lt;br /&gt;
If you have not read my earlier post for the same then please read it before go ahead with this demonstration.&amp;nbsp;In this demo i am going to show the performance of  Grouping Sets and native method of group by.&lt;br /&gt;
&lt;br /&gt;
Let us start the demo here.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;-- Creatind database and table 
CREATE DATABASE GroupingDB

GO

USE GroupingDB

GO

IF (OBJECT_ID('GroupingTable') &amp;gt; 0)
DROP TABLE GroupingTable

CREATE TABLE GroupingTable
  (
     MainCategoryName VARCHAR(100)
     ,SubCategoryId   VARCHAR(100)
     ,VALUE           BIGINT
  )

GO 
&lt;/pre&gt;&lt;br /&gt;
Now we are going to insert so many records in table for the presentation of demo.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;-- Insert some demo records for diffrent group sets
INSERT INTO GroupingTable
SELECT 'Main-1','Sub-1',100
GO 500 

INSERT INTO GroupingTable
SELECT 'Main-1','Sub-2',200
GO 500 

INSERT INTO GroupingTable
SELECT 'Main-2','Sub-1',300
GO 500 

INSERT INTO GroupingTable
SELECT 'Main-3','Sub-1',300
GO 500 

INSERT INTO GroupingTable
SELECT 'Main-3','Sub-2',400
GO 500 
&lt;/pre&gt;&lt;br /&gt;
As i said to check the performance of both of the script using them&amp;nbsp;and check the execution plan.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;-- Get aggregate data using native method of group by of different sets
SELECT NULL, NULL,
  SUM(VALUE) as Total
FROM   GroupingTable
Union all
SELECT &amp;nbsp;MainCategoryName
,NULL
,SUM(VALUE) as Total
FROM   GroupingTable
GROUP  BY MainCategoryName 
Union all
SELECT  NULL,
  SubCategoryId
  ,SUM(VALUE) as Total
FROM   GroupingTable
GROUP  BY SubCategoryId 
union all
SELECT
  MainCategoryName
  ,SubCategoryId
  ,SUM(VALUE) as Total
FROM   GroupingTable
GROUP  BY
  MainCategoryName
  ,SubCategoryId

-- Get aggregate data using Grouping Sets of different sets
SELECT
  MainCategoryName
  ,SubCategoryId
  ,SUM(VALUE) as Total
FROM   GroupingTable
GROUP  BY
GROUPING SETS
(
  (MainCategoryName ,SubCategoryId),
  (MainCategoryName),
  (SubCategoryId),
  ()

)
ORDER BY MainCategoryName,SubCategoryId
&lt;/pre&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-BdlBDivhSIU/Tbf25aRj3qI/AAAAAAAAAZk/fLBPcPqQ2hs/s1600/PerforData_GroupingSets.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://2.bp.blogspot.com/-BdlBDivhSIU/Tbf25aRj3qI/AAAAAAAAAZk/fLBPcPqQ2hs/s640/PerforData_GroupingSets.png" width="611" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
You can see the data rows of above both scripts are same and given same result set.&lt;br /&gt;
Now look for execution plan.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-Fbjz9CElD_w/Tbf3DLC_NAI/AAAAAAAAAZs/_2LRqOAQOnM/s1600/Perfor_GroupingSets.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="366" src="http://1.bp.blogspot.com/-Fbjz9CElD_w/Tbf3DLC_NAI/AAAAAAAAAZs/_2LRqOAQOnM/s640/Perfor_GroupingSets.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
This performance review is&amp;nbsp;totally&amp;nbsp;based on the data and depends on the your business requirement.&lt;br /&gt;
Before implementing this new feature please check the execution and decide you view.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-1959277348753299792?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ODOMxGhjxNYOJrdt7IRkmIrcnZU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ODOMxGhjxNYOJrdt7IRkmIrcnZU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ODOMxGhjxNYOJrdt7IRkmIrcnZU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ODOMxGhjxNYOJrdt7IRkmIrcnZU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/asi01xgHyTM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/1959277348753299792/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2011/10/grouping-sets-vs-native-method-of-group.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/1959277348753299792?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/1959277348753299792?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/asi01xgHyTM/grouping-sets-vs-native-method-of-group.html" title="Grouping Sets vs Native method of Group By - Performance review in SQL Server 2008" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-BdlBDivhSIU/Tbf25aRj3qI/AAAAAAAAAZk/fLBPcPqQ2hs/s72-c/PerforData_GroupingSets.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://paresh-sqldba.blogspot.com/2011/10/grouping-sets-vs-native-method-of-group.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkEDSH4-eyp7ImA9WhdUFUg.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-8384976272927942946</id><published>2011-10-02T18:01:00.000+05:30</published><updated>2011-10-02T18:01:19.053+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-02T18:01:19.053+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2008" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server General" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server Denali" /><category scheme="http://www.blogger.com/atom/ns#" term="tsql" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server" /><category scheme="http://www.blogger.com/atom/ns#" term="t-sql" /><category scheme="http://www.blogger.com/atom/ns#" term="Enhancements" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL new features" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2011" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql" /><title>Multi server Query with Central Management Servers - SQL Server 2008</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Before SQL Server 2008 , when we need gather all information and details related to server or database level, we must run the script individually by connecting each SQL Server instances.&lt;br /&gt;
&lt;br /&gt;
But SQL Server 2008 came up and easy our work for that. It has introduced a new feature - Central Management Servers (CMS).&amp;nbsp;With Central Management Servers we can configure and register SQL Server instances with shared SQL Server instance. Then we run the query against all the SQL instance and get details for all instances.&lt;br /&gt;
&lt;br /&gt;
Let's you demonstrate the same in details here.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;i&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;1. How to open Central Management Servers?&lt;/span&gt;&lt;/b&gt;&lt;/i&gt;&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
Go to &lt;b&gt;View --&amp;gt; Registered Servers&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;/i&gt;&lt;/b&gt;or&lt;br /&gt;
press &lt;i&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;Ctrl + Alt + G&lt;/span&gt;&lt;/b&gt;.&lt;b&gt;&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;u&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;2. How can register SQL Server instances in CMS?&lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Expand Database engine from Registered Servers.&lt;br /&gt;
&lt;br /&gt;
Right click on CMS and click on Register SQL Server Management.&lt;br /&gt;
&lt;br /&gt;
The screen will appear like below,&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-AOr_Hgz_Rc8/TcUR8xWEZBI/AAAAAAAAAdU/OV8B2OA3j9U/s1600/CMS_2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="http://3.bp.blogspot.com/-AOr_Hgz_Rc8/TcUR8xWEZBI/AAAAAAAAAdU/OV8B2OA3j9U/s400/CMS_2.png" width="318" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
In above i have registered SQL Server Denali instance which will be shared SQL Server instance.&lt;br /&gt;
&lt;br /&gt;
Now I am creating new SQL Server Group under CMS and then register SQL Server 2008 and SQL Server 2011 by right click on group and then go on the link of registration and then go on same way as i did for SQL Server Denali instance.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-Nt1tkt9wakI/TcUW7iOFvqI/AAAAAAAAAeE/oAuzGbGMFBI/s1600/cms_1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="330" src="http://3.bp.blogspot.com/-Nt1tkt9wakI/TcUW7iOFvqI/AAAAAAAAAeE/oAuzGbGMFBI/s400/cms_1.png" width="234" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;u&gt;&lt;i&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;3. How can we perform multi server query against all SQL Server ?&lt;/span&gt;&lt;/b&gt;&lt;/i&gt;&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
Go on right click on Shared SQL Server instance under CMS and click on New Query.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-NCMfQp6atu0/TcUWXhUKVoI/AAAAAAAAAd0/N0AucgbKT8o/s1600/cms_6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="275" src="http://4.bp.blogspot.com/-NCMfQp6atu0/TcUWXhUKVoI/AAAAAAAAAd0/N0AucgbKT8o/s400/cms_6.png" width="387" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Let's do here same and execute the query and see what will be the result?&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-hvcINvpWn_Y/TcUWdkbASyI/AAAAAAAAAd8/wP6spZAJHdU/s1600/cms_7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="166" src="http://2.bp.blogspot.com/-hvcINvpWn_Y/TcUWdkbASyI/AAAAAAAAAd8/wP6spZAJHdU/s400/cms_7.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
This feature very help us to run the script against all the registered SQL Server instances. Hope you liked this post.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-8384976272927942946?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/GzBAxmxPaZAPgtjWxSRZbN4JvMQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/GzBAxmxPaZAPgtjWxSRZbN4JvMQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/GzBAxmxPaZAPgtjWxSRZbN4JvMQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/GzBAxmxPaZAPgtjWxSRZbN4JvMQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/OgGBdbhv0so" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/8384976272927942946/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2011/05/multi-server-query-with-central.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/8384976272927942946?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/8384976272927942946?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/OgGBdbhv0so/multi-server-query-with-central.html" title="Multi server Query with Central Management Servers - SQL Server 2008" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-AOr_Hgz_Rc8/TcUR8xWEZBI/AAAAAAAAAdU/OV8B2OA3j9U/s72-c/CMS_2.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://paresh-sqldba.blogspot.com/2011/05/multi-server-query-with-central.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CU4BQXsyeyp7ImA9WhdUE00.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-7252378943084206617</id><published>2011-09-29T19:15:00.000+05:30</published><updated>2011-09-29T19:15:50.593+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-29T19:15:50.593+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="sql errors" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server General" /><category scheme="http://www.blogger.com/atom/ns#" term="tsql" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="Agent" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server" /><category scheme="http://www.blogger.com/atom/ns#" term="t-sql" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server Problems" /><title>How to invoke Job thorugh SQL script - SQL Server</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;We are mostly create the SQL job and schedule it to run automated. But sometime as per requirement&amp;nbsp;we need to invoke and run on demand basis, not on schedules basis. &lt;br /&gt;
&lt;br /&gt;
I have did the same thing and the following is the small demo ready for you.&lt;br /&gt;
&lt;br /&gt;
Let's create one stored procedure and schedule in job.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE [Master]
GO

CREATE PROCEDURE JobInvokeProc
AS
BEGIN
SET NOCOUNT ON

WAITFOR DELAY '00:00:15';

END
GO
&lt;/pre&gt;&lt;br /&gt;
Now we will create the job for the same and execute this stored procedure in job.&lt;br /&gt;
&lt;br /&gt;
The created script for the job is as following,&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE [msdb]
GO

/****** Object:  Job [Start_JobInvokeProc]    Script Date: 05/05/2011 07:51:53 ******/
BEGIN TRANSACTION
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
/****** Object:  JobCategory [[Uncategorized (Local)]]]    Script Date: 05/05/2011 07:51:53 ******/
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'[Uncategorized (Local)]' AND category_class=1)
BEGIN
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'[Uncategorized (Local)]'
IF (@@ERROR &amp;lt;&amp;gt; 0 OR @ReturnCode &amp;lt;&amp;gt; 0) GOTO QuitWithRollback

END

DECLARE @jobId BINARY(16)
EXEC @ReturnCode =  msdb.dbo.sp_add_job @job_name=N'Start_JobInvokeProc', 
  @enabled=1, 
  @notify_level_eventlog=0, 
  @notify_level_email=0, 
  @notify_level_netsend=0, 
  @notify_level_page=0, 
  @delete_level=0, 
  @description=N'No description available.', 
  @category_name=N'[Uncategorized (Local)]', 
  @owner_login_name=N'paresh-PC\paresh', @job_id = @jobId OUTPUT
IF (@@ERROR &amp;lt;&amp;gt; 0 OR @ReturnCode &amp;lt;&amp;gt; 0) GOTO QuitWithRollback
/****** Object:  Step [Step_JobInvokeProc]    Script Date: 05/05/2011 07:51:54 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Step_JobInvokeProc', 
  @step_id=1, 
  @cmdexec_success_code=0, 
  @on_success_action=1, 
  @on_success_step_id=0, 
  @on_fail_action=2, 
  @on_fail_step_id=0, 
  @retry_attempts=0, 
  @retry_interval=0, 
  @os_run_priority=0, @subsystem=N'TSQL', 
  @command=N'exec JobInvokeProc', 
  @database_name=N'master', 
  @flags=0
IF (@@ERROR &amp;lt;&amp;gt; 0 OR @ReturnCode &amp;lt;&amp;gt; 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1
IF (@@ERROR &amp;lt;&amp;gt; 0 OR @ReturnCode &amp;lt;&amp;gt; 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'
IF (@@ERROR &amp;lt;&amp;gt; 0 OR @ReturnCode &amp;lt;&amp;gt; 0) GOTO QuitWithRollback
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollback:
    IF (@@TRANCOUNT &amp;gt; 0) ROLLBACK TRANSACTION
EndSave:

GO
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Now i have one more we i get from MSDB database and customize it which is used to get the SQL job status information as running or not.&lt;br /&gt;
&lt;br /&gt;
This is the script to get the Job status.&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE [master]
GO

CREATE PROCEDURE GetJobStatus     
  @job_Name           varchar(max),     
  @status INT OUTPUT    
AS      
BEGIN      
  DECLARE @can_see_all_running_jobs INT ,    
  @job_type           VARCHAR(12)     ,  -- LOCAL or MULTI-SERVER      
  @owner_login_name   sysname         ,      
  @subsystem          NVARCHAR(40)    ,      
  @category_id        INT             ,      
  @enabled            TINYINT         ,      
  @execution_status   INT             ,  -- 0 = Not idle or suspended, 1 = Executing, 2 = Waiting For Thread, 3 = Between Retries, 4 = Idle, 5 = Suspended, [6 = WaitingForStepToFinish], 7 = PerformingCompletionActions      
  @date_comparator    CHAR(1)         ,  -- &amp;gt;, &amp;lt; or =      
  @date_created       DATETIME        ,      
  @date_last_modified DATETIME        ,      
  @description        NVARCHAR(512)   ,  -- We do a LIKE on this so it can include wildcards      
  @schedule_id        INT                 
     
  set @job_type           = NULL  -- LOCAL or MULTI-SERVER      
  set  @owner_login_name  = NULL      
  set @subsystem          = NULL      
  set @category_id        = NULL      
  set @enabled            = NULL      
  set @execution_status   = NULL  -- 0 = Not idle or suspended, 1 = Executing, 2 = Waiting For Thread, 3 = Between Retries, 4 = Idle, 5 = Suspended, [6 = WaitingForStepToFinish], 7 = PerformingCompletionActions      
  set @date_comparator    = NULL  -- &amp;gt;, &amp;lt; or =      
  set @date_created       = NULL      
  set @date_last_modified = NULL      
  set @description        = NULL  -- We do a LIKE on this so it can include wildcards      
  set @schedule_id        = NULL     
    
  DECLARE @job_owner   sysname      
      
  declare @job_id UNIQUEIDENTIFIER     
  set @job_id = (select job_id from msdb.dbo.sysjobs where name = @job_Name)    
    
  SET NOCOUNT ON      
      
  -- By 'composite' we mean a combination of sysjobs and xp_sqlagent_enum_jobs data.      
  -- This proc should only ever be called by sp_help_job, so we don't verify the      
  -- parameters (sp_help_job has already done this).      
      
  -- Step 1: Create intermediate work tables      
  DECLARE @job_execution_state TABLE (job_id                  UNIQUEIDENTIFIER NOT NULL,      
                                     date_started            INT              NOT NULL,      
                                     time_started            INT              NOT NULL,      
                                     execution_job_status    INT              NOT NULL,      
                                     execution_step_id       INT              NULL,      
                                     execution_step_name     sysname          COLLATE database_default NULL,      
                                     execution_retry_attempt INT              NOT NULL,      
                                     next_run_date           INT              NOT NULL,      
                                     next_run_time           INT              NOT NULL,      
                                     next_run_schedule_id    INT              NOT NULL)      
  DECLARE @filtered_jobs TABLE (job_id                   UNIQUEIDENTIFIER NOT NULL,      
                               date_created             DATETIME         NOT NULL,      
                               date_last_modified       DATETIME         NOT NULL,      
                               current_execution_status INT              NULL,      
                               current_execution_step   sysname          COLLATE database_default NULL,      
                               current_retry_attempt    INT              NULL,      
                               last_run_date            INT              NOT NULL,      
                               last_run_time            INT              NOT NULL,      
                               last_run_outcome         INT              NOT NULL,      
                               next_run_date            INT              NULL,      
                               next_run_time            INT              NULL,      
                               next_run_schedule_id     INT           NULL,      
                               type                     INT              NOT NULL)      
  DECLARE @xp_results TABLE (job_id                UNIQUEIDENTIFIER NOT NULL,      
                            last_run_date         INT              NOT NULL,      
                            last_run_time         INT              NOT NULL,      
                            next_run_date         INT              NOT NULL,      
                            next_run_time         INT              NOT NULL,      
                            next_run_schedule_id  INT              NOT NULL,      
                            requested_to_run      INT              NOT NULL, -- BOOL      
                            request_source        INT              NOT NULL,      
                            request_source_id     sysname          COLLATE database_default NULL,      
                            running               INT              NOT NULL, -- BOOL      
                            current_step          INT              NOT NULL,      
                            current_retry_attempt INT              NOT NULL,      
                            job_state             INT              NOT NULL)      
      
  -- Step 2: Capture job execution information (for local jobs only since that's all SQLServerAgent caches)      
  SELECT @can_see_all_running_jobs = ISNULL(IS_SRVROLEMEMBER(N'sysadmin'), 0)      
  IF (@can_see_all_running_jobs = 0)      
  BEGIN      
    SELECT @can_see_all_running_jobs = ISNULL(IS_MEMBER(N'SQLAgentReaderRole'), 0)      
  END      
  SELECT @job_owner = SUSER_SNAME()      
      
  IF ((@@microsoftversion / 0x01000000) &amp;gt;= 8) -- SQL Server 8.0 or greater      
    INSERT INTO @xp_results      
    EXECUTE master.dbo.xp_sqlagent_enum_jobs @can_see_all_running_jobs, @job_owner, @job_id      
  ELSE      
    INSERT INTO @xp_results      
    EXECUTE master.dbo.xp_sqlagent_enum_jobs @can_see_all_running_jobs, @job_owner      
      
  INSERT INTO @job_execution_state      
  SELECT xpr.job_id,      
         xpr.last_run_date,      
         xpr.last_run_time,      
         xpr.job_state,      
         sjs.step_id,      
         sjs.step_name,      
         xpr.current_retry_attempt,      
         xpr.next_run_date,      
         xpr.next_run_time,      
         xpr.next_run_schedule_id      
  FROM @xp_results                          xpr      
       LEFT OUTER JOIN msdb.dbo.sysjobsteps sjs ON ((xpr.job_id = sjs.job_id) AND (xpr.current_step = sjs.step_id)),      
       msdb.dbo.sysjobs_view                sjv      
  WHERE (sjv.job_id = xpr.job_id)      
      
  -- Step 3: Filter on everything but dates and job_type      
  IF ((@subsystem        IS NULL) AND      
      (@owner_login_name IS NULL) AND      
      (@enabled          IS NULL) AND      
      (@category_id      IS NULL) AND      
      (@execution_status IS NULL) AND      
      (@description      IS NULL) AND      
      (@job_id           IS NULL))      
  BEGIN      
    -- Optimize for the frequently used case...      
    INSERT INTO @filtered_jobs      
    SELECT sjv.job_id,      
           sjv.date_created,      
           sjv.date_modified,      
           ISNULL(jes.execution_job_status, 4), -- Will be NULL if the job is non-local or is not in @job_execution_state (NOTE: 4 = STATE_IDLE)      
           CASE ISNULL(jes.execution_step_id, 0)      
             WHEN 0 THEN NULL                   -- Will be NULL if the job is non-local or is not in @job_execution_state      
             ELSE CONVERT(NVARCHAR, jes.execution_step_id) + N' (' + jes.execution_step_name + N')'      
           END,      
           jes.execution_retry_attempt,         -- Will be NULL if the job is non-local or is not in @job_execution_state      
           0,  -- last_run_date placeholder    (we'll fix it up in step 3.3)      
           0,  -- last_run_time placeholder    (we'll fix it up in step 3.3)      
           5,  -- last_run_outcome placeholder (we'll fix it up in step 3.3 - NOTE: We use 5 just in case there are no jobservers for the job)      
           jes.next_run_date,                   -- Will be NULL if the job is non-local or is not in @job_execution_state      
           jes.next_run_time,                   -- Will be NULL if the job is non-local or is not in @job_execution_state      
           jes.next_run_schedule_id,            -- Will be NULL if the job is non-local or is not in @job_execution_state      
           0   -- type placeholder             (we'll fix it up in step 3.4)      
    FROM msdb.dbo.sysjobs_view                sjv      
         LEFT OUTER JOIN @job_execution_state jes ON (sjv.job_id = jes.job_id)      
    WHERE ((@schedule_id IS NULL)      
      OR   (EXISTS(SELECT *       
                 FROM msdb.dbo.sysjobschedules as js      
                 WHERE (sjv.job_id = js.job_id)      
                   AND (js.schedule_id = @schedule_id))))      
  END      
  ELSE      
  BEGIN      
    INSERT INTO @filtered_jobs      
    SELECT DISTINCT      
           sjv.job_id,      
           sjv.date_created,      
           sjv.date_modified,      
           ISNULL(jes.execution_job_status, 4), -- Will be NULL if the job is non-local or is not in @job_execution_state (NOTE: 4 = STATE_IDLE)      
           CASE ISNULL(jes.execution_step_id, 0)      
             WHEN 0 THEN NULL                   -- Will be NULL if the job is non-local or is not in @job_execution_state      
             ELSE CONVERT(NVARCHAR, jes.execution_step_id) + N' (' + jes.execution_step_name + N')'      
           END,      
           jes.execution_retry_attempt,         -- Will be NULL if the job is non-local or is not in @job_execution_state      
           0,  -- last_run_date placeholder    (we'll fix it up in step 3.3)      
           0,  -- last_run_time placeholder    (we'll fix it up in step 3.3)      
           5,  -- last_run_outcome placeholder (we'll fix it up in step 3.3 - NOTE: We use 5 just in case there are no jobservers for the job)      
           jes.next_run_date,                   -- Will be NULL if the job is non-local or is not in @job_execution_state      
           jes.next_run_time,                   -- Will be NULL if the job is non-local or is not in @job_execution_state      
           jes.next_run_schedule_id,            -- Will be NULL if the job is non-local or is not in @job_execution_state      
           0   -- type placeholder             (we'll fix it up in step 3.4)      
    FROM msdb.dbo.sysjobs_view                sjv      
         LEFT OUTER JOIN @job_execution_state jes ON (sjv.job_id = jes.job_id)      
         LEFT OUTER JOIN msdb.dbo.sysjobsteps sjs ON (sjv.job_id = sjs.job_id)      
    WHERE ((@subsystem        IS NULL) OR (sjs.subsystem            = @subsystem))      
      AND ((@owner_login_name IS NULL)       
          OR (sjv.owner_sid            = msdb.dbo.SQLAGENT_SUSER_SID(@owner_login_name)))--force case insensitive comparation for NT users      
      AND ((@enabled          IS NULL) OR (sjv.enabled              = @enabled))      
      AND ((@category_id      IS NULL) OR (sjv.category_id          = @category_id))      
      AND ((@execution_status IS NULL) OR ((@execution_status &amp;gt; 0) AND (jes.execution_job_status = @execution_status))      
                                       OR ((@execution_status = 0) AND (jes.execution_job_status &amp;lt;&amp;gt; 4) AND (jes.execution_job_status &amp;lt;&amp;gt; 5)))      
      AND ((@description      IS NULL) OR (sjv.description       LIKE @description))      
      AND ((@job_id           IS NULL) OR (sjv.job_id               = @job_id))      
      AND ((@schedule_id IS NULL)      
        OR (EXISTS(SELECT *       
                 FROM msdb.dbo.sysjobschedules as js      
                 WHERE (sjv.job_id = js.job_id)      
                   AND (js.schedule_id = @schedule_id))))      
  END      
      
    
    
  -- Step 3.1: Change the execution status of non-local jobs from 'Idle' to 'Unknown'      
  UPDATE @filtered_jobs      
  SET current_execution_status = NULL      
  WHERE (current_execution_status = 4)      
    AND (job_id IN (SELECT job_id      
                    FROM msdb.dbo.sysjobservers      
                    WHERE (server_id &amp;lt;&amp;gt; 0)))      
      
  -- Step 3.2: Check that if the user asked to see idle jobs that we still have some.      
  --           If we don't have any then the query should return no rows.      
  IF (@execution_status = 4) AND      
     (NOT EXISTS (SELECT *      
                  FROM @filtered_jobs      
                  WHERE (current_execution_status = 4)))      
  BEGIN      
    DELETE FROM @filtered_jobs      
  END      
      
  -- Step 3.3: Populate the last run date/time/outcome [this is a little tricky since for      
  --           multi-server jobs there are multiple last run details in sysjobservers, so      
  --           we simply choose the most recent].      
  IF (EXISTS (SELECT *      
              FROM msdb.dbo.systargetservers))      
  BEGIN      
    UPDATE @filtered_jobs      
    SET last_run_date = sjs.last_run_date,      
        last_run_time = sjs.last_run_time,      
        last_run_outcome = sjs.last_run_outcome      
    FROM @filtered_jobs fj,      
         msdb.dbo.sysjobservers sjs      
    WHERE (CONVERT(FLOAT, sjs.last_run_date) * 1000000) + sjs.last_run_time =      
           (SELECT MAX((CONVERT(FLOAT, last_run_date) * 1000000) + last_run_time)      
            FROM msdb.dbo.sysjobservers      
            WHERE (job_id = sjs.job_id))      
      AND (fj.job_id = sjs.job_id)      
  END      
  ELSE      
  BEGIN      
    UPDATE @filtered_jobs      
    SET last_run_date = sjs.last_run_date,      
        last_run_time = sjs.last_run_time,      
        last_run_outcome = sjs.last_run_outcome      
    FROM @filtered_jobs         fj,      
         msdb.dbo.sysjobservers sjs      
    WHERE (fj.job_id = sjs.job_id)      
  END      
      
  -- Step 3.4 : Set the type of the job to local (1) or multi-server (2)      
  --            NOTE: If the job has no jobservers then it wil have a type of 0 meaning      
  --                  unknown.  This is marginally inconsistent with the behaviour of      
  --                  defaulting the category of a new job to [Uncategorized (Local)], but      
  --                  prevents incompletely defined jobs from erroneously showing up as valid      
  --                  local jobs.      
  UPDATE @filtered_jobs      
  SET type = 1 -- LOCAL      
  FROM @filtered_jobs         fj,      
       msdb.dbo.sysjobservers sjs      
  WHERE (fj.job_id = sjs.job_id)      
    AND (server_id = 0)      
  UPDATE @filtered_jobs      
  SET type = 2 -- MULTI-SERVER      
  FROM @filtered_jobs         fj,      
       msdb.dbo.sysjobservers sjs      
  WHERE (fj.job_id = sjs.job_id)      
    AND (server_id &amp;lt;&amp;gt; 0)      
      
  -- Step 4: Filter on job_type      
  IF (@job_type IS NOT NULL)      
  BEGIN      
    IF (UPPER(@job_type collate SQL_Latin1_General_CP1_CS_AS) = 'LOCAL')      
      DELETE FROM @filtered_jobs      
      WHERE (type &amp;lt;&amp;gt; 1) -- IE. Delete all the non-local jobs      
    IF (UPPER(@job_type collate SQL_Latin1_General_CP1_CS_AS) = 'MULTI-SERVER')      
      DELETE FROM @filtered_jobs      
      WHERE (type &amp;lt;&amp;gt; 2) -- IE. Delete all the non-multi-server jobs      
  END      
      
  -- Step 5: Filter on dates      
  IF (@date_comparator IS NOT NULL)      
  BEGIN      
    IF (@date_created IS NOT NULL)      
    BEGIN      
      IF (@date_comparator = '=')      
        DELETE FROM @filtered_jobs WHERE (date_created &amp;lt;&amp;gt; @date_created)      
      IF (@date_comparator = '&amp;gt;')      
        DELETE FROM @filtered_jobs WHERE (date_created &amp;lt;= @date_created)      
      IF (@date_comparator = '&amp;lt;')      
        DELETE FROM @filtered_jobs WHERE (date_created &amp;gt;= @date_created)      
    END      
    IF (@date_last_modified IS NOT NULL)      
    BEGIN      
      IF (@date_comparator = '=')      
        DELETE FROM @filtered_jobs WHERE (date_last_modified &amp;lt;&amp;gt; @date_last_modified)      
      IF (@date_comparator = '&amp;gt;')      
        DELETE FROM @filtered_jobs WHERE (date_last_modified &amp;lt;= @date_last_modified)      
      IF (@date_comparator = '&amp;lt;')      
        DELETE FROM @filtered_jobs WHERE (date_last_modified &amp;gt;= @date_last_modified)      
    END      
  END      
      
  -- Return the result set (NOTE: No filtering occurs here)      
  SELECT @status = ISNULL(fj.current_execution_status, 0)           -- This column will be NULL if the job is non-local      
            
  FROM @filtered_jobs fj      
       LEFT OUTER JOIN msdb.dbo.sysjobs_view  sjv ON (fj.job_id = sjv.job_id)      
       LEFT OUTER JOIN msdb.dbo.sysoperators  so1 ON (sjv.notify_email_operator_id = so1.id)      
       LEFT OUTER JOIN msdb.dbo.sysoperators  so2 ON (sjv.notify_netsend_operator_id = so2.id)      
       LEFT OUTER JOIN msdb.dbo.sysoperators  so3 ON (sjv.notify_page_operator_id = so3.id)      
       LEFT OUTER JOIN msdb.dbo.syscategories sc  ON (sjv.category_id = sc.category_id)      
  ORDER BY sjv.job_id      
      
return @status    
END      
  
GO  
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Now will run the script to invoke the SQL job through analyzer and will see the SQL job status.&lt;br /&gt;
&lt;br /&gt;
Let's run the below code and see the output &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE [master]
GO

-- Get the job status before invoke the job 
DECLARE @status INT  
DECLARE @JobName VARCHAR(500)  

SET @status = 0 
set @JobName = 'Start_JobInvokeProc'

EXEC GetJobStatus
@JobName,  
@status OUTPUT  

SELECT @status AS JobStatus 
------------------------------------------
-- Run this query to invoke the job
EXEC msdb.dbo.Sp_start_job @JobName  
------------------------------------------
-- Get the job status after invoke the job
WAITFOR DELAY '00:00:3';

SET @status = 0 
set @JobName = 'Start_JobInvokeProc'

EXEC GetJobStatus  
@JobName,  
@status OUTPUT  

SELECT @status AS JobStatus 
GO
&lt;/pre&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-itWenEdTobw/TcIPBJQuERI/AAAAAAAAAdM/sM6CdxdDSvA/s1600/jobStatus_1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="376" src="http://3.bp.blogspot.com/-itWenEdTobw/TcIPBJQuERI/AAAAAAAAAdM/sM6CdxdDSvA/s400/jobStatus_1.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
When you run the script again while executing the job, It will raise the error while invoke it again.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;Msg 22022, Level 16, State 1, Line 0&lt;br /&gt;
SQLServerAgent Error: Request to run job Start_JobInvokeProc (from User paresh-PC\paresh) refused because the job is already running from a request by User paresh-PC\paresh.&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
So better option is we need to check the job status first then we can invoke.&lt;br /&gt;
&lt;br /&gt;
The revised script is,&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE [master]
GO

/* Get the job status before invoke the job */
DECLARE @status INT  
DECLARE @JobName VARCHAR(500)  

SET @status = 0 
set @JobName = 'Start_JobInvokeProc'

EXEC GetJobStatus
@JobName,  
@status OUTPUT  

SELECT @status AS JobStatus 

-- Added condition here to check the job is already running or not.
IF (@status &amp;lt;&amp;gt; 1)
BEGIN
/* Run this query to invoke the job*/
EXEC msdb.dbo.Sp_start_job @JobName  
END
GO
&lt;/pre&gt;&lt;br /&gt;
&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=pareshsqldba-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0470484284&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="align: left; height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-7252378943084206617?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/jtnSF722NZbcoc6ZVCcnaytF9X8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/jtnSF722NZbcoc6ZVCcnaytF9X8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/jtnSF722NZbcoc6ZVCcnaytF9X8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/jtnSF722NZbcoc6ZVCcnaytF9X8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/7NLmVkFqoAA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/7252378943084206617/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2011/09/how-to-invoke-job-thorugh-sql-script.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/7252378943084206617?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/7252378943084206617?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/7NLmVkFqoAA/how-to-invoke-job-thorugh-sql-script.html" title="How to invoke Job thorugh SQL script - SQL Server" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-itWenEdTobw/TcIPBJQuERI/AAAAAAAAAdM/sM6CdxdDSvA/s72-c/jobStatus_1.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://paresh-sqldba.blogspot.com/2011/09/how-to-invoke-job-thorugh-sql-script.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEEAQX49eyp7ImA9WhdUEEk.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-4816919368952877248</id><published>2011-09-26T19:47:00.000+05:30</published><updated>2011-09-26T19:47:20.063+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-26T19:47:20.063+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Denali" /><category scheme="http://www.blogger.com/atom/ns#" term="download" /><category scheme="http://www.blogger.com/atom/ns#" term="CTP" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server Denali" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql Server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server Code Named Denali" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="#sql" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server Problems" /><title>How to reset SQL Server all default settings in SQL Server Denali CTP3?</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;&lt;b&gt;Problem:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;Before a few days ago i have installed &lt;a href="http://paresh-sqldba.blogspot.com/2011/07/sql-server-denali-ctp3-whats-new.html"&gt;SQL Server Denali CTP3&lt;/a&gt;. Then i have querying in query analyzer and found, minimizing result is not working with CTRL+R&amp;nbsp;is not working. Before CTP3 i have already Denali CTP1 installed in my machine and it was working&amp;nbsp;perfectly, So it stopping to work in SQL Server CTP3.The default SQL Server settings was changed during this installation.&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;One of the solution:&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;I did not find any option to resolve it. Then i found one solution to reset these setting which are changed during Denali CTP3 installation. Below are some snaps which i performed to recover it back.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;i&gt;Step 1.&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-dacIJn6F78Q/TkNMRmLZ5bI/AAAAAAAAA-w/KTY85AJYqhI/s1600/Settings_1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="228" src="http://4.bp.blogspot.com/-dacIJn6F78Q/TkNMRmLZ5bI/AAAAAAAAA-w/KTY85AJYqhI/s640/Settings_1.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Step 2.&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-QB4kPXjdMKI/TkNMUI9_gsI/AAAAAAAAA-0/MV_IwcS-pKM/s1600/Settings_2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="560" src="http://2.bp.blogspot.com/-QB4kPXjdMKI/TkNMUI9_gsI/AAAAAAAAA-0/MV_IwcS-pKM/s640/Settings_2.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Step 3.&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-HK8uWA3_Ps0/TkNMVmmzWEI/AAAAAAAAA-4/wG-pY_TLDKM/s1600/Settings_3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="560" src="http://3.bp.blogspot.com/-HK8uWA3_Ps0/TkNMVmmzWEI/AAAAAAAAA-4/wG-pY_TLDKM/s640/Settings_3.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Step 4.&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-iJGf5y3dmw8/TkNMXazQhiI/AAAAAAAAA-8/Jv3vrYjQj7Q/s1600/Settings_4.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="560" src="http://3.bp.blogspot.com/-iJGf5y3dmw8/TkNMXazQhiI/AAAAAAAAA-8/Jv3vrYjQj7Q/s640/Settings_4.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Step 5.&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-dpt_x75KgbM/TkNMY3NO0ZI/AAAAAAAAA_A/az7YcXp2MVI/s1600/Settings_5.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="560" src="http://1.bp.blogspot.com/-dpt_x75KgbM/TkNMY3NO0ZI/AAAAAAAAA_A/az7YcXp2MVI/s640/Settings_5.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div&gt;After completion of all above steps, i recovered my SQL Server default setting and CTRL+R working perfect now with CTP3.&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div&gt;You may also faced this issue. I have this solution, You have which one?&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-4816919368952877248?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/UfyPY1wvxLfw95rKNH1QxgjXsuk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UfyPY1wvxLfw95rKNH1QxgjXsuk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/UfyPY1wvxLfw95rKNH1QxgjXsuk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UfyPY1wvxLfw95rKNH1QxgjXsuk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/D53kczQ5lzk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/4816919368952877248/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2011/09/how-to-reset-sql-server-all-default.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/4816919368952877248?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/4816919368952877248?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/D53kczQ5lzk/how-to-reset-sql-server-all-default.html" title="How to reset SQL Server all default settings in SQL Server Denali CTP3?" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-dacIJn6F78Q/TkNMRmLZ5bI/AAAAAAAAA-w/KTY85AJYqhI/s72-c/Settings_1.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://paresh-sqldba.blogspot.com/2011/09/how-to-reset-sql-server-all-default.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEYAQnc7cCp7ImA9WhdVEUU.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-1601854339460281273</id><published>2011-09-16T19:39:00.000+05:30</published><updated>2011-09-16T19:39:03.908+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-16T19:39:03.908+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="t-sql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server General" /><category scheme="http://www.blogger.com/atom/ns#" term="query" /><category scheme="http://www.blogger.com/atom/ns#" term="tsql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="Service Broker" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql" /><title>Stored Procedure Internal Activation in Service Broker - SQL Server</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;As we have seen earlier posts for &lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/08/working-with-service-broker-for-single.html"&gt;Service Broker for single database&lt;/a&gt;&lt;/span&gt;&lt;/b&gt; and &lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/09/service-broker-conversation-between.html"&gt;Service Broker between databases&lt;/a&gt;&lt;/span&gt;&lt;/b&gt;, we have implemented it with examples. Hope you liked those posts. &lt;br /&gt;
&lt;br /&gt;
Remember, in service broker example for single database, we have created stored procedure to process requested data from in target database sent from initiator database. Then we have manually ran the stored procedure to process history data. Please open the link for that example &lt;span class="Apple-style-span" style="color: #0b5394; font-size: large;"&gt;&lt;u&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/08/working-with-service-broker-for-single.html"&gt;here&lt;/a&gt;&lt;/u&gt;&lt;/span&gt;. We have tested the same there as following,&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE SourceDB
GO

TRUNCATE TABLE TransactionTable
TRUNCATE TABLE TransactionHistory
GO

-- Inserting a record
INSERT INTO TransactionTable
SELECT 2,'Insert',Getdate()

-- Updating a records
UPDATE TransactionTable
SET TranType = 'Update',
TranDate = GETDATE()
WHERE TranId = 2

-- Deleting a record
DELETE FROM TransactionTable
WHERE TranId = 2

GO

-- Executing stored procedure manualy
EXEC SB_ReceiveData
GO

SELECT 
* 
FROM TransactionTable

SELECT 
* 
FROM TransactionHistory
GO
&lt;/pre&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;&lt;b&gt;Now come out from the link and look what i will do?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Instead of running that stored procedure manually as above, we can set stored procedure self executing as following. Whenever the new incomming requested messages come this stored procedures executed and process the data for history. We will alter target queue here. This is called internal activation of stored procedure. Service broker will active the stored procedure to process incomming message from target queue and will call anytime when message arrive in target queue.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;-- Altering queue with self execution of stored procedure
ALTER QUEUE DestinationQueue
    WITH ACTIVATION
    ( STATUS = ON,
      PROCEDURE_NAME = SB_ReceiveData,
      MAX_QUEUE_READERS = 100,
      EXECUTE AS SELF
    )
GO
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;Retseting :&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
As resteting the automated self execution of stored procedure, we will do the same but we will not call the stored procedure.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE SourceDB
GO

-- Truncating table
TRUNCATE TABLE TransactionTable
TRUNCATE TABLE TransactionHistory
GO

-- Inserting a record
INSERT INTO TransactionTable
SELECT 2,'Insert',Getdate()

-- Updating a records
UPDATE TransactionTable
SET TranType = 'Update',
TranDate = GETDATE()
WHERE TranId = 2

-- Deleting a record
DELETE FROM TransactionTable
WHERE TranId = 2

GO

-- Reviewing the data from tables
SELECT 
* 
FROM TransactionTable

SELECT 
* 
FROM TransactionHistory
GO
&lt;/pre&gt;&lt;br /&gt;
Finally the output comming for both testing of manually and self execution of stored procedure as captured following,&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-gAnYoXf5k64/TnMhWXbugjI/AAAAAAAABBU/Z8YDW26jFsc/s1600/ServiceBroker_1_2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="203" src="http://1.bp.blogspot.com/-gAnYoXf5k64/TnMhWXbugjI/AAAAAAAABBU/Z8YDW26jFsc/s640/ServiceBroker_1_2.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Hope you liked this post for setting stored procedure self execution with target queue.  &lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-1601854339460281273?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/dNFssYGH-j5aUc0EvT_prmVBnNg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/dNFssYGH-j5aUc0EvT_prmVBnNg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/dNFssYGH-j5aUc0EvT_prmVBnNg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/dNFssYGH-j5aUc0EvT_prmVBnNg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/m36jMpX3EXU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/1601854339460281273/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2011/09/stored-procedure-internal-activation-in.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/1601854339460281273?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/1601854339460281273?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/m36jMpX3EXU/stored-procedure-internal-activation-in.html" title="Stored Procedure Internal Activation in Service Broker - SQL Server" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-gAnYoXf5k64/TnMhWXbugjI/AAAAAAAABBU/Z8YDW26jFsc/s72-c/ServiceBroker_1_2.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://paresh-sqldba.blogspot.com/2011/09/stored-procedure-internal-activation-in.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0ADR3s-fCp7ImA9WhdWGU8.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-617995264099752789</id><published>2011-09-13T19:19:00.000+05:30</published><updated>2011-09-13T19:19:36.554+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-13T19:19:36.554+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="CTP" /><category scheme="http://www.blogger.com/atom/ns#" term="query" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server Denali" /><category scheme="http://www.blogger.com/atom/ns#" term="tsql" /><category scheme="http://www.blogger.com/atom/ns#" term="new features" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server" /><category scheme="http://www.blogger.com/atom/ns#" term="t-sql" /><category scheme="http://www.blogger.com/atom/ns#" term="Enhancements" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL new features" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2011" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql" /><title>New Logical functions coming in SQL Server Denali CTP3</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;As i have started to learn new functions arrived by SQL Server Denali CTP3 version and i have posted some of them. You can learn &lt;a href="http://paresh-sqldba.blogspot.com/2011/07/amazing-analytical-functions-arrived-by.html"&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;b&gt;Analytical functions&lt;/b&gt;&lt;/span&gt;&lt;/a&gt; , &lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/07/intresting-conversion-functions-arrived.html"&gt;Conversion functions&lt;/a&gt;&lt;/span&gt;&lt;/b&gt; and &lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;b&gt;&lt;a href="http://paresh-sqldba.blogspot.com/2011/09/new-string-functions-arrived-by-sql.html"&gt;String functions&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;. You can also get the list of all the features coming in SQL Server 2011 CTP3.&lt;br /&gt;
&lt;br /&gt;
Now&amp;nbsp;diverting&amp;nbsp;on this post for the new Logical functions which are following,&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;1. IIF&lt;/span&gt;&lt;/b&gt;&lt;/u&gt; : &lt;br /&gt;
It returns one of two arguments, depending on the evaluation of expression. It has require three arguments, first is condition, second and third are the values. Depending on the evaluation of first condition second or third values will be return, means if first condition is ture then it will return second value and if it is false then it will return third value. It returns the data type with the highest precedence from the types in true_value and false_value.&lt;br /&gt;
&lt;br /&gt;
Let us evaluate it to know it better.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;DECLARE @IsDone bit
SET @IsDone = 1
SELECT iif(@IsDone = 1,'Success', 'Failed')
GO
&lt;/pre&gt;&lt;br /&gt;
Above code returns "Success". Now les us assign the NULL value to variable then verify.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;DECLARE @IsDone bit
SET @IsDone = NULL
SELECT iif(@IsDone = 1,'Success', 'Failed')
GO
&lt;/pre&gt;&lt;br /&gt;
Here it returns "Failed" as output. Now elaborate it with more examples.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;DECLARE @IsDone bit
DECLARE @FirstVal varchar(10)
DECLARE @SecondVal varchar(10)
SET @IsDone = 1
SET @FirstVal = NULL
SET @SecondVal = NULL

SELECT iif(@IsDone = 1,@FirstVal, @SecondVal)
GO
&lt;/pre&gt;&lt;br /&gt;
Above code returns NULL as resulted output. What happen if we pass directly NULL in both first and second values?&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;DECLARE @IsDone bit
SET @IsDone = 1

SELECT iif(@IsDone = 1,NULL, NULL)
GO
&lt;/pre&gt;&lt;br /&gt;
It comes with following error,&lt;br /&gt;
&lt;br /&gt;
"&lt;span class="Apple-style-span" style="color: red;"&gt;Msg 8133, Level 16, State 1, Line 4&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: red;"&gt;At lease one of the result expressions in a CASE specification must be an expression other than the NULL constant.&lt;/span&gt;"&lt;br /&gt;
&lt;br /&gt;
Now second turns come for CHOOSE function.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;2. CHOOSE&lt;/span&gt;&lt;/b&gt;&lt;/u&gt; :&lt;br /&gt;
It returns the value at the specified index from among the lists. It has require first argument as Index and hen we can pass mutiple parameters for the values. It returns the data type with the highest precedence from the set of types passed to the function&lt;br /&gt;
&lt;br /&gt;
Let elaborate it with sample examples.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;DECLARE @Index int
SET @Index = 2

SELECT CHOOSE (@Index,'First','Second','Third')
GO
&lt;/pre&gt;&lt;br /&gt;
It returns "Second" value becuase it belong to second index.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;DECLARE @Index int
SET @Index = 0

SELECT CHOOSE (@Index,'First','Second','Third')
GO
&lt;/pre&gt;&lt;br /&gt;
Above query returns NULL as output. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;DECLARE @Index int
SET @Index = NULL

SELECT CHOOSE (@Index,'First','Second','Third')
GO
&lt;/pre&gt;&lt;br /&gt;
Same as earlier query it also returns NULL as resulted output. What happen if we pass all the values with NULL ?&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;DECLARE @Index int
SET @Index = 2

SELECT CHOOSE (@Index,NULL,NULL,NULL)
GO
&lt;/pre&gt;&lt;br /&gt;
It also come up with NULL.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;Hope you liked these functions. stay tuned for more posts.&lt;br /&gt;
&lt;br /&gt;
&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=pareshsqldba-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0976635356&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="align: left; height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-617995264099752789?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/3sqj3mzaAiof6iIyDN1EcxgeW0Q/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3sqj3mzaAiof6iIyDN1EcxgeW0Q/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/3sqj3mzaAiof6iIyDN1EcxgeW0Q/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3sqj3mzaAiof6iIyDN1EcxgeW0Q/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/R9U1InxZ2e8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/617995264099752789/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2011/09/new-logical-functions-coming-in-sql.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/617995264099752789?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/617995264099752789?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/R9U1InxZ2e8/new-logical-functions-coming-in-sql.html" title="New Logical functions coming in SQL Server Denali CTP3" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://paresh-sqldba.blogspot.com/2011/09/new-logical-functions-coming-in-sql.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEcNRXwyfSp7ImA9WhdWFk4.&quot;"><id>tag:blogger.com,1999:blog-2029072262337060983.post-5126202180553862860</id><published>2011-09-10T10:51:00.000+05:30</published><updated>2011-09-10T10:51:34.295+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-10T10:51:34.295+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2008" /><category scheme="http://www.blogger.com/atom/ns#" term="sql errors" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL SERVER 2005" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server General" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server Denali" /><category scheme="http://www.blogger.com/atom/ns#" term="tsql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server" /><category scheme="http://www.blogger.com/atom/ns#" term="t-sql" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql server" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Scripts" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2011" /><category scheme="http://www.blogger.com/atom/ns#" term="database" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><category scheme="http://www.blogger.com/atom/ns#" term="ms sql" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server Problems" /><title>"The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION" - Error encountered in SQL Server</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;During development of stored procedures, i ran into one issue and this was due to not applied best practice of stored procedures practice and this issue comes mostly when we call stored procedures inside another one and so on, which are used in nested in transactions.&lt;br /&gt;
&lt;br /&gt;
So i &amp;nbsp;would like to write next post for the stored procedures development , as how we should write it, It will be a just a template of best practice.&amp;nbsp;In this post i will explain the details of the issue which i suffered and how can we resolve it.&lt;br /&gt;
&lt;br /&gt;
Let's for the demonstration we will created one table and stored procedures.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;-- Creating table which will be used in SPs.
CREATE TABLE tbl_Tran
  (
     TranId    INT NOT NULL PRIMARY KEY
     ,TranName VARCHAR(10)
  )

GO


-- Creating first stored procedure.
CREATE PROCEDURE Firttranproc
AS
  BEGIN
      SET NOCOUNT ON

      BEGIN TRY
          BEGIN TRANSACTION

    -- Inserting records in table,
    -- Due to this insert error will be raised.
          INSERT INTO tbl_Tran
                      (TranId
                       ,TranName)
          SELECT
            1
            ,'Tran-1'
          UNION ALL
          SELECT
            1
            ,'Tran-1'

          COMMIT TRANSACTION
      END TRY

      BEGIN CATCH
          ROLLBACK TRANSACTION

          PRINT 'Rollback Tran1'
      END CATCH
  END

GO


-- Creating Second stored procedure
CREATE PROCEDURE Secondtranproc
AS
  BEGIN
      SET NOCOUNT ON

      BEGIN TRY
          BEGIN TRANSACTION

          INSERT INTO tbl_Tran
                      (TranId
                       ,TranName)
          SELECT
            2
            ,'Tran-2'

    -- Calling first created stored procedure here.
          EXEC Firttranproc

          COMMIT TRANSACTION
      END TRY

      BEGIN CATCH
          ROLLBACK TRANSACTION

          PRINT 'Rollback Tran2'
      END CATCH
  END

GO



-- Executing second stored procedure here and see what happen.
EXEC Secondtranproc

GO

&lt;/pre&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-1fUQnWw0fZE/TcUhGLUgp9I/AAAAAAAAAec/-iakqX6j94M/s1600/error_1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="116" src="http://4.bp.blogspot.com/-1fUQnWw0fZE/TcUhGLUgp9I/AAAAAAAAAec/-iakqX6j94M/s640/error_1.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
In first stored we have written a code to raise error and due to transaction issue while running  second stored procedure it raised error.&lt;br /&gt;
&lt;br /&gt;
This is not best practice as we have write only "Begin Transaction". We should specify the name of the stored procedure. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;u&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;# 1 Solution :&lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Let's specify the name of transactions in both of the stored procedures and altering stored procedures here and execute it again with same.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;-- Altering first stored procedure here
ALTER PROCEDURE Firttranproc
AS
  BEGIN
      SET NOCOUNT ON
   
   -- Here we have specified Tran1 as transaction name
 
   BEGIN TRY
          BEGIN TRANSACTION Tran1

          INSERT INTO tbl_Tran
                      (TranId
                       ,TranName)
   
          SELECT
            1
            ,'Tran-1'
          UNION ALL
          SELECT
            1
            ,'Tran-1'

          COMMIT TRANSACTION Tran1
      END TRY

      BEGIN CATCH
          PRINT 'Rollback Tran1'

          ROLLBACK TRANSACTION Tran1
      END CATCH
  END

GO

-- Altering second stored procedure here
ALTER PROCEDURE Secondtranproc
AS
  BEGIN
      SET NOCOUNT ON

  -- Here we have specified Tran2 as transaction name

      BEGIN TRY
          BEGIN TRANSACTION Tran2

    -- Inserting records
          INSERT INTO tbl_Tran
                      (TranId
                       ,TranName)
          SELECT
            2
            ,'Tran-2'

          -- Calling first stored procedure here
          EXEC Firttranproc

          COMMIT TRANSACTION Tran2
      END TRY

      BEGIN CATCH
          PRINT 'Rollback Tran2'

          ROLLBACK TRANSACTION Tran2
      END CATCH
  END

GO


-- Executing second stored procedure which will also call of SP1 
EXEC Secondtranproc

GO

&lt;/pre&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-3S9W0lpakLI/TcUlJBGyKHI/AAAAAAAAAek/vcpc6jkPrvU/s1600/error_2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="99" src="http://2.bp.blogspot.com/-3S9W0lpakLI/TcUlJBGyKHI/AAAAAAAAAek/vcpc6jkPrvU/s640/error_2.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
You can see here the error is not raised which is raided in first case. Here stored procedure find and commit/rollback correct and their transactions only.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;u&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;# 2 Solution :&lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;u&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Le's look another alternative method which can also help to come out from issue.&lt;br /&gt;
&lt;br /&gt;
The rewritten stored procedures,&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;-- Altering first stored procedure here
ALTER PROCEDURE Firttranproc
AS
  BEGIN
      SET NOCOUNT ON
   
   -- Here we have specified Tran1 as transaction name
 
   BEGIN TRY
          BEGIN TRANSACTION 

          INSERT INTO tbl_Tran
                      (TranId
                       ,TranName)
   
          SELECT
            1
            ,'Tran-1'
          UNION ALL
          SELECT
            1
            ,'Tran-1'

          COMMIT TRANSACTION 
      END TRY

      BEGIN CATCH
          PRINT 'Rollback Tran1'

   -- This statement first check open transaction for their session 
   -- If found then will rollback it.
         IF @@TRANCOUNT &amp;gt; 0
             ROLLBACK TRANSACTION 
      END CATCH
  END

GO

-- Altering second stored procedure here
ALTER PROCEDURE Secondtranproc
AS
  BEGIN
      SET NOCOUNT ON

      BEGIN TRY
          BEGIN TRANSACTION 

    -- Inserting records
          INSERT INTO tbl_Tran
                      (TranId
                       ,TranName)
          SELECT
            2
            ,'Tran-2'

          -- Calling first stored procedure here
          EXEC Firttranproc

          COMMIT TRANSACTION 
      END TRY

      BEGIN CATCH
          PRINT 'Rollback Tran2'

    
   -- This statement first check open transaction for their session 
   -- If found then will rollback it.
         IF @@TRANCOUNT &amp;gt; 0
          ROLLBACK TRANSACTION 
      END CATCH
  END

GO


-- Executing second stored procedure which will also call of SP1 
EXEC Secondtranproc

GO

&lt;/pre&gt;&lt;br /&gt;
Here is same output as second case , it is also not raised error.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-FRgwsKyMPps/TcUnZiWKI_I/AAAAAAAAAes/piy0VyCdSb8/s1600/error_2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="99" src="http://4.bp.blogspot.com/-FRgwsKyMPps/TcUnZiWKI_I/AAAAAAAAAes/piy0VyCdSb8/s640/error_2.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Let me know what you think over here. You also encountered this issue in past, Please share you experience and alternation solution.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029072262337060983-5126202180553862860?l=paresh-sqldba.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/TT_h3pjt8Augdq1QxivYTZNO6_w/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/TT_h3pjt8Augdq1QxivYTZNO6_w/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/TT_h3pjt8Augdq1QxivYTZNO6_w/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/TT_h3pjt8Augdq1QxivYTZNO6_w/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlDbaPosts/~4/Gj1ZbUjvZk0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://paresh-sqldba.blogspot.com/feeds/5126202180553862860/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://paresh-sqldba.blogspot.com/2011/09/rollback-transaction-request-has-no.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/5126202180553862860?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2029072262337060983/posts/default/5126202180553862860?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/SqlDbaPosts/~3/Gj1ZbUjvZk0/rollback-transaction-request-has-no.html" title="&quot;The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION&quot; - Error encountered in SQL Server" /><author><name>Paresh Prajapati - SQL DBA</name><uri>http://www.blogger.com/profile/01031181680771363872</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="28" height="32" src="http://1.bp.blogspot.com/-5ImperByH3o/TqikDh30QbI/AAAAAAAABB8/yzOPTHjAtBk/s220/Blog.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-1fUQnWw0fZE/TcUhGLUgp9I/AAAAAAAAAec/-iakqX6j94M/s72-c/error_1.png" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://paresh-sqldba.blogspot.com/2011/09/rollback-transaction-request-has-no.html</feedburner:origLink></entry></feed>

