<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6039733735905460821</id><updated>2024-09-09T00:40:07.093-04:00</updated><category term="SQL Server"/><category term="Scripts"/><category term="Backup"/><category term="Oracle"/><category term="Powershell"/><category term="Powershell SQL Server"/><category term="Restore"/><category term="SSMS"/><category term="Security"/><title type='text'>SqlWritesql PowershellWriteSql</title><subtitle type='html'>SQL script that writes sql (DLL or DML) script for DBA and Developer for MS SQL Server 2005 or 2008 or R2</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://sqlwritesql.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6039733735905460821/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://sqlwritesql.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>9</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6039733735905460821.post-8491841382961173720</id><published>2015-08-13T09:13:00.000-04:00</published><updated>2017-12-22T11:57:54.651-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Powershell"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server"/><category scheme="http://www.blogger.com/atom/ns#" term="SSMS"/><title type='text'>Open-SSMS  function. Open SSMS using powershell command prompt. </title><content type='html'>&lt;b&gt;Open SQL Server Management Server using powershell command prompt. &lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;Since working with powershell while now. I got use to open all the tools using powershell command line. I have below list function. 

&lt;script src=&quot;https://gist.github.com/hiten004/4ddd4311c2e612fc66d6cc197fb8fafc.js&quot;&gt;&lt;/script&gt;
&lt;/b&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlwritesql.blogspot.com/feeds/8491841382961173720/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlwritesql.blogspot.com/2015/08/open-ssms-function-open-ssms-using.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6039733735905460821/posts/default/8491841382961173720'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6039733735905460821/posts/default/8491841382961173720'/><link rel='alternate' type='text/html' href='http://sqlwritesql.blogspot.com/2015/08/open-ssms-function-open-ssms-using.html' title='Open-SSMS  function. Open SSMS using powershell command prompt. '/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6039733735905460821.post-6398520299884527777</id><published>2014-08-01T11:51:00.002-04:00</published><updated>2017-12-22T12:04:43.296-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Scripts"/><category scheme="http://www.blogger.com/atom/ns#" term="Security"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server"/><title type='text'></title><content type='html'>SQL Login is locked? instead of looking at one at time on SSMS. Here is the script that will check all SQL Sever login at same time .&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/hiten004/c8aa7f9906be12daca93e60aa9820f90.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
Thanks
</content><link rel='replies' type='application/atom+xml' href='http://sqlwritesql.blogspot.com/feeds/6398520299884527777/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlwritesql.blogspot.com/2014/08/sql-login-is-locked-instade-of-looking.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6039733735905460821/posts/default/6398520299884527777'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6039733735905460821/posts/default/6398520299884527777'/><link rel='alternate' type='text/html' href='http://sqlwritesql.blogspot.com/2014/08/sql-login-is-locked-instade-of-looking.html' title=''/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6039733735905460821.post-1281157732055174866</id><published>2012-09-06T12:44:00.002-04:00</published><updated>2017-12-22T12:12:58.029-05:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Powershell SQL Server"/><category scheme="http://www.blogger.com/atom/ns#" term="Scripts"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server"/><title type='text'>Genarate DBCC SHRINKFILE command script using Powershell</title><content type='html'>&lt;br /&gt;
Generate DBCC SHRINKFILE shrink file command in small size as time

&lt;script src=&quot;https://gist.github.com/hiten004/f1e706c3bf8452cefc8518f4c146e54b.js&quot;&gt;&lt;/script&gt;



# OUTPUT

 USE [ MyDB] 
 GO 
 DBCC SHRINKFILE (N&#39; MyDBdata&#39; ,10000) 
 GO
 USE [ MyDB] 
 GO 
 DBCC SHRINKFILE (N&#39; MyDBdata&#39; ,9000) 
 GO
 USE [ MyDB] 
 GO 
 DBCC SHRINKFILE (N&#39; MyDBdata&#39; ,8000) 
 GO
 USE [ MyDB] 
 GO 
 DBCC SHRINKFILE (N&#39; MyDBdata&#39; ,7000) 
 GO
 USE [ MyDB] 
 GO 
 DBCC SHRINKFILE (N&#39; MyDBdata&#39; ,6000) 
 GO
 USE [ MyDB] 
 GO 
 DBCC SHRINKFILE (N&#39; MyDBdata&#39; ,5000) 
 GO
 USE [ MyDB] 
 GO 
 DBCC SHRINKFILE (N&#39; MyDBdata&#39; ,4000) 
 GO
 USE [ MyDB] 
 GO 
 DBCC SHRINKFILE (N&#39; MyDBdata&#39; ,3000) 
 GO
 USE [ MyDB] 
 GO 
 DBCC SHRINKFILE (N&#39; MyDBdata&#39; ,2000) 
 GO
#&amp;gt;


</content><link rel='replies' type='application/atom+xml' href='http://sqlwritesql.blogspot.com/feeds/1281157732055174866/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlwritesql.blogspot.com/2012/09/genarate-shrink-script-using-powershell.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6039733735905460821/posts/default/1281157732055174866'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6039733735905460821/posts/default/1281157732055174866'/><link rel='alternate' type='text/html' href='http://sqlwritesql.blogspot.com/2012/09/genarate-shrink-script-using-powershell.html' title='Genarate DBCC SHRINKFILE command script using Powershell'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6039733735905460821.post-4595976185450316767</id><published>2012-07-11T12:35:00.003-04:00</published><updated>2015-08-10T18:04:55.982-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Backup"/><category scheme="http://www.blogger.com/atom/ns#" term="Restore"/><category scheme="http://www.blogger.com/atom/ns#" term="Scripts"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server"/><title type='text'>Backup and Restore Database status indicator</title><content type='html'>&lt;pre class=&quot;brush:sql;&quot;&gt;

-- Backup and Restore Database status indicator
 
SELECT [spid] = r.session_id,
    substring(t.[text],charindex(&#39;[&#39;,t.[text],1)+1,(charindex(&#39;]&#39;,t.[text],1)-charindex(&#39;[&#39;,t.[text],1))-1) restore_db, r.start_time,
 percent_complete = round(r.percent_complete,2),
 DATEDIFF(mi,r.start_time,getdate()) &#39;elapsed_time (min)&#39;,
    r.[status],
    r.command,
    t.[text] sql_text,
case r.percent_complete
when 0 THEN 1  
else DATEADD(mi,round(DATEDIFF(mi,r.start_time,getdate())/(r.percent_complete/100),0),r.start_time) 
end as &#39;estimated_completion&#39;
FROM
    sys.dm_exec_requests AS r
CROSS APPLY
    sys.dm_exec_sql_text(r.[sql_handle]) AS t
WHERE
    r.session_id &lt;&gt; @@SPID
    AND r.command in (&#39;RESTORE DATABASE&#39;,&#39;BACKUP DATABASE&#39;)
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlwritesql.blogspot.com/feeds/4595976185450316767/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlwritesql.blogspot.com/2012/07/backup-and-restore-database-status.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6039733735905460821/posts/default/4595976185450316767'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6039733735905460821/posts/default/4595976185450316767'/><link rel='alternate' type='text/html' href='http://sqlwritesql.blogspot.com/2012/07/backup-and-restore-database-status.html' title='Backup and Restore Database status indicator'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6039733735905460821.post-8236692136851601058</id><published>2011-08-29T18:16:00.003-04:00</published><updated>2015-08-10T18:04:40.785-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Scripts"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server"/><title type='text'>Generate trigger script using sys.all_sql_modules in SQL Server 2008</title><content type='html'>Generate trigger script using sys.all_sql_modules in SQL Server 2008&lt;br /&gt;
&lt;span style=&quot;font-family: courier new;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;iframe align=&quot;left&quot; frameborder=&quot;0&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;http://rcm.amazon.com/e/cm?t=sqlwritesql-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0735626022&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=FFFFFF&amp;amp;bg1=FFFFFF&amp;amp;f=ifr&quot; style=&quot;align: left; height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;&quot;&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;pre class=&quot;brush:sql;&quot;&gt;
-- Generate trigger script using sys.all_sql_modules in SQL Server 2008
Select definition+CHAR(10)+&#39;GO&#39; AS &#39;--definition&#39; from sys.all_sql_modules 
where object_id in 
 (Select object_id  from sys.objects where type = &#39;TR&#39;)
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlwritesql.blogspot.com/feeds/8236692136851601058/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlwritesql.blogspot.com/2011/08/generate-trigger-script-using.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6039733735905460821/posts/default/8236692136851601058'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6039733735905460821/posts/default/8236692136851601058'/><link rel='alternate' type='text/html' href='http://sqlwritesql.blogspot.com/2011/08/generate-trigger-script-using.html' title='Generate trigger script using sys.all_sql_modules in SQL Server 2008'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6039733735905460821.post-5652132996725271779</id><published>2011-08-17T12:51:00.003-04:00</published><updated>2015-08-10T18:04:22.143-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Oracle"/><category scheme="http://www.blogger.com/atom/ns#" term="Scripts"/><title type='text'>List profile without user in oracle</title><content type='html'>Folling pl/sql script with give you List profile without user in oracle. &lt;br /&gt;
&lt;br /&gt;
--List profile without user in oracle&lt;br /&gt;
&lt;span style=&quot;font-family: courier new;&quot;&gt;&lt;br /&gt;
&lt;pre name=&quot;code&quot; class=&quot;sql&quot;&gt;

Select distinct p.PROFILE 
from dba_profiles p, dba_users u 
where p.PROFILE  = u.PROFILE (+) and  u.USERNAME is null

&lt;/pre&gt;&lt;/SPAN&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlwritesql.blogspot.com/feeds/5652132996725271779/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlwritesql.blogspot.com/2011/08/list-profile-without-user-in-oracle.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6039733735905460821/posts/default/5652132996725271779'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6039733735905460821/posts/default/5652132996725271779'/><link rel='alternate' type='text/html' href='http://sqlwritesql.blogspot.com/2011/08/list-profile-without-user-in-oracle.html' title='List profile without user in oracle'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6039733735905460821.post-7456582630472601693</id><published>2010-08-02T19:52:00.001-04:00</published><updated>2015-08-10T18:03:19.682-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Scripts"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server"/><title type='text'>Create dump device dynamicly on the fly.</title><content type='html'>--dump device Create dynamicly&lt;br /&gt;
&lt;span style=&quot;font-family: courier new;&quot;&gt;&lt;br /&gt;
&lt;pre class=&quot;brush:sql;&quot;&gt;
-- dumpdevice full diskbakup
Select &#39;EXEC master.dbo.sp_addumpdevice  @devtype = N&#39;&#39;disk&#39;&#39;, @logicalname = N&#39;&#39;&#39; + name + &#39;_DUMP&#39;&#39;, @physicalname = N&#39;&#39;E:\MSSQL\BACKUP\&#39; + name + &#39;_DUMP.BAK&#39;&#39;&#39;
from sys.sysdatabases

-- dumpdevice Diff diskbackup
Select &#39;EXEC master.dbo.sp_addumpdevice  @devtype = N&#39;&#39;disk&#39;&#39;, @logicalname = N&#39;&#39;&#39; + name + &#39;_DIFFDUMP&#39;&#39;, @physicalname = N&#39;&#39;E:\MSSQL\BACKUP\&#39; + name + &#39;_DIFFDUMP.BAK&#39;&#39;&#39;
from sys.sysdatabases

&lt;/pre&gt;&lt;/SPAN&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlwritesql.blogspot.com/feeds/7456582630472601693/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlwritesql.blogspot.com/2010/08/create-dump-device-dynamicly-on-fly.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6039733735905460821/posts/default/7456582630472601693'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6039733735905460821/posts/default/7456582630472601693'/><link rel='alternate' type='text/html' href='http://sqlwritesql.blogspot.com/2010/08/create-dump-device-dynamicly-on-fly.html' title='Create dump device dynamicly on the fly.'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6039733735905460821.post-5149309494181657423</id><published>2010-07-07T10:47:00.000-04:00</published><updated>2015-08-10T18:03:06.742-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Scripts"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server"/><title type='text'>DBO OFF Script</title><content type='html'>&lt;em&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;-- DBO&amp;nbsp;OFF Script help DBA put all or some database out of DBO mode after maintenance or DBA activities. &lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;-- SQL 2000&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;-- SQL 2005 /2008&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: courier new;&quot;&gt;&lt;br /&gt;
&lt;pre class=&quot;brush:sql;&quot;&gt;
DECLARE @vbcrlf varchar(100)

Select @vbcrlf = char(13) + char(10)
select &#39;USE master&#39; + @vbcrlf +
&#39;GO&#39; + @vbcrlf +
&#39;ALTER DATABASE [&#39;+ name + &#39;] SET SINGLE_USER WITH ROLLBACK IMMEDIATE&#39; 
+ @vbcrlf + &#39;GO&#39; + @vbcrlf +
&#39;ALTER DATABASE [&#39;+ name + &#39;] SET SINGLE_USER &#39; 
+ @vbcrlf + &#39;GO&#39; + @vbcrlf +
&#39;ALTER DATABASE [&#39;+ name + &#39;] SET MULTI_USER WITH ROLLBACK IMMEDIATE&#39; 
+ @vbcrlf + &#39;GO&#39; + @vbcrlf +
&#39;ALTER DATABASE [&#39;+ name + &#39;] SET MULTI_USER&#39;
+ @vbcrlf + &#39;GO&#39; + @vbcrlf
from sys.sysdatabases(nolock) where dbid&amp;gt;4 order by name&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.com/Learning-SQL-Alan-Beaulieu/dp/0596520832?ie=UTF8&amp;amp;tag=sqlwritesql-20&amp;amp;link_code=btl&amp;amp;camp=213689&amp;amp;creative=392969&quot; target=&quot;_blank&quot;&gt;Learning SQL&lt;/a&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; height=&quot;1&quot; src=&quot;http://www.assoc-amazon.com/e/ir?t=sqlwritesql-20&amp;amp;l=btl&amp;amp;camp=213689&amp;amp;creative=392969&amp;amp;o=1&amp;amp;a=0596520832&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0px; padding-bottom: 0px! important; padding-left: 0px! important; padding-right: 0px! important; padding-top: 0px! important;&quot; width=&quot;1&quot; /&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlwritesql.blogspot.com/feeds/5149309494181657423/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlwritesql.blogspot.com/2010/07/dbo-off-script.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6039733735905460821/posts/default/5149309494181657423'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6039733735905460821/posts/default/5149309494181657423'/><link rel='alternate' type='text/html' href='http://sqlwritesql.blogspot.com/2010/07/dbo-off-script.html' title='DBO OFF Script'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6039733735905460821.post-6775037367408445183</id><published>2010-06-30T18:41:00.000-04:00</published><updated>2015-08-10T18:02:49.040-04:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Scripts"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server"/><title type='text'>DBO ON Scripts</title><content type='html'>&lt;em&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;-- DBO on Script help DBA put all or some database into DBO mode for maintenance or DBA activities. &lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;-- SQL 2000&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;em&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;-- SQL 2005 /2008&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:sql;&quot;&gt;
DECLARE @vbcrlf varchar(100)
Select @vbcrlf = char(13) + char(10)

select &#39;USE master&#39; + @vbcrlf +
&#39;GO&#39; + @vbcrlf +
&#39;ALTER DATABASE [&#39;+ name + &#39;] SET SINGLE_USER WITH ROLLBACK IMMEDIATE&#39; 
+ @vbcrlf + &#39;GO&#39; + @vbcrlf +
&#39;ALTER DATABASE [&#39;+ name + &#39;] SET SINGLE_USER &#39; 
+ @vbcrlf + &#39;GO&#39; + @vbcrlf +
&#39;ALTER DATABASE [&#39;+ name + &#39;] SET RESTRICTED_USER WITH ROLLBACK IMMEDIATE&#39;
+ @vbcrlf + &#39;GO&#39; + @vbcrlf +
&#39;ALTER DATABASE [&#39;+ name + &#39;] SET RESTRICTED_USER&#39;
+ @vbcrlf + &#39;GO&#39; + @vbcrlf
from sys.sysdatabases(nolock) where dbid&gt;4 order by name
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.amazon.com/Learning-SQL-Alan-Beaulieu/dp/0596520832?ie=UTF8&amp;amp;tag=sqlwritesql-20&amp;amp;link_code=btl&amp;amp;camp=213689&amp;amp;creative=392969&quot; target=&quot;_blank&quot;&gt;Learning SQL&lt;/a&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; height=&quot;1&quot; src=&quot;http://www.assoc-amazon.com/e/ir?t=sqlwritesql-20&amp;amp;l=btl&amp;amp;camp=213689&amp;amp;creative=392969&amp;amp;o=1&amp;amp;a=0596520832&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0px; padding-bottom: 0px! important; padding-left: 0px! important; padding-right: 0px! important; padding-top: 0px! important;&quot; width=&quot;1&quot; /&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlwritesql.blogspot.com/feeds/6775037367408445183/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlwritesql.blogspot.com/2010/06/dbo-scripts.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6039733735905460821/posts/default/6775037367408445183'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6039733735905460821/posts/default/6775037367408445183'/><link rel='alternate' type='text/html' href='http://sqlwritesql.blogspot.com/2010/06/dbo-scripts.html' title='DBO ON Scripts'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>